PDA

View Full Version : Getting a random player from team?



voron00
23rd June 2015, 16:45
Hello, i need to get random player from team (axis or allies), what i tried - didn't work, but im not much of a dev. Anyone can help, please?

Mitch
23rd June 2015, 16:54
Hello, i need to get random player from team (axis or allies), what i tried - didn't work, but im not much of a dev. Anyone can help, please?

Can you post the code that you used? And for which cod version is it?

voron00
23rd June 2015, 17:00
Can you post the code that you used? And for which cod version is it?

cod2, well i tried many things but something like that, but that not work:



level.alliesteam = [];
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if((isdefined(players.pers["team"])) && (players.pers["team"] == "allies") && (players.sessionstate == "playing"))
level.alliesteam[level.level.alliesteam.size] = players;
}
random = level.alliesteam[randomint(level.alliesteam.size)];

php
23rd June 2015, 17:58
try



level.alliesteam = [];
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
if(isdefined(players[i].pers["team"]) && players[i].pers["team"] == "allies" && players[i].sessionstate == "playing")
level.alliesteam[level.alliesteam.size] = players[i];
random = level.alliesteam[randomint(level.alliesteam.size)];


I edited the players to players[i]

voron00
23rd June 2015, 18:17
try



level.alliesteam = [];
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
if(isdefined(players[i].pers["team"]) && players[i].pers["team"] == "allies" && players[i].sessionstate == "playing")
level.alliesteam[level.alliesteam.size] = players[i];
random = level.alliesteam[randomint(level.alliesteam.size)];


I edited the players to players[i]

Works, thanks, at least i was close to the solution:P

IzNoGoD
23rd June 2015, 22:19
if you would have been running your mod in DEVELOPER mode it would have CRASHED and given you a clue where to look for fixes.

Please ALWAYS use DEVELOPER mode to debug shit.