Page 1 of 1
ShowDamage
Posted: Mon Oct 05, 2015 9:18 pm
by Jerome69
Posted: Mon Oct 05, 2015 9:58 pm
by satoon101
You have to get the event variables from the GameEvent object (which we call game_event in event callbacks). dmg_health is a byte value, so you want to use get_int to get its value:
[python] damage = game_event.get_int('dmg_health')[/python]
Posted: Tue Oct 06, 2015 11:38 am
by Jerome69
Thanks it works

When I put :
Syntax: Select all
attacker= game_event.get_int('attacker')
It returns me "2"...
How can I send a message only to the attacker? I know how to send a message to a team, but not to a single player...
Posted: Tue Oct 06, 2015 11:59 am
by Ayuto
Syntax: Select all
from players.helpers import index_from_userid
from messages import SayText2
from events import Event
@Event('player_hurt')
def on_player_hurt(event):
attacker = event.get_int('attacker')
if not attacker:
# If the attacker is 0, the damage was done by the world (e.g. fall damage)
return
# Convert the userid into an index
index = index_from_userid(attacker)
# Send the message only to the attacker
SayText2('You hit somebody.').send(attacker)
Posted: Wed Oct 07, 2015 2:54 am
by satoon101
Ayuto meant this to be the last line:
Syntax: Select all
SayText2('You hit somebody.').send(index)
Posted: Wed Oct 07, 2015 7:26 am
by Jerome69
Ok it works fine, thanks.
Now, I would like to show the damage on the center screen, so I added this, as Satoon told me in another plugin request (
bomb):
Syntax: Select all
from players.helpers import index_from_userid
from messages import SayText2
from messages import TextMsg
from events import Event
# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('player_hurt')
def on_player_hurt(event):
damage = event.get_int('dmg_health')
attacker = event.get_int('attacker')
if not attacker:
# If the attacker is 0, the damage was done by the world (e.g. fall damage)
return
# Convert the userid into an index
index = index_from_userid(attacker)
# Send the message only to the attacker
TextMsg('Essai', HudDestination.CENTER).send(index)
But it tolds me this :
The attachment Erreur.jpg is no longer available
Do you know why?
Posted: Wed Oct 07, 2015 8:40 am
by Ayuto
You have to import HudDestination.
Syntax: Select all
from messages import HudDestination
Posted: Wed Oct 07, 2015 8:41 am
by Predz
You haven't defined HudDestination and so therefore cannot use it. In this case you must import it directly from the SourcePython modules. Look below for the import:
Syntax: Select all
from messages import HudDestination
EDIT: God damn you Ayuto xD
Posted: Wed Oct 07, 2015 8:53 am
by Jerome69
Ho yeah, it works fine. Thanks
Now I have to add a message at the end of the round with the total damage done
I will give you news (or ask help ^^)
Posted: Sat Oct 24, 2015 7:59 am
by Jerome69
Finally, I ask help...
I would like to create an array and reset it at each round start.
This array will contain the userid and the total damage done by round. So at each hunt, the array is updated.
How I can do this please? I didn't find the answer anywhere...
Thanks
Posted: Sat Oct 24, 2015 8:58 am
by Ayuto
In Python you don't use arrays. Your choice would be a dictionary. In this case a
defaultdict would be the best choice.
Syntax: Select all
import collections
# Create a new defaultdict that gets initialized with int() when a key is
# missing
total_damage = collections.defaultdict(int)
# Will print an empty dictionary
print(total_damage)
# Add 50 to the value of the key 2. Note: that key doesn't exist, yet. But
# since this is a defaultdict, it will be created and its value will be
# initialized with int(), which returns 0.
total_damage[2] += 50
# Will print {2: 50}
print(total_damage)
# Add 25. This time the key exists, so it doesn't initialize anything
total_damage[2] += 25
# Will print {2: 75}
print(total_damage)
# Empty the whole dictionary
total_damage.clear()
# Will print {}
print(total_damage)
Posted: Sat Oct 24, 2015 10:05 am
by Jerome69
Posted: Sat Oct 24, 2015 11:38 am
by Ayuto
Posted: Sat Oct 24, 2015 1:57 pm
by Jerome69
Yeah, it works fine.
Thanks a lot

Posted: Mon Feb 15, 2016 12:02 pm
by Jerome69
I have this line :
Syntax: Select all
TextMsg('- {0} HP'.format(damage), HudDestination.CENTER).send(index)
How can I do to display it with a specific number of seconds?
Thanks
Posted: Mon Feb 15, 2016 1:37 pm
by satoon101
The center message lasts about 3 seconds, if I remember correctly. That, by itself, is not something we can change. However, if you wish for the message to last longer, you can send the message again after a delay.
Syntax: Select all
message = TextMsg('- {0} HP'.format(damage), HudDestination.CENTER)
message.send(index)
Delay(3, message.send, index)
I think you can also make the message last a shorter amount of time if you send an empty message after a delay to cancel out the old message.
Syntax: Select all
TextMsg('- {0} HP'.format(damage), HudDestination.CENTER).send(index)
Delay(1, TextMsg(' ', HudDestination.CENTER).send, index)
The danger in both situations is if another plugin sends a message before the delayed message, it will be cut short.
Posted: Tue Feb 16, 2016 2:17 pm
by Jerome69
Ok thanks.
I think another plugin send an empty message just after my plugin.
I'll see to change it.
Posted: Wed Feb 17, 2016 9:15 pm
by L'In20Cible
Note that if you send the message on round start, you need to wait at least 1 frame since the server is sending a ResetHud every rounds.