Forum

> > CS2D > Scripts > Explosion on player with hit hook spam
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Explosion on player with hit hook spam

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Explosion on player with hit hook spam

WexDex
User Off Offline

Zitieren
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

alt Re: Explosion on player with hit hook spam

DC
Admin Off Offline

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

alt Re: Explosion on player with hit hook spam

WexDex
User Off Offline

Zitieren
@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

alt Re: Explosion on player with hit hook spam

omg
User Off Offline

Zitieren
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

alt Re: Explosion on player with hit hook spam

VADemon
User Off Offline

Zitieren
@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.

alt Re: Explosion on player with hit hook spam

WexDex
User Off Offline

Zitieren
@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
3× editiert, zuletzt 27.01.16 12:25:03
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht