Damaging a player
Posted: Mon Jan 14, 2013 5:51 pm
Not sure if you all have been keeping track of the repository, but L'In20Cible and I worked through the issues we had with getting damage to work, and it now works properly (with the exception of the hitgroup offset). All entities, not just players, can damage any other entity, so we added it to the BaseEntity class instead of just the PlayerEntity class.
We also added constants for damage types, so you do not have to remember them, and if they change, it will be a quick plugin-side fix instead of a script-by-script fix. The test script I use is as follows:Again, the hitgroup offset is wrong, and I still need to look that up again. If you have any other questions on this please feel free to ask away.
Satoon
We also added constants for damage types, so you do not have to remember them, and if they change, it will be a quick plugin-side fix instead of a script-by-script fix. The test script I use is as follows:
Syntax: Select all
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from filters.players import PlayerIter
from entities.constants import DamageTypes
hitgroups = [
'Generic',
'Head',
'Chest',
'Stomach',
'Left Arm',
'Right Arm',
'Left Leg',
'Right Leg'
]
@Event
def round_freeze_end(GameEvent):
for player in PlayerIter(return_types='player'):
player.freeze = True
@Event
def player_say(GameEvent):
userid = GameEvent.GetInt('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
team = player.team
other = get_other_player(team)
player.damage(other, 400, DamageTypes.HEADSHOT, hitgroup=2, iObjectsPenetrated=2)
def get_other_player(team):
for player in PlayerIter(return_types='player'):
if player.team != team and not player.isdead:
return player.index
return None
@Event
def player_hurt(GameEvent):
userid = GameEvent.GetInt('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
attackerid = GameEvent.GetInt('attacker')
attacker_index = index_from_userid(attackerid)
attacker = PlayerEntity(attacker_index)
damage = GameEvent.GetInt('dmg_health')
armor = GameEvent.GetInt('dmg_armor')
weapon = GameEvent.GetString('weapon')
hitgroup = hitgroups[GameEvent.GetInt('hitgroup')]
print('%s damaged %s for %s/%s health with his %s in the %s' % (
attacker.name, player.name, damage, armor, weapon, hitgroup))
Satoon