I made a function similar to get_players(); which as most of you know returns an array of all the players ingame. so this function does the same thing but it ONLY returns players that are alive
anyways heres the function: copy and paste this in whatever gsc file you use it in
Code Snippet
Plaintext
get_players_alive() { players = get_players(); // We Get An Array With All Players Currently Ingame (Alive or Dead) playersAlive = []; // A New Array To Hold Players Which Are Alive
for(i = 0; i < players.size; i++) { // Running Through The Players Array if( isPlayer(players[i]) && isAlive(players[i]) ) { // Checking If A Single Player Is A Player & is Alive playersAlive[playersAlive.size] = players[i]; // If The Above Evaluates To True We'll Add This Player To The playersAlive Array } }
return playersAlive; // Return The playersAlive Array }
then just use it like you would get_players();
Code Snippet
Plaintext
playersAlive = get_players_alive();
for(i = 0; i < playersAlive.size; i++) { IPrintLn(playersAlive[i].playername + " is currently alive!"); }
Last Edit: August 26, 2015, 07:15:55 pm by Alerion
playersAlive[i] = players[i]; // If The Above Evaluates To True We'll Add This Player To The playersAlive
this is a nice function, i may even use it myself but i would change the above line to something like this, that way you dont define values in the array out of order
Some Code
Code Snippet
Plaintext
playersAlive[playersAlive.size] = players[i]; // If The Above Evaluates To True We'll Add This Player To The playersAlive
lets say there are 4 players in the game and players 1 and 3 are alive your way would have the array like this
this is a nice function, i may even use it myself but i would change the above line to something like this, that way you dont define values in the array out of order
Some Code
Code Snippet
Plaintext
playersAlive[playersAlive.size] = players[i]; // If The Above Evaluates To True We'll Add This Player To The playersAlive
lets say there are 4 players in the game and players 1 and 3 are alive your way would have the array like this
Hey guys and gals, sorry but it looks like I am unable to update my post without a moderator and since I cant find a way to contact one ill post the update here.
change this line:
Code Snippet
Plaintext
playersAlive[i] = players[i];
to this:
Code Snippet
Plaintext
playersAlive[playersAlive.size] = players[i];
thanks again to WARDOGSK93 for letting me know about this if you want to know why The change was made look at WARDOGSK93's reply, thanks