Lua Scripting Crash Course!
5 replies



10.09.12 06:45:23 am
Hey everyone, I'm new to the forum and I was wondering if anyone would want to give me a crash course on Lua Scripting so I can make a script for a zombie mod that I have been wanting to make for ages (Google doesn't offer me a good understanding of scripting). Some things I wanted to do in the script were:
Making zombies walk slower
Giving zombies a random health amount
Making zombies appear randonly on the map
Zombies respawning after death
Any help would be greatly appreciated! Thank you!
Making zombies walk slower
Giving zombies a random health amount
Making zombies appear randonly on the map
Zombies respawning after death
Any help would be greatly appreciated! Thank you!
I can make you a script that does all that but if you want a full tutorial there is some in the Scripting forum
Or I could make one...
Just browse to
(Note the .lua)
and open
server.lua
then just type
dofile("sys/lua/zombieMod.lua")
save and close.
It should work.
Or I could make one...
Code:
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
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
-- UNTESTED --
zm={}
-- <editable values> --
zm.speedmod=-15 -- Speedmod for zombies
zm.healthMin=80 -- Min and max extremes of health giver
zm.healthMax=120
zm.xPositions={1,2 ,3 ,4 ,5 } -- choices for x and y positions, 2 from the same column are picked randomly, example is 1 and 7
zm.yPositions={7,14,21,28,35} -- because of this, each table must have the same amount of entries
zm.defaultSpawnpoint={52,33} -- just put {x,y} of any walkable tile.
-- <end of editable values> --
addhook("spawn","zombieSpawn")
addhook("die","zombieDie")
function zombieSpawn(id)
local pos=math.random(1,#xPositions)
if player(id,"team")==1 then
parse("setpos "..id.." "..( math.random(1,pos) ).." "..( math.random(1,pos) ) ) -- Spawn at random spot
parse("speedmod "..id.." "..zm.speedmod) -- Speed
parse("sethealth "..id.." "..( math.random(zm.healthMin,zm.healthMax) ) ) -- Health
end
end
function zombieDie(id)
if player(id,"team")==1 then
parse("spawnplayer "..id.." "..zm.defaultSpawnpoint[1].." "..zm.defaultSpawnpoint[2])
end
end
zm={}
-- <editable values> --
zm.speedmod=-15 -- Speedmod for zombies
zm.healthMin=80 -- Min and max extremes of health giver
zm.healthMax=120
zm.xPositions={1,2 ,3 ,4 ,5 } -- choices for x and y positions, 2 from the same column are picked randomly, example is 1 and 7
zm.yPositions={7,14,21,28,35} -- because of this, each table must have the same amount of entries
zm.defaultSpawnpoint={52,33} -- just put {x,y} of any walkable tile.
-- <end of editable values> --
addhook("spawn","zombieSpawn")
addhook("die","zombieDie")
function zombieSpawn(id)
local pos=math.random(1,#xPositions)
if player(id,"team")==1 then
parse("setpos "..id.." "..( math.random(1,pos) ).." "..( math.random(1,pos) ) ) -- Spawn at random spot
parse("speedmod "..id.." "..zm.speedmod) -- Speed
parse("sethealth "..id.." "..( math.random(zm.healthMin,zm.healthMax) ) ) -- Health
end
end
function zombieDie(id)
if player(id,"team")==1 then
parse("spawnplayer "..id.." "..zm.defaultSpawnpoint[1].." "..zm.defaultSpawnpoint[2])
end
end
Just browse to
Code:
and put the above in somthing like zombieMod.lua<CS2D INSTALL ROOT>\sys\lua\
(Note the .lua)
and open
server.lua
then just type
dofile("sys/lua/zombieMod.lua")
save and close.
It should work.
edited 1×, last 10.09.12 07:45:19 pm
Thanks! Your are awesome! I might just use your script (I will credit and all!). After I make some tiles, weapons sprites and a map, if I do ever upload the mod, I'll be sure that your name is in it! btw, any idea on removing the money system from the HUD and changing the hud's look/style?
dont upload the finished product as there are already tons of files that are similar to each other and most of them dont compare to the original constructs
will code for food
omg has written:
dont upload the finished product as there are already tons of files that are similar to each other and most of them dont compare to the original constructs
Well then I will send the contributers a copy of the mod if they want it.

Thanks! Your are awesome! I might just use your script (I will credit and all!). After I make some tiles, weapons sprites and a map, if I do ever upload the mod, I'll be sure that your name is in it! btw, any idea on removing the money system from the HUD and changing the hud's look/style?
check console command mp_hud



