Forum

> > CS2D > Scripts > Lua Scripting Crash Course!
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Lua Scripting Crash Course!

5 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Lua Scripting Crash Course!

mysteryguy202
User Off Offline

Zitieren
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!

alt Re: Lua Scripting Crash Course!

danh
User Off Offline

Zitieren
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...

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
-- 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

Just browse to
<CS2D INSTALL ROOT>\sys\lua\
and put the above in somthing like zombieMod.lua
(Note the .lua)

and open
server.lua

then just type
dofile("sys/lua/zombieMod.lua")

save and close.

It should work.
1× editiert, zuletzt 10.09.12 19:45:19

alt Re: Lua Scripting Crash Course!

mysteryguy202
User Off Offline

Zitieren
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?

alt Re: Lua Scripting Crash Course!

omg
User Off Offline

Zitieren
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

alt Re: Lua Scripting Crash Course!

mysteryguy202
User Off Offline

Zitieren
omg hat geschrieben
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.

alt Re: Lua Scripting Crash Course!

Happy eyes
User Off Offline

Zitieren
user mysteryguy202 hat geschrieben
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
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht