Forum

> > CS2D > Scripts > Explosion on player with hit hook spam
Forums overviewCS2D overview Scripts overviewLog in to reply

English Explosion on player with hit hook spam

7 replies
To the start Previous 1 Next To the start

old Explosion on player with hit hook spam

WexDex
User Off Offline

Quote
Hello everyone , So like it's mentioned in the title , when i create an explosion on the hitted player (his x and y) on hit , the explosion just spams about 50 times or more
Here's an example :
1
2
3
4
addhook("hit","OnHit")
function OnHit(id,source)
	parse("explosion " ..player(id,"x") .." " ..player(id,"y") .." 50 20 "..source)
end

it made my game crash

old Re: Explosion on player with hit hook spam

DC
Admin Off Offline

Quote
Well... the problem is that the explosion causes damage. And the damage will trigger a new hit-event because the player is damaged (= hit) by the explosion. This is very dangerous. It might even lead to stack overflows and infinite loops.

There are two workarounds:

• spawn the explosion without damage and cause damage manually. This might not be what you want though because maybe you want to damage everything and not just that single player.

• Better: Check the parameters of the cs2d lua hook hit hook. A simple check would be:
1
2
3
4
5
function OnHit(id,source, weapon)
     if weapon~=251 then
          parse("explosion " ..player(id,"x") .." " ..player(id,"y") .." 50 20 "..source)
     end
end
untested! 251 is the internal ID for explosions. See: cs2d lua hook hit
The if means in words: If the hit comes from an explosion ignore it and do NOT trigger a new explosion.

old Re: Explosion on player with hit hook spam

WexDex
User Off Offline

Quote
@user DC: so i did as you said ,it worked yes .But now the explosion only sometimes do damage.
EDIT : if the damage is higher than 120 the player dies , but if it's small it doesn't do any damage

old Re: Explosion on player with hit hook spam

omg
User Off Offline

Quote
the explosion is obviously hitting the intended target because in the first part you said the explosion kept looping. so the explosion just isnt doing as much damage as u expect it to

old Re: Explosion on player with hit hook spam

VADemon
User Off Offline

Quote
@user omg: the explosion is surely triggering the hook repeatedly, it doesn't mean the player can't be damaged due to a game bug (paraphrased: hook works, damage doesn't)

We can check this case as well:
1
2
3
4
5
6
7
8
addhook("hit","onExplosionHitOnce")
function onExplosionHitOnce(id, source, weapon, hpdmg, armordmg, rawdmg)
   if weapon == 251 then
      msg("Explosion registered! Player ID: ".. id .." Source: ".. source .." Weapon ID: ".. weapon)
      msg("HP dmg: ".. hpdmg .." Armor dmg: ".. armordmg .." Raw: ".. rawdmg)
      freehook("hit","onExplosionHitOnce")
   end
end
This code was written on my phone, excuse me for possible errors.

old Re: Explosion on player with hit hook spam

WexDex
User Off Offline

Quote
@user VADemon: With the freehook it works well √ . But Once
EDIT : First ,when the explosion was spamming on the player , he didn't die . so it wasn't doing the damage from the beginning :x
edited 3×, last 27.01.16 12:25:03 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview