Forum

> > CS2D > General > Lua scripting tutorial
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Lua scripting tutorial

51 replies
Page
To the start Previous 1 2 3 Next To the start

old Re: Lua scripting tutorial

lenz-_-
User Off Offline

Quote
And i don't get the hook part for some reason..
I watched at DC's samples as well, but i think i owe this misunderstanding to my bad english..
and i really want to teach myself..
Well, in this case , i guess i am a newbie, not a noob...

old Re: Lua scripting tutorial

SQ
Moderator Off Offline

Quote
In cs2d hook means when to apply function.
Example:

addhook("Period when to apply function","function name")

Periods like :
Join - every player join
minute - each minute
spawn - every time player spawn
edited 1×, last 03.07.09 05:11:24 pm

old Re: Lua scripting tutorial

ohaz
User Off Offline

Quote
you need to add hooks, which are called when something in game happens and then call their function.
addhook(1, 2)
function 2(param1, param2,....)
1 is a special text, you need to either know it, or watch into the info.txt in your /sys/lua folder.
it's always something like say, kill, die, spawn, ....
2 is a name you can give this hook. When the hook is called, it will call the function which has the same name.
(in this case function 2)

old Re: Lua scripting tutorial

ohaz
User Off Offline

Quote
1
2
3
4
5
6
addhook("kill", "restartonkill")
function restartonkill(killer, victim)
if (victim == 1) then
	parse("sv_restart 0")
end
end

old Re: Lua scripting tutorial

Alpha Beta
User Off Offline

Quote
Then try that:
1
2
3
4
5
6
addhook("die", "restartonkill")
function restartonkill(victim,killer,weapon,x,y)
	if (victim == 1) then
		parse("sv_restart 0")
	end
end
Should work for team gate ,too...
edited 1×, last 03.07.09 07:39:10 pm

old Re: Lua scripting tutorial

ohaz
User Off Offline

Quote
1
2
3
4
5
6
addhook("die", "restartondie")
function restartondie(victim)
if (victim == 1) then
	parse("sv_restart 0")
end
end
@ heavy: you mixed the parameters!

old closed Re: Lua scripting tutorial

mortyr22
User Off Offline

Quote
how to create reloading after 2 shots?

Admin/mod comment

Don't spam around with your question! Everybody here has read it at least a thousand times already. /TheKilledDeath
To the start Previous 1 2 3 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview