Healing and Hopefully Better Questions

Please post any questions about developing your plugin here. Please use the search function before posting!
paytonpenn
Junior Member
Posts: 10
Joined: Tue Aug 21, 2012 5:52 pm

Healing and Hopefully Better Questions

Postby paytonpenn » Sat Feb 02, 2013 11:05 pm

Is there a way to heal everyone on a specific team?

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

Postby satoon101 » Sat Feb 02, 2013 11:14 pm

You mean loop through all players on a specific team and setting their health to 100? If so:

Syntax: Select all

from filters.players import PlayerIter

# This would be if you are doing this for CTs
# We use 'player' as the return_type to return a PlayerEntity instance
ct_players = PlayerIter(['ct', 'alive'], return_types='player')

# Randomly named function you wish to use to restore every players health on the team
def something():

# Iterate over all players who on alive CTs
for player in ct_players:

# Set the player's health
player.health = 100
Satoon
paytonpenn
Junior Member
Posts: 10
Joined: Tue Aug 21, 2012 5:52 pm

Postby paytonpenn » Sun Feb 03, 2013 12:01 am

Syntax: Select all

File '..\addons\source-python\_libs\filters\iterator.py', line 47, in __iter__ 
yield self.manager._return_types[self._return_types](item)
File '..\addons\source-python\_libs\filters\players.py', line 172, in _return_player
return PlayerEntity.get_instance_from_playerinfo(IPlayerInfo)

AttributeError: type object 'PlayerEntity' has no attribute 'get_instance_from_playerinfo'
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Feb 03, 2013 12:05 am

Update your _libs folder. That error was fixed on Dec 17th.

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

Postby satoon101 » Sun Feb 03, 2013 12:17 am

Sorry, just realized this is an issue with the current download. Unfortunately, until we can fix our Linux build issues, we cannot release a new build. There are many things in the newest _libs that utilize functionality in more recent builds, which makes me hesitant to release the old build with the newest _libs.

Satoon
paytonpenn
Junior Member
Posts: 10
Joined: Tue Aug 21, 2012 5:52 pm

Postby paytonpenn » Sun Feb 03, 2013 2:50 pm

Thanks, I updated, except got some errors during the update. But with the player.health is there a way to get a player's health? Or is there a page you could point me to so I could know all of the player.<options>
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Feb 03, 2013 3:02 pm

Unfortunately, since the site went down, we have not really gotten the Wiki back up, yet. "health" is just an attribute of the PlayerEntity object. You get it by simply calling player.health and not "setting" player.health:

Syntax: Select all

# Get player's current health
health = player.health

# Set player's current health
player.health = 100

# Add to player's current health
player.health += 50
For the time being, you can look through the _data files to see what all is available for specific entity types. Note that since PlayerEntity inherits from BaseEntity, all "entity" properties, functions, offsets, and keyvalues are available for players as well.

Satoon
paytonpenn
Junior Member
Posts: 10
Joined: Tue Aug 21, 2012 5:52 pm

Postby paytonpenn » Sun Feb 03, 2013 3:27 pm

Hmm.. Is there anyway I could heal a specific userid or attacker that doesn't isn't the "player", or how would I go about setting the "player" part for a specific player that triggered the event such as killing a player.
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Feb 03, 2013 3:32 pm

paytonpenn wrote:Hmm.. Is there anyway I could heal a specific userid or attacker that doesn't isn't the "player", or how would I go about setting the "player" part for a specific player that triggered the event such as killing a player.


retrieve the player entity from userid.

Syntax: Select all

from events import Event

@Event
def player_death(GameEvent):
victim_userid = GameEvent.GetInt('userid')
attack_userid = GameEvent.GetInt('attacker')
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Feb 03, 2013 3:35 pm

I'm not 100% sure what you are asking, but it seems to me you want to set the health of the "attacker" on player_death. If that is right:

Syntax: Select all

from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid

@Event
def player_death(GameEvent):
# Get the userid of the attacker
attacker = GameEvent.GetInt('attacker')

# Get the index of the attacker
index = index_from_userid(attacker)

# Get the attacker's PlayerEntity instance
player = PlayerEntity(index)

# Set the attacker's health
player.health = 100
Of course, you might also want to verify that the kill wasn't a suicide or team kill prior to setting the health:

Syntax: Select all

from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from players.helpers import playerinfo_from_userid

