damage inflicted

Please post any questions about developing your plugin here. Please use the search function before posting!
MrMalina
Member
Posts: 53
Joined: Mon Apr 08, 2013 2:40 pm
Location: Russian Federation

damage inflicted

Postby MrMalina » Thu Mar 05, 2015 1:56 pm

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?
Attachments
pfff.jpg
first_error.jpg
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Fri Mar 06, 2015 7:27 am

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)
MrMalina
Member
Posts: 53
Joined: Mon Apr 08, 2013 2:40 pm
Location: Russian Federation

Postby MrMalina » Fri Mar 06, 2015 3:41 pm

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.
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Mar 06, 2015 4:25 pm

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.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Fri Mar 06, 2015 11:51 pm

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 151 guests