Forum

> > CS2D > Scripts > sethookstate
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch sethookstate

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt sethookstate

Powermonger
User Off Offline

Zitieren
Hello again scripters,

I tried to use the sethookstate, but I couldn't get it work.

Here is my script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
items={1,2,3,4,5,6,10,11,20,21,22,23,24,30,31,32,33,34,35,36,37,38,39,91,40,45,46,47,48,49,88,90,69,74,78,85,51,52,53,72,73,75,76,86,89,77,87,41,57,58,61,62,64,65,79,80}	-- 56

addhook("kill","rg_kill")
function rg_kill(killer,victim)
	if player(killer,"team")~=player(victim,"team") then
		parse("equip "..killer.." "..items[math.random(1,56)].."")
		parse("equip "..killer.." "..items[math.random(1,56)].."")
		parse("setmoney "..victim.." 1000")
	end
end

addhook("say","cmds")
function cmds(id,txt)
	if txt:sub(1,7)=="!random" then
		if tonumber(txt:sub(8,10))==99 then
			sethookstate("rg_kill",0)
			msg("©000255255Random Rounds ON!@C")
		elseif tonumber(txt:sub(8,10))==98 then
			sethookstate("rg_kill",1)
			msg("©000255255Random Rounds OFF!@C")
		end
	end
end

Hook "rg_kill":
Player gets two random items when he kills another player and when player dies his money will decrease to 1k.

By saying "!random 99" hook will be enabled and by saying "!random 98" hook will be disabled.

It doesn't work, but it won't also give any errors.
Can you guys help me with this?

Thanks
1× editiert, zuletzt 25.08.12 11:35:38

alt Re: sethookstate

Cure Pikachu
User Off Offline

Zitieren
1
2
3
sethookstate("rg_kill",0)

sethookstate("rg_kill",1)
Replace these respectively with:
1
2
3
sethookstate("kill",0)

sethookstate("kill",1)

alt Re: sethookstate

Powermonger
User Off Offline

Zitieren
user Cure Pikachu hat geschrieben
1
2
3
sethookstate("rg_kill",0)

sethookstate("rg_kill",1)
Replace these respectively with:
1
2
3
sethookstate("kill",0)

sethookstate("kill",1)

Thanks Pikachu!
Now it works like a dream : )


Btw, does "sethookstate("kill",0)" effect to all kill hooks, if script would have more than one of them?
Is it possible to make specific hook removed?

I don't need it right now, but I might need in future, so it would be good to know.

alt Re: sethookstate

Cure Pikachu
User Off Offline

Zitieren
cs2d lua cmd sethookstate will affect all functions that are bound to the same hook across all scripts (This is an assumption, never tested it out.)
To disable certain functions, use cs2d lua cmd freehook instead. To re-activate them, use cs2d lua cmd addhook .
1
2
3
4
5
6
7
sethookstate("kill",0)
-- Becomes
freehook("kill","rg_kill")

sethookstate("kill",1)
-- Becomes
addhook("kill","rg_kill")
1× editiert, zuletzt 25.08.12 12:29:24

alt Re: sethookstate

Powermonger
User Off Offline

Zitieren
user Cure Pikachu hat geschrieben
cs2d lua cmd sethookstate will affect all functions that are bound to the same hook across all scripts (This is an assumption, never tested it out.)
To disable certain functions, use cs2d lua cmd freehook instead. To re-activate them, use cs2d lua cmd addhook .
1
2
3
4
5
6
7
sethookstate("kill",0)
-- Becomes
freehook("kill","rg_kill")

sethookstate("kill",1)
-- Becomes
addhook("kill","rg_kill")


Okay, great to know that!
And thanks again, I appreciate your help


Thread can be closed now.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht