Raised This Month: $ Target: $400
 0% 

Need Psuedo Code for Team Scramble


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 09-25-2008 , 12:11   Need Psuedo Code for Team Scramble
Reply With Quote #1

I am always terrible at psuedo code, and for the life of me I cannot think of a decent way of coding a team scrambler function. The only thing I can really come up with is swapping every 2nd player from one team, with every 2nd player from the other team, or something to that affect.

If anyone can possibly throw me some pseudo code on scrambling teams that would be awesome. (Just to save you posting time, its not for TF2 so mp_scrambleteams isn't an option).
__________________
CrimsonGT is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 09-25-2008 , 13:07   Re: Need Psuedo Code for Team Scramble
Reply With Quote #2

Store every player into an array, shuffle the array, and then put one person on team a, the next on b, the next on a, etc until you hit the end of the array.
bl4nk is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 09-25-2008 , 13:45   Re: Need Psuedo Code for Team Scramble
Reply With Quote #3

Thanks bl4nk. I have rarely had to use arrays for my plugins, so I didn't know you could shuffle them.

For those needing to do this in the future, you can use SortStrings() with a sorting order of Sort_Random.
__________________
CrimsonGT is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 09-26-2008 , 04:48   Re: Need Psuedo Code for Team Scramble
Reply With Quote #4

Would this work? I don't have anywhere to test it until tommorow

PHP Code:
public RandomizeTeams()
{
new 
Players[MAXPLAYERS 1];
new 
clientcount GetClientCount();
new 
max_clients GetMaxClients();
new 
StartTeamID 2;
for (new 
i=1<= max_clientsi++)
{
if (
IsClientConnected(i) && IsClientInGame(i))
{
Players[i] = GetClientUserId(i);
}
else
{
continue;
}
}
//Randomize the Players in the Array
SortIntegers(Playerssizeof(Players), Sort_Random);
for (new 
i=1i<=clientcounti++)
{
if(
StartTeamID == 2)
{
ChangeClientTeam(iTEAM_BLUE);
StartTeamID 3;
}
else
{
ChangeClientTeam(iTEAM_RED);
StartTeamID 2;
}
}

__________________
CrimsonGT is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 09-26-2008 , 08:42   Re: Need Psuedo Code for Team Scramble
Reply With Quote #5

Well, no... This is how I'd do it:

Code:
RandomizeTeams() {     decl players[MAXPLAYERS], i     new max_clients = GetMaxClients()     new count, bool:team     for(i = 1; i <= max_clients; i++) {         if(IsClientInGame(i)) {             players[count++] = i         }     }     SortIntegers(players,count,Sort_Random)     for(i = 0; i < count; i++) {         ChangeClientTeam(players[i],team ? TEAM_RED : TEAM_BLUE)         team = !team     } }
__________________
plop
p3tsin is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 09-26-2008 , 09:58   Re: Need Psuedo Code for Team Scramble
Reply With Quote #6

Thanks mate, helped much!
+Karma
__________________
CrimsonGT is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 09-26-2008 , 10:09   Re: Need Psuedo Code for Team Scramble
Reply With Quote #7

Just out of curiosity, doesnt decl players[MAXPLAYERS] need to be MAXPLAYERS+1?
__________________
CrimsonGT is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 09-26-2008 , 12:16   Re: Need Psuedo Code for Team Scramble
Reply With Quote #8

Nope. Only indexes from 0 to 63 will be used.
__________________
plop
p3tsin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode