Getting largest value in an array.
#1

Could someone provide an example of how to do the above?
I've never really came across this before and I'm probably overthinking, any help would be appreciated.

Thanks a lot!
Reply
#2

Hello!

You want to get the largest value of an array?
PHP код:
new value = array[sizeof(array)]; 
If that isn't the right you are free to ask.
Reply
#3

PHP код:
new value = -1;
for (new 
i!= sizeof (some_array); ++i)
{
    if (
some_array[i] > valuevalue some_array[i];
}
if (
value != -1printf("%i is the highest value of some_array"value); 
Reply
#4

Thanks for the response, I may have made it a little confusing.

Basically I'm trying to determine the most damage to a bodypart and which one in the array..

pawn Код:
new Float: BodyPartDamage[MAX_PLAYERS][10];
The idea is to loop through the 10 slots (body parts) and check the damage in each saved area and find the slot with the highest amount.
Reply
#5

pawn Код:
new Float: dmg_bodypart, index = -1;
for (new i; i != 10; ++i)
{
    if (index == -1)
    {
        index = 0;
        dmg_bodypart = BodyPartDamage[playerid][0];
    }
    else if (index != -1 && BodyPartDamage[playerid][i] > BodyPartDamage[playerid][index])
    {
        index = i;
        dmg_bodypart = BodyPartDamage[playerid][i];
    }
}
if (index != -1) printf("highest damage (%f) on bodypart (%i)", dmg_bodypart, index);
Reply
#6

Ahhh!

Thank you very much, I truly appreciate that.

REP +.
Reply
#7

Ahhh!

Thank you very much, I truly appreciate that.

REP +.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)