@Event
def player_death(GameEvent):
# Get the userid of the attacker
attacker = GameEvent.GetInt('attacker')

# Get the userid of the victim
victim = GameEvent.GetInt('userid')

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

# Do not increase health
return

# Get the index of the attacker
index = index_from_userid(attacker)

# Get the attacker's PlayerEntity instance
player = PlayerEntity(index)

# Get the victim's IPlayerInfo instance
vplayer = playerinfo_from_userid(victim)

# Was this a team kill?
if player.team == vplayer.GetTeamIndex():

# Do not increase health
return

# Set the attacker's health
player.health = 100
paytonpenn
Junior Member
Posts: 10
Joined: Tue Aug 21, 2012 5:52 pm

Postby paytonpenn » Sun Feb 03, 2013 3:40 pm

Thanks satoon, works perfectly. You will soon see what I was trying to do.
paytonpenn
Junior Member
Posts: 10
Joined: Tue Aug 21, 2012 5:52 pm

Postby paytonpenn » Mon Feb 04, 2013 1:09 am

Getting a team's player count? I feel there is an easier way than what I was trying to do.

http://www.eventscripts.com/pages/Es_getlivingplayercount
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Feb 04, 2013 2:39 am

Hey paytonpenn,

Taking the example Satoon gave you:

Syntax: Select all

ct_count = len(list(ct_players))

L'In20Cible
paytonpenn
Junior Member
Posts: 10
Joined: Tue Aug 21, 2012 5:52 pm

Postby paytonpenn » Mon Feb 04, 2013 3:19 am

Thanks, anyway to round numbers because I keep getting this error and I am quite sure it is because I am trying to set someone's health at something with a decimal.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Feb 04, 2013 3:38 am

Hey paytonpenn,

It would be easier to help you solving that problem with your code.

Thanks,

L'In20Cible
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Mon Feb 04, 2013 4:57 am

what error?
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Feb 04, 2013 5:10 am

As they said, it would be much easier to help you if we could see the code/error instead of just guessing at what your issue could possibly be.

The only thing I could think it would be is that the health property uses an integer:

Syntax: Select all

# From ../_libs/_data/properties/player/csgo.ini

[health]
prop = "CBasePlayer.m_iHealth"
type = "Int"
So, you "must" pass an integer when setting the value.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Mon Feb 04, 2013 12:42 pm

satoon101 wrote:As they said, it would be much easier to help you if we could see the code/error instead of just guessing at what your issue could possibly be.

The only thing I could think it would be is that the health property uses an integer:

Syntax: Select all

# From ../_libs/_data/properties/player/csgo.ini

[health]
prop = "CBasePlayer.m_iHealth"
type = "Int"
So, you "must" pass an integer when setting the value.

Satoon


As satoon101 pointed out check your math formel it might return a decimal instead of int
-Tuck
paytonpenn
Junior Member
Posts: 10
Joined: Tue Aug 21, 2012 5:52 pm

Postby paytonpenn » Mon Feb 04, 2013 3:13 pm

I would've posted the error earlier but there isn't easy copying and pasting.
Image

Here's a snip of the code that involves that, pretty sure its because the output gives a decimal and not a whole integer, so.. how does one go about rounding or an alternative method.

Syntax: Select all

@Event
def bomb_planted(GameEvent):
if sesharing == 1:
sesearch = PlayerIter(['t', 'alive'], return_types='player')
t_count = len(list(sesearch))
for player in sesearch:
sehealthbp2 = sehealthbp / t_count
health = player.health
sehealthalt = semaxhealth - sehealthbp2

The error comes in when I add sehealthbp2 to the player's current health or attempt force it.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Feb 04, 2013 3:29 pm

Yeah, it is definitely due to you passing a float value instead of an integer. Notice in the error, this section:

Code: Select all

Boost.Python.ArgumentError: Python argument types in
    edict_t.SetPropInt(edict_t, str, float)
did not match C++ signature:
    SetPropInt(struct edict_t *, char const * szFullPath, int propValue)
So, the first arguments match, as it wants an edict_t instance, and the second arguments match, as it wants a string (C++ char equals Python str). The third argument, however, should be an integer, but you pass it a float.

You can get an integer one of two ways. You can typecast the result you wish to pass as an integer:

Syntax: Select all

player.health = int(sehealthbp2)
or if you wish to round the value, you would use the built-in round function:

Syntax: Select all

player.health = round(sehealthbp2)

Satoon

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 30 guests