Comparing Teams (interesting behavior)

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Comparing Teams (interesting behavior)

Postby arawra » Fri May 16, 2014 10:55 am

I am was testing this code (for another thing) and when I am comparing teams, it seems to think the victim and player are on the same team.

Syntax: Select all

@SayCommand('!slay')    
def slay(player, teamonly, CCommand):
myPlayer = PlayerEntity(userid_from_playerinfo(player))
for players in PlayerGenerator():
victim = PlayerEntity(index_from_playerinfo(players))
teamA = victim.team
teamB = myPlayer.team
msg('Team of Victim: %s \n Team of Slayer: %s'%(teamA,teamB))
if teamA != teamB:
msg('Damaging %s'%(victim.name))
myPlayer.damage(index_from_playerinfo(players), 100, DamageTypes.BULLET, hitgroup=2)


Console Output

Code: Select all

[D&D] Team of Victim: 2  Team of Slayer: 3
[D&D] Damaging Arawra
[D&D] Team of Victim: 3  Team of Slayer: 3
[D&D] Team of Victim: 3  Team of Slayer: 3
[D&D] Team of Victim: 2  Team of Slayer: 3
[D&D] Damaging Wyatt
[D&D] Team of Victim: 3  Team of Slayer: 3
[D&D] Team of Victim: 2  Team of Slayer: 3
[D&D] Damaging Tim
[D&D] Team of Victim: 3  Team of Slayer: 3
[D&D] Team of Victim: 2  Team of Slayer: 3
[D&D] Damaging Tom
[D&D] Team of Victim: 2  Team of Slayer: 3
[D&D] Damaging Paul
[D&D] Team of Victim: 3  Team of Slayer: 3


All these players (including myself) were on the same team. I'm assuming the iteration is moving too quickly to pause and calculate accurate results per player?
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri May 16, 2014 11:08 am

Check your third line. You need to pass an index to the constructor of PlayerEntity.

A side note: The name "players" for a single player is really missleading. ;)
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri May 16, 2014 1:47 pm

Also, there is no need to directly use PlayerGenerator unless you want each and every player's PlayerInfo instance specifically. You should rather use filters.players.PlayerIter:

Syntax: Select all

from commands.say import SayCommand
from entities.constants import DamageTypes
from filters.players import PlayerIter
from players.entity import PlayerEntity
from players.helpers import index_from_playerinfo

slay_teams = {
2: 'ct'
3: 't'
}


@SayCommand('!slay')
def slay(playerinfo, teamonly, command):
player = PlayerEntity(index_from_playerinfo(playerinfo))

# Is the player on a team?
if not player.team in slay_teams:
return

# Loop through the index of each player on the opposing team
# Can also leave out the return_types as 'index' is the default
for index in PlayerIter(slay_teams[player.team], return_types='index'):

player.damage(index, 100, DamageTypes.BULLET, hitgroup=2)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 64 guests