Page 1 of 1

KillerInfo

Posted: Fri Mar 25, 2016 8:23 am
by Jerome69

Posted: Fri Mar 25, 2016 10:50 am
by Kami
You get this error, because you actually did not define "player_index". But you already have the Player Entity for the attacker, so you can just use "killer" instead of first player.
Now you also did not define "other_index" which would be the victims index. But you defined "victim" which IS the victims index so you can just use that instead of "other_index".

Something like this:

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python
from menus import Text
from events import Event
from mathlib import Vector
from menus import SimpleMenu
from messages import SayText2
from players.entity import Player
from weapons.entity import Weapon
from players.helpers import index_from_userid

# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('player_death')
def player_death(event):
victim = index_from_userid(event.get_int('userid'))
killerID = event.get_int('attacker')

#Was it a suicide?
if killerID == 0 :
return

killer = Player(index_from_userid(event.get_int('attacker')))
weapon = event.get_string('weapon')

second_player = Player(victim)
distance = killer.origin.get_distance(second_player.origin)

menu = SimpleMenu()
menu.append(' Killer Info')
menu.append('--------------------------------')
menu.append('Killer : {0}'.format(killer.name))
menu.append('Arme : {0}'.format(weapon))
menu.append('Distance : {0}'.format(distance))
menu.append('Vie restante : {0}'.format(killer.health))
menu.append('Armure restante : {0}'.format(killer.armor))
menu.append(' ')
menu.append('0. Quitter')
menu.send(victim)

Posted: Fri Mar 25, 2016 11:21 am
by Ayuto

Posted: Fri Mar 25, 2016 12:13 pm
by satoon101
A few points/tips. First, we (fairly) recently added the ability to use GameEvent objects as if they were dictionaries. You can still use the get_<type> methods if you wish, but the __getitem__ method "should" always return the values with the proper type:
http://forums.sourcepython.com/showthread.php?960


Second, you are retrieving the attacker userid twice. Also, your suicide check should not only check for equaling zero, but equaling the attacker. And, you might also want to check if it was a team kill:

Syntax: Select all

@Event('player_death')
def player_death(game_event):
userid = game_event['userid']
attacker = game_event['attacker']

# Was this a suicide?
if attacker in (0, userid):
return

victim = Player(index_from_userid(userid))
killer = Player(index_from_userid(attacker))

# Was this a team kill?
if victim.team == killer.team:
return


Lastly, you seem to have a lot of unused imports. This doesn't harm anything, I just wanted to make sure you knew that you do not have to, for instance, import Vector just because you use Vector objects. I realize that there is probably more to your code than this, but wanted to make sure to point that out.


Actually, as far as the Delay calling close(), do we not have the ability to set that within the menu object itself? This line seems to indicate that that was at least planned at some point.

Posted: Fri Mar 25, 2016 12:39 pm
by Ayuto
satoon101 wrote:Actually, as far as the Delay calling close(), do we not have the ability to set that within the menu object itself? This line seems to indicate that that was at least planned at some point.
Yes, it's planned, but that method just returns the data for ShowMenu which requires an integer that defines the duration to show the menu. However, as far as I remember that value is not really usable. If it's greater than 0, the menu shows up for 4 seconds. If the value is 0, it's shown permantently.