help - How do I do this?
#1

How do I make a loop that checks who is the highest? (The z axis)
Reply
#2

Replace 'ARRAY' in the code below with the array you use. If the values you want to compare are floats, replace 'new HighestValue;' with 'new Float:HighestValue;'.

pawn Код:
new HighestID = -1;
new HighestValue;
for(new i; i<sizeof(ARRAY); i++)
{
    if(ARRAY[i] > HighestValue)
    {
        HighestID = i;
        HighestValue = ARRAY[i];
    }
}
//now you have the highest id and highest value.
Edit: after reading your post again I now know what you mean.
This should do it:

pawn Код:
new HighestID = -1;
new Float:HighestValue, Float:X, Float:Y, Float:Z;
for(new i; i<MAX_PLAYERS; i++)
{
    GetPlayerPos(i, X, Y, Z);
    if(Z > HighestValue)
    {
        HighestID = i;
        HighestValue = Z;
    }
}
// Player 'HighestID' is the highest at "Z = HighestValue"
//Note: This code does not deal with a tie... if 2 players are at exactly the same height, the player with the lowest playerID will 'win'.
Reply
#3

Quote:
Originally Posted by Schneider
Посмотреть сообщение
Replace 'ARRAY' in the code below with the array you use. If the values you want to compare are floats, replace 'new HighestValue;' with 'new Float:HighestValue;'.

pawn Код:
new HighestID = -1;
new HighestValue;
for(new i; i<sizeof(ARRAY); i++)
{
    if(ARRAY[i] > HighestValue)
    {
        HighestID = i;
        HighestValue = ARRAY[i];
    }
}
//now you have the highest id and highest value.
Edit: after reading your post again I now know what you mean.
This should do it:

pawn Код:
new HighestID = -1;
new Float:HighestValue, Float:X, Float:Y, Float:Z;
for(new i; i<MAX_PLAYERS; i++)
{
    GetPlayerPos(i, X, Y, Z);
    if(Z > HighestValue)
    {
        HighestID = i;
        HighestValue = Z;
    }
}
// Player 'HighestID' is the highest at "Z = HighestValue"
//Note: This code does not deal with a tie... if 2 players are at exactly the same height, the player with the lowest playerID will 'win'.
thank you,

hummm,

What is wrong here? ,
It interrupts me the rest of the code..

(It should store all the weapons of the players)

PHP код:
for(new SlotSlot 12Slot++)
                    {
                        
GetPlayerWeaponData(iCountSlotWeapons_Storage[iCount][Slot][0], Weapons_Storage[iCount][Slot][1]);
                    } 
Continue code if necessary-
PHP код:
                   for(new iCountiCount MAX_PLAYERSiCount++) if(IsPlayerConnected(iCount) && In_Pyramid[iCount])
                   {
                    
SetPlayerHealth(iCount100.0);
                    
SetPlayerInArea(iCount2270.75152384.83721217.57141351.884460.0000);
                    
SetPlayerInterior(iCount0);
                     
SetPlayerVirtualWorld(iCountPYRAMID_WORLD);
            
/*        for(new Slot; Slot < 12; Slot++)
                    {
                        GetPlayerWeaponData(iCount, Slot, Weapons_Storage[iCount][Slot][0], Weapons_Storage[iCount][Slot][1]);
                    }*/
                    
ResetPlayerWeapons(iCount);
                     
GivePlayerWeapon(iCount389999);
                    
TogglePlayerControllable(iCountfalse);
                } 
Reply
#4

I don't see anything wrong with that little piece of code...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)