KillerInfo

Please post any questions about developing your plugin here. Please use the search function before posting!
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

KillerInfo

Postby Jerome69 » Fri Mar 25, 2016 8:23 am

User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Fri Mar 25, 2016 10:50 am

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)
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Mar 25, 2016 11:21 am

User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Mar 25, 2016 12:13 pm

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.
Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Mar 25, 2016 12:39 pm

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 151 guests