Forum

> > CS2D > Scripts > Function cooldown time
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Function cooldown time

15 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Function cooldown time

En-Kay
User Off Offline

Zitieren
I'm adding some spells for some classes. Is there any way of adding cooldown for like a minute or so for those spells?

alt Re: Function cooldown time

DC
Admin Off Offline

Zitieren
A very simple solution would be to do something with cs2d lua cmd timer (click for reference and samples). You could also work with timestamps and their difference instead.

alt Re: Function cooldown time

Infinite Rain
Reviewer Off Offline

Zitieren
1. Create a cooldown variable
2. When player uses spell, set cooldown variable to whatever the cooldown time you want.
3. Decrease this variable by 1 each second in second hook.
4. When cooldown is 0, make players be able to use that spell again.

It's incredibly simple. I didn't give you the code because I need to see your code in order to properly make it.

If you want me (or someone else) to write the code for cooldown, then post your code here.

alt Re: Function cooldown time

En-Kay
User Off Offline

Zitieren
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
--RAIN OF FIRE--

addhook ("say","hellfire")
function hellfire (id,text)

x=player(id,"x")
y=player(id,"y")
x1=128
y1=128
x2=256
y2=256


function expl1(id)
	parse ("explosion "..(x+x1).." "..y.." 125 75 "..id)
	parse ("explosion "..x.." "..(y+y1).." 125 75 "..id)
	parse ("explosion "..(x+70).." "..(y+70).." 125 75 "..id)
	parse ("explosion "..(x-x1).." "..y.." 125 75 "..id)
	parse ("explosion "..x.." "..(y-y1).." 125 75 "..id)
	parse ("explosion "..(x-70).." "..(y-70).." 125 75 "..id)
	parse ("explosion "..(x-70).." "..(y+70).." 125 75 "..id)
	parse ("explosion "..(x+70).." "..(y-70).." 125 75 "..id)
end

function expl2(id)
	parse ("explosion "..(x+x2).." "..y.." 125 75 "..id)
	parse ("explosion "..x.." "..(y+y2).." 125 75 "..id)
	parse ("explosion "..(x+140).." "..(y+140).." 125 75 "..id)
	parse ("explosion "..(x-x2).." "..y.." 125 75 "..id)
	parse ("explosion "..x.." "..(y-y2).." 125 75 "..id)
	parse ("explosion "..(x-140).." "..(y-140).." 125 75 "..id)
	parse ("explosion "..(x-140).." "..(y+140).." 125 75 "..id)
	parse ("explosion "..(x+140).." "..(y-140).." 125 75 "..id)	
end

	if (sample.classes.class[id]==8) then
		if (text=="!spell1") then
			if (player(id,"money")==16000) then
			 	parse ("setmoney "..id.." -16000")
				expl1(id)
				timer (500,"expl2" ,id)
			else
				msg2 (id, "You do not have enough mana!")
			end
		end
	end
end

alt Re: Function cooldown time

TimeQuesT
User Off Offline

Zitieren
It is pretty simple to do this as user Infinite Rain said.

Logical steps >


Example code >

alt Re: Function cooldown time

TimeQuesT
User Off Offline

Zitieren
You do not have to put all your code there.
PM me your full code and I will help you.

Edit: I noticed that you already posted the important part. Give me some time.
Edit²:
code >
1× editiert, zuletzt 30.08.14 23:44:53

alt Re: Function cooldown time

En-Kay
User Off Offline

Zitieren
Yes I believe it works, but I keep getting this error:

Zitat
LUA ERROR: sys/lua/core/default.lua:281: bad argument #1 to 'msg2' (number expected, got no value)

alt Re: Function cooldown time

En-Kay
User Off Offline

Zitieren
Yes it works now but can just tell me where should I add msg2(id, "Spell is ready") when cooldown is over?

alt Re: Function cooldown time

TimeQuesT
User Off Offline

Zitieren
user En-Kay hat geschrieben
Yes it works now but can just tell me where should I add msg2(id, "Spell is ready") when cooldown is over?

There where you're decreasing the cooldown variable.

alt Re: Function cooldown time

En-Kay
User Off Offline

Zitieren
If I want to add cooldown for more spells, do I have to copy whole function and just change names or can I just add spells to this one?

edit:

Ok I got it.
1× editiert, zuletzt 31.08.14 13:04:12
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht