Page 1 of 1

damage inflicted

Posted: Thu Mar 05, 2015 1:56 pm
by MrMalina
I just wanted to cause damage user. For this I used the code:

Syntax: Select all

aplayer.damage (uplayer.index, 500)

I got an error:
second_error.jpg


I changed the code to:

Syntax: Select all

aplayer.damage (uplayer.index, 500, damage_types.FALL)


Get an error:
second_error.jpg


I changed the code to:

Syntax: Select all

index = tuple (aplayer.weapon_indexes ())
aplayer.damage (uplayer.index, 500, damage_types.FALL, weapon_index = index [0])


Get an error:
second_error.jpg


I changed the code to:

Syntax: Select all

def take_damage(victim, attacker, damage, type, weapon=0):
take_damage_info = TakeDamageInfo()
take_damage_info.hAttacker = inthandle_from_userid(attacker)
take_damage_info.hInflictor = inthandle_from_userid(attacker)
take_damage_info.hWeapon = weapon
take_damage_info.flDamage = damage
take_damage_info.bitsDamageType = type
victim.take_damage(take_damage_info)

take_damage(uplayer, aplayer.userid, 500, 32, weapon)


No error and not damage.

How do I deal damage to the player?

Posted: Fri Mar 06, 2015 7:27 am
by L'In20Cible
I really don't think your version is up-to-date. The following works just fine for me:

Syntax: Select all

from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid

@Event
def player_jump(game_event):
player = PlayerEntity(index_from_userid(game_event.get_int('userid')))
player.damage(1)

Posted: Fri Mar 06, 2015 3:41 pm
by MrMalina
I wanted to deal damage some other players, not yourself.

I got to put it this code. Suddenly, someone will need:

Syntax: Select all

# ======================================================================
# >> IMPORTS
# ======================================================================

from random import choice

# Source.Python
from events import Event

from players.entity import PlayerEntity
from players.helpers import index_from_userid
from filters.players import PlayerIter

from entities.entity import BaseEntity
from basetypes import TakeDamageInfo


# ======================================================================
# >> GAME EVENTS
# ======================================================================
@Event
def player_jump(game_event):

userid = game_event.get_int('userid')
index=index_from_userid(userid)
player=PlayerEntity(index)

index_victim=PlayerIter(is_filters={3:'t', 2:'ct'}[player.team], return_types="index")

damage(index, tuple(index_victim)[0], 555, 32)


# ======================================================================
# >> DAMAGE FUNCTION
# ======================================================================
def damage(victim_index, attacker_index, damage, damage_type):

victim = BaseEntity(victim_index)

take_damage_info = TakeDamageInfo()
take_damage_info.inflictor = victim_index
take_damage_info.attacker = attacker_index
take_damage_info.damage = damage
take_damage_info.type = damage_type

victim.take_damage(take_damage_info)


And I'm using the latest build of the sp (2 March 2015),
and an example of the damage taken from the theme.

Posted: Fri Mar 06, 2015 4:25 pm
by satoon101
Currently the damage method causes damage from the current instance to the given entity index. There are plans to change that, they just haven't happened yet.

Posted: Fri Mar 06, 2015 11:51 pm
by L'In20Cible
MrMalina wrote:I changed the code to:

Syntax: Select all

def take_damage(victim, attacker, damage, type, weapon=0):
take_damage_info = TakeDamageInfo()
take_damage_info.hAttacker = inthandle_from_userid(attacker)
take_damage_info.hInflictor = inthandle_from_userid(attacker)
take_damage_info.hWeapon = weapon
take_damage_info.flDamage = damage
take_damage_info.bitsDamageType = type
victim.take_damage(take_damage_info)

take_damage(uplayer, aplayer.userid, 500, 32, weapon)


No error and not damage.

How do I deal damage to the player?

This quote made me think so since you said "no error" and those attributes are renamed for a while now.