Get varialbe max value - 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: Get varialbe max value (
/showthread.php?tid=505464)
Get varialbe max value -
audriuxxx - 08.04.2014
Hi how to know which variable value is biggest for ex:
Код:
new VARIABLESNEW[ 6 ];
VARIABLESNEW[ 0 ] = 10;
VARIABLESNEW[ 1 ] = 5;
VARIABLESNEW[ 2 ] = 7;
VARIABLESNEW[ 3 ] = 3;
VARIABLESNEW[ 4 ] = 15;
VARIABLESNEW[ 5 ] = 2;
Of course varialbes value will be different. But now looking to this example biggest variable is 4
VARIABLESNEW[ 4 ]
But now, how just know which variable is with biggest value?
Re: Get varialbe max value -
Misiur - 08.04.2014
pawn Код:
stock minArray(arr[], len = sizeof arr) {
new
record = cellmin,
index = -1
;
for(new i = 0; i != len; ++i) {
if(arr[i] > record) {
index = i;
record = arr[i];
}
}
return index;
}
//(...)
new
result = minArray({ 5, 6, 8, 14, 14, 10 }, 6)
;
//result == 3
This will return first index with highset value (if indexes 3 and 4 have maximum value, function will return 3). Also, it will return -1 if all your cells contain cellmin value.