Forum

> > CS2D > Scripts > Countdown+Effect
Forums overviewCS2D overview Scripts overviewLog in to reply

English Countdown+Effect

13 replies
To the start Previous 1 Next To the start

old Countdown+Effect

Kirito2K
User Off Offline

Quote
Hi us , i have a magic script and i need a help with making a :-
1-Countdown when player uses spell , spell countdown time should be 5m (300s)
2-Real effects when a player uses a spell , same as if i use spell speed then my speed will be increased.
3-Shown effect , when a player uses a spell a effect will be shown on the player who used it like a blue smoke..

>
Script >

old Re: Countdown+Effect

Bowlinghead
User Off Offline

Quote
1. Countdown example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
player_cdtime = {} -- a table for every player´s countdown time

addhook("second","second_counter")
function second_counter()
	for _, id in pairs(player(0,"table")) do -- a loop with every player id.
		if (player_cdtime[id] < 300) then
			player_cdtime[id] += 1
		else
			msg2(id,string.char(169).."000255000You can use your spell again@C")
		end
	end
end

-- call this function when somebody uses a spell
function UseSpell(id)
	if (player_cdtime[id] < 300) then
		msg2(id,string.char(169).."255000000You can´t use this now.")
	else
		player_cdtime[id] = 0
		-- what happens when the player calls the spell?
		-- put commands here
	end
end
This will not wait exactly 300 seconds. In the worst case these can be 299 or 301 seconds. But nobody will notice.
For a perfect timer:
More >


2. Real effects:
what do you mean?
cs2d cmd explosion ?
You can use every console-command in Lua with cs2d lua cmd parse .
For speed you would write something like this:
1
parse("speedmod "..id.." "..player(id,"speedmod")+20) -- increases player speed by 20
3. Spell effect:
What type of effect do you mean?
edited 3×, last 26.05.15 11:59:55 am

old Re: Countdown+Effect

Kirito2K
User Off Offline

Quote
I didn't mean all of that lol ..

1-Countdown for use spell i meant like when i use spell the effect of spell removes after 5m , not countdown for use another time.

2-real effect same as speed , when i use speed spell i get speed for 5m..

3-shown effect like fire/flare/smoke/colored smoke (effect cmd) ..

I'm a bit bad at those stuff ..

old Re: Countdown+Effect

Bowlinghead
User Off Offline

Quote
He gave us more information even though my question was silly.

code >

Call UseSpellSpeed(id) whenever you want to start der speed spell.
This is just an example. You can read more here: cs2d cmd effect , cs2d cmd parse

old Re: Countdown+Effect

Kirito2K
User Off Offline

Quote
That for the speed spell , the other spells would be same , got it thx.

Another thing , i have a attack spell i want when a player use it his wpn damage increase , and only for him .

/Edit : After using it , i have some bugs and i fixed them but i have a wrong in your lua which when the timer ends player slows because of (speedmod "..id.." -25) so changed to (speedmod "..id.." 0) another thing when timers end the Spell Stopped msg repeats because of the second hook , idk how to fix help please .

And btw when i kill my self and i use a spell the speed disappear but smoke still , fix this too please .
edited 2×, last 27.05.15 06:21:30 am

old Re: Countdown+Effect

Ridho
User Off Offline

Quote
user Kirito2K
Quote
Another thing , i have a attack spell i want when a player use it his wpn damage increase , and only for him


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addhook("hit","damage_")
function damage_(receiver,attacker,normaldamage)
  if spell[attacker]==true then
    if player(id,"weapontype")==weaponid then
      local hpinflicted=normaldamage*spelldamage
      if player(attacker,"team")~=player(receiver,"team") then
        if player(receiver,"health")>hpinflicted then
          parse("sethealth "..id.." "..player(id,"health")-hpinflicted)
          return 1 --to prevent other damage
        else
          parse("customkill "..attacker.." "Spell Name" "..receiver)
        end
      end
    end
  end
end

Quote
another thing when timers end the Spell Stopped msg repeats because of the second hook

I give you an example
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
addhok("spray","example_")
function example(id)
  if spell[id]==1 then
    spellmode[id]=true
    timer=30
    msg(""..player(id,"name").." used a Spell")
  end
end

addhook("second","continuing_")
function continuing_(id)
  for id=1,32 do
    if player(id,"exist") then
      if spellmode[id]==true then
        timer=timer-1
        --add ur effect here
        if timer=0 then
          spellmode[id]=false
          msg(""..player(id,"name").."'s Spell is now Off")
          --ur effect when the spell is off, you can ignore this
        end
      end
    end
  end
end

untested but I hope it works and you can understand my code

old Re: Countdown+Effect

Bowlinghead
User Off Offline

Quote
I don´t see a way to make this code more readable.
another code >

untested but I added much commants.
edited 1×, last 27.05.15 03:58:02 pm

old Re: Countdown+Effect

Kirito2K
User Off Offline

Quote
i tested your code but it have many bugs , i fixed them , then this bug pop up and annoyed me , i tried to slove it but i can;t :S
error >


The code another time >

old Re: Countdown+Effect

Bowlinghead
User Off Offline

Quote
It doesn´t help me when I only have the line number as reference and your code isn´t embedded as [ / code].
Pls fix (remove the [ /quote])

Edit:
the single colours you add in TimerSpells(); they need to have a space between.
So change "200000000" into "200 0 0" (these are all single parameters for the parse command, seperated with a space)
edited 1×, last 27.05.15 06:07:30 pm

old Re: Countdown+Effect

Kirito2K
User Off Offline

Quote
@user Bowlinghead: I did that and i got same error..

@user Masea: I know , us says if u have a problem with any game ask players , they could be better than u and in fact , i started scripting because of user Bowlinghead , when he made a script called with admin-app or smth like that, i downloaded it and studied it , after that i start scripting !

for that i prefer his codes..

After trying and trying i solve the problem !
This code is incorrect ..
1
2
3
4
5
6
7
addhook("second","second_hook")
function second_hook()
     for _, id in pairs(player(0,"table") do
          TimeSpells[id] -- Call this function every second for every player id
          HpSpell(id, math.random(1,11)) -- handles the HP Spell, 2nd parameter is the amount of health!
     end
end
I changed it to
1
2
3
4
5
6
7
addhook("second","second_hook")
function second_hook()
     for _, id in pairs(player(0,"table") do
          TimeSpells(id) -- Call this function every second for every player id
          HpSpell(id, math.random(1,11)) -- handles the HP Spell, 2nd parameter is the amount of health!
     end
end

After that i didn't get errors , but when i launch the lua , i try to use a spell but it says that spell is already in use , i solve that too!
The problem wasn't in your code , you just forgot to put a join hook makes the spells false when player joins , so when i use that spell it says it's already in use bcs the "ActiveSpell[spell][id]" wasn't false or even true , so i made a join hook for that ..
edited 1×, last 28.05.15 05:31:34 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview