Getting largest value in an array. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Getting largest value in an array. (
/showthread.php?tid=573557)
Getting largest value in an array. -
Dokins - 08.05.2015
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!
AW: Getting largest value in an array. -
Mencent - 08.05.2015
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.
Re: Getting largest value in an array. -
Konstantinos - 08.05.2015
PHP код:
new value = -1;
for (new i; i != sizeof (some_array); ++i)
{
if (some_array[i] > value) value = some_array[i];
}
if (value != -1) printf("%i is the highest value of some_array", value);
Re: Getting largest value in an array. -
Dokins - 08.05.2015
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.
Re: Getting largest value in an array. -
Konstantinos - 08.05.2015
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);
Re: Getting largest value in an array. -
Dokins - 08.05.2015
Ahhh!
Thank you very much, I truly appreciate that.
REP +.
Re: Getting largest value in an array. -
Dokins - 08.05.2015
Ahhh!
Thank you very much, I truly appreciate that.
REP +.