SA-MP Forums Archive
Return max, and repeating from string 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: Return max, and repeating from string array. (/showthread.php?tid=519718)



Return max, and repeating from string array. - [WSF]ThA_Devil - 15.06.2014

I've tried this:
somewhere:
test[3];
test[0] = 12;
test[1] = 11;
test[2] = 44;
new value = ReturnMax(test);

Код:
stock ReturnMax(string[]) {
	new maxi = -1,maxcount,value[2];
	for(new i = 0; i < strlen(string); i++) {
	    if(string[i] > maxi) {
	        maxi = string[i];
            maxcount = 1;
	    } else if(string[i] == maxi) maxcount++;
	}
	value[0] = maxcount;
	value[1] = maxi;
	return value;
}
but that doesn't seem to help.


Re: Return max, and repeating from string array. - Konstantinos - 15.06.2014

pawn Код:
ReturnMax(&count, const string[], len)
{
    count = 0;
    new max_val = -1;
   
    for (new i; i != len; ++i)
    {
        if (string[i] > max_val)
        {
            max_val = string[i];
            count = 1;
        }
        else if (string[i] == max_val) ++count;
    }
    return max_val;
}
An example:
pawn Код:
test[0] = 44;
test[1] = 11;
test[2] = 44;

new
    count,
    value = ReturnMax(count, test, sizeof (test));
   
printf("%i %i", count, value);
It will print 2 (2 indexes with the highest number) and 44 (the highest number).


Re: Return max, and repeating from string array. - [WSF]ThA_Devil - 15.06.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
ReturnMax(&count, const string[], len)
{
    count = 0;
    new max_val = -1;
   
    for (new i; i != len; ++i)
    {
        if (string[i] > max_val)
        {
            max_val = string[i];
            count = 1;
        }
        else if (string[i] == max_val) ++count;
    }
    return max_val;
}
An example:
pawn Код:
test[0] = 44;
test[1] = 11;
test[2] = 44;

new
    count,
    value = ReturnMax(count, test, sizeof (test));
   
printf("%i %i", count, value);
It will print 2 (2 indexes with the highest number) and 44 (the highest number).
haha, Thanks, but at the end this wasn't what I needed.
I needed it to return ID of the highest.
Edited a bit.
Thanks anyways.