UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

get_players_alive(); similar to get_players();

broken avatar :(
Created 9 years ago
by louisfm16
0 Members and 1 Guest are viewing this topic.
2,492 views
broken avatar :(
×
broken avatar :(
Location: usCali
Date Registered: 11 July 2015
Last active: 8 years ago
Posts
21
Respect
Forum Rank
Legless Crawler
Primary Group
Member
Personal Quote
Live and Learn
×
louisfm16's Groups
louisfm16's Contact & Social LinksPortfolio
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
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(
Code Snippet
Plaintext
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
Code Snippet
Plaintext
playersAlive[0] == Alive
playersAlive[1] == Undefined
playersAlive[2] == Alive
playersAlive[3] == Undefined
where as my way would define the array like so
Code Snippet
Plaintext
playersAlive[0] == Alive
playersAlive[1] == Alive
broken avatar :(
×
broken avatar :(
The King of Zombies
Location: usLouisiana
Date Registered: 24 June 2013
Last active: 4 years ago
Posts
2,148
Respect
Forum Rank
King of the Zombies
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Signature
Donate to me if you enjoy my work. https://www.paypal.me/thezombiekilla6
×
Dust's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Dust's Contact & Social LinksMrZ0mbiesFanaticdust103194MrZ0mbiesFanatic
Good tutorial!
broken avatar :(
×
broken avatar :(
Location: usCali
Date Registered: 11 July 2015
Last active: 8 years ago
Posts
21
Respect
Forum Rank
Legless Crawler
Primary Group
Member
Personal Quote
Live and Learn
×
louisfm16's Groups
louisfm16's Contact & Social LinksPortfolio
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
Code Snippet
Plaintext
playersAlive[0] == Alive
playersAlive[1] == Undefined
playersAlive[2] == Alive
playersAlive[3] == Undefined
where as my way would define the array like so
Code Snippet
Plaintext
playersAlive[0] == Alive
playersAlive[1] == Alive
oh lol i see what I did wrong ill update the ttutorial, thanks WARDOGSK93
broken avatar :(
×
broken avatar :(
Location: usCali
Date Registered: 11 July 2015
Last active: 8 years ago
Posts
21
Respect
Forum Rank
Legless Crawler
Primary Group
Member
Personal Quote
Live and Learn
×
louisfm16's Groups
louisfm16's Contact & Social LinksPortfolio
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
broken avatar :(
×
broken avatar :(
The Voice in your Eyes
Location: deBavaria
Date Registered: 26 June 2013
Last active: 2 years ago
Posts
830
Respect
Forum Rank
The Decider
Primary Group
Community Mapper
My Groups
More
My Contact & Social Links
More
Personal Quote
Breton boys do what Breton boys do.
×
Alerion's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
I canged it on the OP.
broken avatar :(
×
broken avatar :(
Location: usCali
Date Registered: 11 July 2015
Last active: 8 years ago
Posts
21
Respect
Forum Rank
Legless Crawler
Primary Group
Member
Personal Quote
Live and Learn
×
louisfm16's Groups
louisfm16's Contact & Social LinksPortfolio
I canged it on the OP.

Awesome Thanks Alerion

 
Loading ...