[Tool/Web/Other] GetHighestNumber
#1

ive stopped Developing after some time, and Decided to Give it a try again. I made a successful small little script to just get me started on scripting again tho i didn't find anything similar to this except a GetPlayerWitHhighestScore or something similar. Anyway. What it does is basically Go throught all the arguments to find the Highest Number

pawn Код:
stock GetHighestNumber(...)
{
    new args = numargs();
    new highestyet = 0;
    for (new i = 0; i<args; i++)
    {
        if (getarg(i,0) > highestyet) highestyet = getarg(i,0);
    }
    return highestyet;
}
Example of Usage:

Код:
GetHighestNumber(9,9,6,5,1,0,444,5);
Would Compare the highest Yet number, the first six Rounds of the loops would be nine.

This is exactly what it does

Код:
Is 0 (Start Number) > 9. Yes. Start Number = 9.
Is 9 > 9. No. Start Number unchanged
Is 6 > 9. No. Start number unchanged.
And so on
Hope this will be useful to someone.
Reply
#2

Nice function, but you should've placed it here: https://sampforum.blast.hk/showthread.php?tid=38965
Reply
#3

My Bad. Should I Edit this and Give it a link to where i posted it?
Reply
#4

NICE!!!!!!!!!!!!!!!
first time possible msg
Reply
#5

It's nice. And was it my "GetPlayerWithHighestScore" you've seen? :P (-.-)
However, in my function (GetPlayerWithHighestScore) I use 'cellmin' instead of 0. What is the integer is a '-' value?
Here's an example with your function:

pawn Код:
#include <a_samp>

public OnFilterScriptInit()
    return printf("%d", GetHighestNumber(-1, -5, -9, -3));
Which will return '0', because:
Код:
highestyet = 0;
if(-1 > 0) highestyet = -1. FALSE: highestyet stays 0;
if(-5 > 0) highestyet = -5. FALSE: highestyet stays 0;
if(-9 > 0) highestyet = -9. FALSE: highestyet stays 0;
if(-3 > 0) highestyet = -3; FALSE: highestyet stays 0;
return highestyet = 0;
You see what I mean?
I recommend you to change 'highestyet = 0' to 'highestyet = cellmin', so:
pawn Код:
stock GetHighestNumber(...)
{
    new args = numargs();
    new highestyet = cellmin;
    for (new i = 0; i<args; i++)
    {
        if (getarg(i,0) > highestyet) highestyet = getarg(i,0);
    }
    return highestyet;
}
Also, I wouldn't use brackets for one single line after a for statement (optional).
pawn Код:
for (new i = 0; i<args; i++)
    if (getarg(i,0) > highestyet) highestyet = getarg(i,0);
And with the 'new' I would use komma's :P (I'm annoying now aren't I). + why using 'new args = numargs()', you could just use 'numargs' in the loop.
pawn Код:
stock GetHighestNumber(...)
{
    new highestyet = cellmin;
    for(new i = 0; i < numargs(); i++)
        if(getarg(i) > highestyet) highestyet = getarg(i);
    return highestyet;
}
However, sorry for annoying (again :P). But the first thing I've said is quite important for such a function as this.

- Kevin
Reply
#6

You can't really use this a lot in PAWN because it's with constant parameters. You better make one with arrays like I did a while ago: http://forum.sa-mp.com/showthread.ph...6108&post=1535

EDIT:

@Kwarde:
First assign "numargs()" to a variable cause it's not smart to call it each time. That will make your code slower.
Reply
#7

Ah there's the cellmin again
Hmm Ryder`, seems like you've done everything already. :P
Reply
#8

Hmm :/ didnt tested but for beginners it will be helpfull i think
4/10
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)