So you should always have to show example
Forum
CS2D Scripts Lua Scripts/Questions/HelpSo you should always have to show example
Example 1. : You can walkover any weapon boom you get it even if you already have it.
1
2
3
4
5
6
7
2
3
4
5
6
7
function hook_walkover_mod(i,wid,w) 		parse("equip "..i.." "..w) 		parse("removeitem "..wid) 		parse("setweapon "..i.." "..w) 		parse("sv_sound2 "..i.." items/pickup.wav") end addhook("walkover","hook_walkover_mod")
when you walkover it will then equip the item you have just walkover(ed) and remove the one on the ground
sets the weapon to you, plays the pickup sound.
Example 2. : Freeze your server temporarily
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
addhook("always","hook_always_rdk") a = 0 function hook_always_rdk() 	while a ~= 10000 do 		a = a + 1 	error("TEMPORARY FROZEN!") 	end end
Example 3. : Math Library Quadratic Formula Substitute
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--Quadratic Formula [Math] function quadform(a,b,c) 	--[[-- 	local f2 = math.pow(b,2) - 4 * a * c / 2 * a 	local f11 = -b + math.sqrt(f2) 	local f12 = -b - math.sqrt(f2) 	--]]-- 	if a == nil or b == nil or c == nil then 		error("Wrong Parameters",1) 	else 	local f11 = -b/2/a+math.pow(math.pow(b,2)-4*a*c,0.5)/2/a 	local f12 = -b/2/a-math.pow(math.pow(b,2)-4*a*c,0.5)/2/a 	print("B+") 	print(f11) 	print("B-") 	print(f12) 	return f11,f12 	end end
Input in lua
1
2
3
4
2
3
4
quadform(a,b,c) ------------ ax^2 + bx + c ------------
I got lazy so i made this lua thing as a "shortcut" lol
Flacko has written
You are pro
indeed.
why just show it? why you don't teach to us more about this?
Allows you to do inline string formating. For example, if you need to do the following
1
print(player_name.." ("..admin_type.."): "..message)
you can instead write
1
print("%s (%s): %s" % {player_name, admin_type, message})
Note that this is the same as the python notation.
Code:
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
--string.format local _mtstr = getmetatable("") function _mtstr.__mod(self, other) 	if type(other) == "table" then 		return self:format(unpack(other)) 	else 		return self:format(other) 	end end
_mtstr is a metatable that contains all of the methods of ALL strings. the .__mod function is the callback for the modulus operator (%), therefore, whenever you write "some weird string %s"%"!!", the statement instead returns string.format("some weird string %s", "!!").
Admirdee has written
indeed.
Flacko has written
You are pro
indeed.
I wasn't serious
@Lee: I was wondering how did you get to make your string library and be able to call your functions as a method of a string, like in the Lua string library. I could have never figured out that this was done through metatables, good job
So I guess I'll share something too
Something very basic that uses the pythagorean theorem that at the same time is very useful. Circular collision detection.
1
2
3
2
3
function distance(point1,point2) 	return math.sqrt(math.pow(point1,2) + math.pow(point2,2)) end
The pythagorean theorem says that
1
side1^2 + side2^2 = hipotenuse^2
Here I can show you an image and try to explain:
In case you didn't know, the red line is the hypotenuse (the shortest distance between a point an another) and the black ones are the other sides.
The side from the bottom is the horizontal distance from point a to point b, to get this distance we just need to know the difference between a.x and b.x, so we use a substraction. The same happens with the left side and the vertical distance.
So, this is how you use the function I wrote before.
1
distance(point1.x - point2.x, point1.y - point2.y)
Now, you might be asking yourself how can an hypotenuse be useful for circular detection.
Since the hypotenuse is the shortest path from one point to another (because it's a straight line, and this never fails in 2D) we can detect if to circles are colliding using the circle's radius.
1
2
3
2
3
if distance(a.x - b.x, a.y - b.y) <= a.r + b.r then 	--Circles are colliding! end
And here I will show you a way to detect the players nearby, both with bounding box (when called with 4 parameters) and circular collision detection (when called with 3).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function getNearPlayers(xpos,ypos,xdist,ydist) 	local players_nearby = player(0,"table") 	if ydist then --BOUNDING BOX 		for i,p in ipairs(players_nearby) do 			if math.abs(player(p,"tilex")-xpos) > xdist then 				table.remove(players_nearby,i) 			elseif math.abs(player(p,"tiley")-ypos) > ydist then 				table.remove(players_nearby,i) 			end 		end 	else --CIRCLE (XDIST IS RADIUS) 		for i,p in ipairs(players_nearby) do 			if distance(xpos-player(p,"tilex"), ypos-player(p,"tiley")) > xdist then --This player is too far, remove him 				table.remove(players_nearby,i) 			end 		end 	end 	return players_nearby end
edited 2×, last 06.01.10 08:11:03 am
Anyway, i never liked the %s or the .. to concenate strings...
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
local _mtstr = getmetatable("") function _mtstr.__add(self,other) 	if(type(other) == "table") then 		return string.format("%s %s",self,unpack(other)) 	else 		return string.format("%s %s",self,other) 	end end example: msg("Hi all my" + 25 + "friends!") parse("setarmor" + 1 + 100)
But i doubt it's fast for large chuncks of text
It's almost the same colliding stuff I used for my physics game before 3 months.
Same pythagorean theorem + some bouncing.
Screenshot:
Yellow means "Oval shouldn't be stuck" - but not always.
edited 1×, last 06.01.10 01:37:20 pm
As the flashlight's Zombie Plague but only that the same person can see
I made this:
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
addhook("hit","badc.hit") function badc.hit(id,src,wpn,hpdmg) 	if player(id,"health")-hpdmg < 30 then 		msg2(id,"©255255255You are hurt, Get Cover!@C") 		for i = 1,32,1 do 		img = image("gfx/!Huevitorojo Sprites/Bind.png",1,1,100 + i) 			imagecolor(img,250,250,250) 			imageblend(img,1) 		end 	end end
Help ME!
Sorry for my English
Another thing i need but not as much as the other one lua that would give like $1 at a area.(work spot)
Deatherr has written
I have a lua for my Town([DS] Town) server. If a "Give Money". You say "!give <id> <money>". It works but people been saying something like "!give 10 -16000" And when they say that they steal/bug money off of people! and even if they don't have that much the person still gets the money so i'm asking for a small/big lua that if the player uses (-) in there "!give" command their money will be set to 0.
Ok, post the script I gave you before so we can fix it
That's probably same ZP 1.1b ( !giveap <id> <APs> ) script... With same bug.
To fix that bug, you have check "if money > 0 then" for example.
I made some funny small scripts some time ago, but I never found a way to share them.
So one of them is Oval Hudtext Animation
This script also includes some small Hex color tricks.
HudText Color Changes
HudText Letter Changes
Oval Size Changes
Oval Rotation Changes
Screens:
Script looks like I'm kidding around
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-------------------------------------------------------- -- Hudtext Oval By Blazzing -- Blazz Library: 14th - Hudtxt Oval Animation Script -- 2009/11/20 - v1.2 -------------------------------------------------------- addhook([[always]],[[blazz_oval]]) abc = [[ABCDEFGHIJKLMNOPQRSTUVWXYZ]] letter = {} color = {0x00,0x11,0x33,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff} zeros = {[[00]],[[0]],[[0]],[[0]],[[0]],[[0]]} hudtxt_count = 47 oval = {} oval.x = 320 ; oval.y = 240 oval.rot = 0 oval.letter = 1 oval.set = 1.5 oval.size = 150 for let = 1, #abc, 1 do 	letter[let] = string.sub(abc, let, let) end for i = 1, #zeros do 	color[i] = zeros[i]..color[i] end local function blazz_hudtxt(s,t,x,y) 	parse([[hudtxt ]]..s..[[ "©]]..oval.color..t..[[" ]]..x..[[ ]]..y..[[ 1]]) end local function blazz_rndcolor() 	local r, g, b 	r = color[math.random(1,#color)] 	g = color[math.random(1,#color)] 	b = color[math.random(1,#color)] 	return r..g..b end oval.color = blazz_rndcolor() function blazz_oval() 	local i, x, y, rot 	for i = 0, hudtxt_count, 1 do 		rot = oval.rot + (i * (360 / 50)) 		x = oval.x + math.cos(rot) * oval.size 		y = oval.y + math.sin(rot) * oval.size 		blazz_hudtxt(i,letter[oval.letter], x, y) 	end 	if (oval.size > 250 or oval.size < 32) then 		math.randomseed(os.time()) 		oval.color = blazz_rndcolor() 		oval.set = oval.set / - 1 		oval.letter = math.random(1,#letter) 	end 	oval.size = oval.size + oval.set 	oval.rot = oval.rot + (.1 * oval.set) end
edited 1×, last 07.01.10 05:29:38 pm
How i make Script that you can enter car with pressing "E" and Leave it pressing"E" ?
HELP!
i need it too.
Ha4r has written
Can anyone help me?
How i make Script that you can enter car with pressing "E" and Leave it pressing"E" ?
HELP!
How i make Script that you can enter car with pressing "E" and Leave it pressing"E" ?
HELP!
Transformation v1.0 by editorman
http://www.unrealsoftware.de/files_show.php?file=131
CrashDay mode 1.0 by Fapicon
http://www.unrealsoftware.de/files_show.php?file=153
it work saying it..