take_damage triggers player_death twice

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

take_damage triggers player_death twice

Postby Kami » Fri Jul 13, 2018 8:22 pm

Hey guys, for Warcraft Source I use skills on player_hurt which also deal damage to players. This leads to the same problem that is described here:

viewtopic.php?f=20&t=1817&hilit=take_damage

I know I could propably avoid this issue with using on_take_damage hook like in that thread but I feel like that would not be as practical in my situation.

So I'm wondering how I can prevent player_death from firing twice.

I tried the following ways of dealing damage:

Syntax: Select all

@ServerCommand('wcs_damage')
def _deal_damage(command):
victim = int(command[1])
attacker = int(command[2])
damage = int(command[3])
if len(command) > 4:
weapon = str(command[4])
else:
weapon = None
if exists(victim) and exists(attacker):
victim_player = Player.from_userid(victim)
attacker_player = Player.from_userid(attacker)
victim_player.target_name = "wcs_hurtme"
entity = Entity.create('point_hurt')
entity.set_key_value_string("DamageTarget","wcs_hurtme")
entity.damage = damage
entity.damage_type = 2
if weapon != None:
entity.set_key_value_string("classname",weapon)
entity.spawn()
entity.call_input("Hurt",activator=attacker_player)
victim_player.target_name = "wcs_donthurtme"
entity.remove()


@ServerCommand('wcs_tdmg')
def _deal_damage(command):
victim = int(command[1])
attacker = int(command[2])
damage = int(command[3])
if exists(victim) and exists(attacker):
victim_player = Player.from_userid(victim)
attacker_player = Player.from_userid(attacker)
victim_player.take_damage(damage,attacker_index=attacker_player.index)


Thank you guys :)
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: take_damage triggers player_death twice

Postby Ayuto » Fri Jul 13, 2018 9:24 pm

IIRC, you just need to check whether the player's health is already less or equal 0. If it is, don't apply the damage.
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: take_damage triggers player_death twice

Postby Kami » Sat Jul 14, 2018 12:31 am

Thank you I think this might work! :)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 21 guests