[ANY]How can I loop through active players in turn?
Hi!
I'm trying to loop through active players in turn in order to determine whos turn it is next, but I'm having a bit of a logic block. I could be trying to do something really stupid here, can anyone help me out? Code:
int nextplayer = 1; |
Re: [ANY]How can I loop through active players in turn?
Hmm, am I forgetting to break out of the loop? I shut down my server already so I cant test until tomorrow.
Code:
if(i > 0 && i <= MaxClients && IsClientInGame(i) && GetClientTeam(i) == 2 && IsPlayerAlive(i) && !IsFakeClient(i) && nextplayerset) |
Re: [ANY]How can I loop through active players in turn?
May I know what are you exactly trying to do?
Can you provide me with more details I maybe able to help, give the whole picture if possible |
Re: [ANY]How can I loop through active players in turn?
Sorry for the poor explanation! I am trying to target players by client in order to give a special weapon for X seconds.
Alice, Bob, Charlie and Dave are playing in a server on team 2 against bots. I want a function which can help me find out whos turn it is to have the weapon. In no particular order, I want to give everybody the weapon. If they are dead, ignore them and give it to the next player. Once everybody has had it (except anyone who was dead when it was their turn), give it back to the player who had it first, then continue. If a new player connects, include them in the scheme. I want to be able to run the function whenever I want. Maybe I want charlie to have the weapon for two turns, so the nextplayer variable should be global. Thankyou! EDIT: Okay I think I got it. Well, it works in some early testing but if anyone knows how to improve the code that would be useful! Thanks Code:
int nextclient; |
Re: [ANY]How can I loop through active players in turn?
Here is my testings.
This one you can ignore, but I wanted to show anyway. This look next index from previous one, loop back to start from 1, stop on old index. Similiar as yours.
not important
In this version, it can use either client index or client UserID - This collect matching targets into array and sort array by ascending method. (0,1,2,3,4,5 ...) But when using this one same function, use only same type, either client index or userid. Not both or you can not get right result. To able to use both, you need dublicate function and rename it. For looking client index, from team 2 "terrorists": int player = GetNextHumanPlayer(2); PHP Code:
Here is demonstration with bots, using UserID without team index: player = GetNextHumanPlayer(.UseUserID = true); Code:
# userid name uniqueid connected ping loss state adr look, edit, test it. |
Re: [ANY]How can I loop through active players in turn?
Thanks for sharing this Bacardi! :twisted:
|
All times are GMT -4. The time now is 02:44. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.