Forum

> > CS2D > Scripts > Function cooldown time
Forums overviewCS2D overview Scripts overviewLog in to reply

English Function cooldown time

15 replies
To the start Previous 1 Next To the start

old Function cooldown time

En-Kay
User Off Offline

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

old Re: Function cooldown time

DC
Admin Off Offline

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

old Re: Function cooldown time

Infinite Rain
Reviewer Off Offline

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

old Re: Function cooldown time

En-Kay
User Off Offline

Quote
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

old Re: Function cooldown time

TimeQuesT
User Off Offline

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

Logical steps >


Example code >

old Re: Function cooldown time

TimeQuesT
User Off Offline

Quote
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 >
edited 1×, last 30.08.14 11:44:53 pm

old Re: Function cooldown time

En-Kay
User Off Offline

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

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

old Re: Function cooldown time

En-Kay
User Off Offline

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

old Re: Function cooldown time

TimeQuesT
User Off Offline

Quote
user En-Kay has written
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.

old Re: Function cooldown time

En-Kay
User Off Offline

Quote
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.
edited 1×, last 31.08.14 01:04:12 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview