ShowDamage
Thanks it works 
When I put :
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...

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...
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)
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):
But it tolds me this :
Do you know why?
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 :
Do you know why?
You have to import HudDestination.
Syntax: Select all
from messages import HudDestination
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:
EDIT: God damn you Ayuto xD
Syntax: Select all
from messages import HudDestination
EDIT: God damn you Ayuto xD
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)
I have this line :
How can I do to display it with a specific number of seconds?
Thanks
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
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.
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.
The danger in both situations is if another plugin sends a message before the delayed message, it will be cut short.
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.
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 116 guests