ShowDamage

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

ShowDamage

Postby Jerome69 » Mon Oct 05, 2015 9:18 pm

Attachments
Erreur.jpg
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Oct 05, 2015 9:58 pm

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]
Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Tue Oct 06, 2015 11:38 am

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

Postby Ayuto » Tue Oct 06, 2015 11:59 am

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

Postby satoon101 » Wed Oct 07, 2015 2:54 am

Ayuto meant this to be the last line:

Syntax: Select all

SayText2('You hit somebody.').send(index)
Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Wed Oct 07, 2015 7:26 am

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?
Attachments
Erreur.jpg
User avatar
Ayuto
Project Leader
Posts: 2208
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed Oct 07, 2015 8:40 am

You have to import HudDestination.

Syntax: Select all

from messages import HudDestination
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Postby Predz » Wed Oct 07, 2015 8:41 am

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
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Wed Oct 07, 2015 8:53 am

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 ^^)
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 24, 2015 7:59 am

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

Postby Ayuto » Sat Oct 24, 2015 8:58 am

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)
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 24, 2015 10:05 am

Attachments
Error.jpg
User avatar
Ayuto
Project Leader
Posts: 2208
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 24, 2015 11:38 am

Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 24, 2015 1:57 pm

Yeah, it works fine.

Thanks a lot :D
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Mon Feb 15, 2016 12:02 pm

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

Postby satoon101 » Mon Feb 15, 2016 1:37 pm

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.
Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Tue Feb 16, 2016 2:17 pm

Ok thanks.

I think another plugin send an empty message just after my plugin.

I'll see to change it.
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Feb 17, 2016 9:15 pm

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.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 128 guests