The basic idea is that the script acquires the Health of all players ingame and their corresponding TIDs, puts them into 2 arrays and sorts them from lowest to highest health. Since I had trouble getting the health via For-Loops into the arrays, I simply request the health already while initializing the arrays.
All that is working fine, BUT the sorting process is somewhat broken. The first index of the array does not get sorted, while any following indexes will be sorted as intended.
Example:
Player 1 = 100 Health, Player 2 = 50 Health, Player 3 = 25 Health
So the result SHOULd be: Player 3, Player 2, Player 1
The result however is: Player 1, Player 3, Player 2
Player 2 and Player 3 got sorted properly, while Player 1 remains in it's position.
I know that, because I used HUDMESSAGE to show me the results.
Here's the Script
Code: Select all
Script 2 (void)
{
int counter;
int innercounter;
int itemamount; //dummy variable for swapping
int player; //dummy variable for swapping
int sortitemamount[8] = { CheckActorInventory(1000, "Health"), CheckActorInventory(1001, "Health"), CheckActorInventory(1002, "Health"), CheckActorInventory(1003, "Health"), CheckActorInventory(1004, "Health"), CheckActorInventory(1005, "Health"), CheckActorInventory(1006, "Health"), CheckActorInventory(1007, "Health") } ;
int sortplayer[8] = { 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007 };
For (counter = 0; counter < PlayerCount() - 2; counter++); //Sort the variables, from lowest to highest amount
{
For (innercounter = counter + 1; innercounter < PlayerCount() - 1; innercounter++);
{
If (sortitemamount[counter] > sortitemamount[innercounter])
{
itemamount = sortitemamount[counter];
player = sortplayer[counter];
sortitemamount[counter] = sortitemamount[innercounter];
sortplayer[counter] = sortplayer[innercounter];
sortitemamount[innercounter] = itemamount;
sortplayer[innercounter] = player;
}
}
}
}
PS: I am fully aware that I can use "GetActorProperty(TID, APROP_Health)" but I want to use this script for Armor & Ammo as well later on.