Page 1 of 1

Comparing Teams (interesting behavior)

Posted: Fri May 16, 2014 10:55 am
by arawra
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?

Posted: Fri May 16, 2014 11:08 am
by Ayuto
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. ;)

Posted: Fri May 16, 2014 1:47 pm
by satoon101
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)