« Previous entry | Next entry » Browse > Snippets

Skip to comments (10) krosens code
Posted by krosen on Mar 05 2009 @ 20:59  :: 1031 unique visits

#include <logging> //for LogMessage function
#include <sourcemod> //required base
#include <sdktools> //required base
#include <tf2_stocks> //for GetPlayerResourceData commands
#include <clients> //for client data
#include <console>
#include <halflife>

#define MOTDPANEL_TYPE_TEXT 0
#define TEAM_RED 2
#define TEAM_BLUE 3
///////////////////////////////////////////////////////////////////////////////
/////////FIRST PART OF SCRIPT IS FOR SOURCEMODS TO SET UP ////////////////////
/////////////////////////////////////////////////////////////////////////////

public Plugin:myinfo =
{
name = \"VoteBalance\",
author = \"KRosen\",
description = \"designed to allow balancing by score\",
version = \"1.0.0.0\",
url = \"http://www.iOGaming.net/\"
}

public OnPluginStart()
{
LoadTranslations(\"common.phrases\")
RegAdminCmd(\"sm_balance\", Command_Balance, ADMFLAG_SLAY)

AutoExecConfig(true, \"plugin_balance\")
}


///////////////////////////////////////////////////////////////////////////////
/////////SECOND PART OF SCRIPT IS FOR VOTING              ////////////////////
/////////////////////////////////////////////////////////////////////////////












new clientArrayFillCounter //the counter used to fill the initClientArray; so we can keep our place while testing for false clients
new maxServerClients //will be the limit for seeking through all clients; must be run every time
new clientsToSort //number of clients that will need to be sorted according to their score; must be reset to actual value every time
new nullingScore //so we can test all numbers without getting into infinite loop; must be reset every time, and be higher than highest score
new highestClientT //for the highest client test; a buffer to hold the known highest client; must be reset on use
new nextClientT //for highest client test; so we can cycle to the next available client for test; must be reset on use
new lowestClientT //for the lowest client test; a buffer to hold the known lowest client; must be reset on use
new sortingPlaceCounter //the counter used when adding items to the sorting array; must be reset
new sortingTestCounter //the counter used when testing items to add to the sorting array; is reset during loop
new teamRedTotalOld //the original total of points on red
new teamBlueTotalOld //the original total of points on blue
new sortingTeamCounter //the counter used when calculating team scores
new redTeamIsWinning //if red team is winning, this is positive.  
new teamShiftingCounter //counter for shuffling the teams
new teamRedNewTotal //holds the total points of new red team; for calculating additional balancing
new teamBlueNewTotal //holds the total points of new blue team; for calculationg additional balancing
new Float:teamMovingCounter //holds the number on a team, or 1/2 the clientsToMove, minus .5 if there is a bias on a team
new sortingCycleCounter //used for ????????????????
new errorMessageControl = 1
new disableFakeClients = 1


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public Action:Command_Balance(client, args)
{
clientArrayFillCounter = 0 //resets the array counter to prevent not filling array properly
maxServerClients = MaxClients //resets maxServerClients to current value to prevent errors
new initClientArray[MaxClients][3] //2Dimensional Array to hold valid clients and their scores for comparison; 0 is client, 1 is score, 2 is team
new orderedClientArray[MaxClients][3] //2Dimensional Array to hold clients in the order of their score for shuffling; 0 is client, 1 is score, 2 is team
new teamRedNew[MaxClients][3] //array to hold new red team; 0 is client, 1 is score, 2 is team
new teamBlueNew[MaxClients][3] //array to hold new blue team; 0 is client, 1 is score, 2 is team
clientsToSort = 0 //initializes a number we can refer back to when we need to know how many numbers are used in the array
highestClientT = 1 //initializes highest scoring client to 1
nextClientT = 2 //initializes the next client to 2
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 1: maxServerClients Filled to %d\" ,maxServerClients)
}



redTeamIsWinning = (GetTeamScore(TEAM_RED) - GetTeamScore(TEAM_BLUE))
//set up variable for first choice test

if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 2a: clientArrayFillCounter set to %d\" ,clientArrayFillCounter)
PrintToChatAll(\"Part 2b: redTeamIsWinning calculated to %d\" ,redTeamIsWinning)
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//adds all connected real clients and score to array; so we have a list to order then shuffle
for(new initClientLoopCounter = 1; initClientLoopCounter <= maxServerClients; initClientLoopCounter++)
{
if(IsClientInGame(initClientLoopCounter) == 1)
{
initClientArray[clientArrayFillCounter][0] = initClientLoopCounter
initClientArray[clientArrayFillCounter][1] = TF2_GetPlayerResourceData(initClientLoopCounter, TFResource_Score)
initClientArray[clientArrayFillCounter][2] = GetClientTeam(initClientLoopCounter)
clientArrayFillCounter = clientArrayFillCounter+1
clientsToSort = clientsToSort+1
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 3a: initClientArray filled with all valid clients: added client %d\" ,initClientArray[clientArrayFillCounter--][0])
PrintToChatAll(\"Part 3b: team client was on: team %d\" ,initClientArray[clientArrayFillCounter--][2])
PrintToChatAll(\"Part 3c: clientArrayFillCounter is: %d\" ,clientArrayFillCounter)
}
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 4a: clientsToSort filled; clients %d\" ,clientsToSort)
PrintToChatAll(\"Part 4b: highestClientT filled; client %d\" ,highestClientT)
PrintToChatAll(\"Part 4c: NextClientT filled; client %d\" ,nextClientT)
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//will go through all clients, and set the highest scoring client to highestClientT; so we have an upper limit

for(new i = 0; i < clientsToSort; i++)
{
if(nextClientT <= clientsToSort)
{
if(initClientArray[highestClientT][1] >= initClientArray[nextClientT][1])
{
nextClientT++
}
else
{
highestClientT = nextClientT
nextClientT++
}
}
}
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 5: highestClientT discovered; client %d\" ,highestClientT)
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

nullingScore = initClientArray[highestClientT][1]++;
//initializes the nulling score for the ranger; so no scores are mistaken for unused when being put in the sorting array
lowestClientT = 0 //initializes lowest scoring client to 1st place
nextClientT = 1 //reinitializes next client to 2nd place for next test

//will go through all clients, and set the lowest scoring client to lowestClientT; so we have a lower limit
for(new i = 0; i < clientsToSort; i++)
{
if(nextClientT <= clientsToSort)
{
if(initClientArray[lowestClientT][1] <= initClientArray[nextClientT][1])
{
nextClientT = nextClientT++
}
else
{
lowestClientT = nextClientT
nextClientT = nextClientT++
}
}
else{}
}
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 6: lowestClientT discovered; client %d\" ,lowestClientT)
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//starts off the sorted array with the known highest scored client, and replaces it w/ the nulling score
orderedClientArray[1][0] = highestClientT
orderedClientArray[1][1] = initClientArray[highestClientT][1]
orderedClientArray[1][2] = initClientArray[highestClientT][2]
initClientArray[highestClientT][1] = nullingScore
//sets to nulling score; should be same, just ++
sortingPlaceCounter = 1 //counter for sorting array; is set to 1 because we already added the highest score
nextClientT = 1 //reinitializes next client for sorting;
sortingTestCounter = 0

if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 7: orderedClientArray is starting to be filled; client %d\" ,orderedClientArray[1][0])
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//tests for all scores if there is a higher score or if next score is invalid; if so, invalid test will break loop, valid will cycle
for(new i = clientsToSort--; i > 0; i--)
{
for(sortingCycleCounter = clientsToSort; sortingCycleCounter > 0; sortingCycleCounter--)
{
if(nextClientT <= clientsToSort)
{
if(initClientArray[sortingTestCounter][1] > initClientArray[nextClientT][1])
{
if(initClientArray[nextClientT][1] != nullingScore)
{
orderedClientArray[sortingPlaceCounter][0] = initClientArray[sortingTestCounter][0]
orderedClientArray[sortingPlaceCounter][1] = initClientArray[sortingTestCounter][1]
orderedClientArray[sortingPlaceCounter][2] = initClientArray[sortingTestCounter][2]
sortingPlaceCounter = sortingPlaceCounter++
initClientArray[sortingTestCounter][1] = nullingScore
sortingCycleCounter = clientsToSort
//to reinitialize the cycle; if there are no more to add this will not fire, ending the cycle
nextClientT = 1
sortingTestCounter = 0
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 8.1: client added to ordereedClientArray; client %d\", orderedClientArray[sortingPlaceCounter--][0])
}
}
else
{
nextClientT = nextClientT++
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 8.2: client already present in ordereedClientArray; client %d\", initClientArray[nextClientT--][0])
}
}
}
else
{
sortingTestCounter = nextClientT
}
}
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


sortingTeamCounter = 0
teamRedTotalOld = 0 //resets to 0 for calculating totals
teamBlueTotalOld = 0 //resets to 0 for calculating totals


//this will calculate total amount of points for all players on each team; can be used for prequiesites
for(new k = clientsToSort; sortingTeamCounter <= k; sortingTeamCounter++)
{
if(orderedClientArray[sortingTeamCounter][2] == TEAM_BLUE)
{
teamRedTotalOld = teamRedTotalOld + orderedClientArray[sortingTeamCounter][1]
}
else
{
teamBlueTotalOld = teamBlueTotalOld + orderedClientArray[sortingTeamCounter][1]
}
}

if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 9a: Old scores tallied; red team has %d\" , teamRedTotalOld)
PrintToChatAll(\"Part 9b: Old scores tallied; blue team has %d\" , teamBlueTotalOld)
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//will calculate new teams for each side, depending on which side was winning
if (redTeamIsWinning >= 0)
{
for (teamShiftingCounter = clientsToSort; teamShiftingCounter >= 1; teamShiftingCounter--)
{
teamBlueNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamBlueNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamBlueNewTotal = teamBlueNewTotal + orderedClientArray[teamShiftingCounter][1]
teamShiftingCounter = teamShiftingCounter--
teamRedNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamRedNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamRedNewTotal = teamRedNewTotal + orderedClientArray[teamShiftingCounter][1]
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 10.1: client added to blue; client %d\" ,teamBlueNew[teamShiftingCounter++][0],\" client added to red; client %d\" ,teamRedNew[teamShiftingCounter][0])
}
}
if (teamShiftingCounter == 0) //if odd number of players, will add one more to blue
{
teamBlueNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamBlueNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamBlueNewTotal = teamBlueNewTotal + orderedClientArray[teamShiftingCounter][1]
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 10.2: One more client added to blue; client %d\" , teamBlueNew[teamShiftingCounter][0])
}
}
}
else
{
for (teamShiftingCounter = clientsToSort; teamShiftingCounter >= 1; teamShiftingCounter--)
{
teamRedNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamRedNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamRedNewTotal = teamRedNewTotal + orderedClientArray[teamShiftingCounter][1]
teamShiftingCounter = teamShiftingCounter--
teamBlueNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamBlueNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamBlueNewTotal = teamBlueNewTotal + orderedClientArray[teamShiftingCounter][1]
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 10.2: One more client added to red; client %d\" , teamRedNew[teamShiftingCounter][0])
}
}
if (teamShiftingCounter == 0) //if odd number of players, will add one more to red
{
teamRedNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamRedNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamRedNewTotal = teamRedNewTotal + orderedClientArray[teamShiftingCounter][1]
if(errorMessageControl == 1) //Debugging
{
PrintToChatAll(\"Part 10.2: One more client added to red; client %d\" , teamRedNew[teamShiftingCounter][0])
}
}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//will force players to go to each side
if (redTeamIsWinning > 0)
{
teamMovingCounter = (clientsToSort--/2)
new ClientToMove = teamBlueNew[teamMovingCounter++][0]
ChangeClientTeam(ClientToMove, TEAM_BLUE)
for (teamShiftingCounter = teamMovingCounter; teamShiftingCounter >= 0; teamShiftingCounter--)
{
ChangeClientTeam(teamBlueNew[teamShiftingCounter][0], TEAM_BLUE)
ChangeClientTeam(teamRedNew[teamShiftingCounter][0], TEAM_RED)
teamShiftingCounter = teamShiftingCounter--
}
}
else if(redTeamIsWinning < 0)
{
teamMovingCounter = (clientsToSort--/2)
ChangeClientTeam(teamRedNew[teamMovingCounter++][0], TEAM_RED)
for (teamShiftingCounter = teamMovingCounter; teamShiftingCounter >= 0; teamShiftingCounter--)
{
ChangeClientTeam(teamBlueNew[teamShiftingCounter][0], TEAM_BLUE)
ChangeClientTeam(teamRedNew[teamShiftingCounter][0], TEAM_RED)
teamShiftingCounter = teamShiftingCounter--
}
}
else if(redTeamIsWinning == 0)
{
teamMovingCounter = (clientsToSort)
for (teamShiftingCounter = teamMovingCounter; teamShiftingCounter >= 0; teamShiftingCounter--)
{
ChangeClientTeam(teamBlueNew[teamShiftingCounter][0], TEAM_BLUE)
ChangeClientTeam(teamRedNew[teamShiftingCounter][0], TEAM_RED)
teamShiftingCounter = teamShiftingCounter--
}
}


//will calculate new totals to make sure it is balanced
/* if (teamShiftingCounter == 0)
{
teamBlueNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamBlueNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamBlueNewTotal = teamBlueNewTotal + orderedClientArray[teamShiftingCounter][1]
}
else
{
for (teamShiftingCounter = clientsToSort; teamShiftingCounter >= 1; teamShiftingCounter--)
{
teamRedNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamRedNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamRedNewTotal = teamRedNewTotal + orderedClientArray[teamShiftingCounter][1]
teamShiftingCounter = teamShiftingCounter--
teamBlueNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamBlueNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamBlueNewTotal = teamBlueNewTotal + orderedClientArray[teamShiftingCounter][1]
}
if (teamShiftingCounter == 0)
{
teamRedNew[teamShiftingCounter][0] = orderedClientArray[teamShiftingCounter][0]
teamRedNew[teamShiftingCounter][1] = orderedClientArray[teamShiftingCounter][1]
teamRedNewTotal = teamRedNewTotal + orderedClientArray[teamShiftingCounter][1]
}
}
*/
}

10 comments posted so far
Add your own »

1. On Apr 14 2009 @ 13:36 guest wrote:

Find information about tiffany ,gucci ,chanel and other jewelry online shopping at online shopping ,
jewelry,craft,antique,daily news online collection at Online Collector ,Tiffany Jewelry including Tiffany Necklaces,Tiffany Rings, and tiffany bracelets…
Guide To Buy Tiffany Product ,   fashion jewelry provide,Tiffany,Oxette,Swarovski,CHANEL Jewelry Information
Find the discount gucci shoes



Louis Vuitton is luxury gifts, French fashion, the replica Louis Vuitton Handbag is woman best friend.Monogram Groom.
Offers Discount Louis Vuitton handbags and Louis Vuitton bags and all other designer handbags,free global fast shipping,low price and top quality.Monogram Jokes,Monogram Suede cheap Louis Vuitton
Louis Vuitton.

Looking For Gucci Shoes ? Gucci Store provide gucci Mens shoes,gucci Womens shoes
Wonderful Gucci shoes sale Gucci men's shoes and Gucci women's shoes at discount Gucci Shoes prices.
cheap gucci Shoes
Gucci Shoes and gucci clothing Spring - Summer 2009, Prada Shoes and prada clothing from the Latest Collection 2009 and Dolce Gabbana Clothing 2009
Gucci Loafers
Gucci Sneakers

Louis Vuitton Handbags
UGGs
Louis Vuitton Handbags
Gucci Shoes
Louis Vuitton
UGG Boots
Louis Vuitton Handbags
gucci shoes
Monogram Groom
Discount Louis Vuitton
UGG Boots

4. On Apr 23 2009 @ 07:23 hua224 wrote:

Do you wantmassage shanghai?
Do you suffer fromvitiligo?
We will offer youreplica watches.

5. On Apr 28 2009 @ 11:01 guest wrote:

Yes,As a pursuer for the most stylish ugg boots sale, you have no excuse anymore if you don't have a pair of UGG Classic Cardy . Through our site you can purchase high quality UGG Classic Crochet  in low price, many of which are hand made by craftspeople. We offer a wide range of UGG Boots in different color and styles. Believe us, we have the best UGG Classic Mini you want, and we are sure that you will become an fan of
UGG Classic Short . Browse the website, we are sure you will find UGG Classic Tall to tempt you!

6. On May 31 2009 @ 03:03 hua224 wrote:

Do you want to buyjordan shoesand
louis vuitton?
We will offer youcheap jordanand
ugg bootsand
Nfl jersey.

8. On Jul 14 2009 @ 04:04 guest wrote:

buy wow gold
my wow power leveling
buy wow gold
good wow power leveling
BUY wow gold
my wow power leveling
CHEAP rs gold
cheap wow power leveling
CHEAPEST lotro gold
MY aion gold
buy wow gold
cheap wow gold
CHEAPEST wow gold

10. On Jan 05 2010 @ 15:06 uggbaileybutton wrote:

bailey button uggs

-ugg boots cheap

ugg boots uk

ugg classic

Add a new comment

Name:
Password: (leave empty for anonymous comment)
 
View formatting tags Comment: