AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Find lowest number.. (https://forums.alliedmods.net/showthread.php?t=12651)

XunTric 04-20-2005 11:54

Find lowest number..
 
I need to know how to find the lowest number...

Lets say I have 1,2,3,4 and 5.
How do I let the plugin find that 1 is the lowest number there?

In my case, I got a variable that holds your points.
How do I let the plugin find who gots the lowest number on that variable?

Like if I have:
Points = 10
And somebody else have:
Points = 20

How do I let the plugin find out who that got the lowest number on the Points variable?

Thanks...

Twilight Suzuka 04-20-2005 13:08

Code:
 main ( val1, val2 )

slurpycof 04-20-2005 13:10

If you want to check everyone, you can modify this code that I use in my frequent fragger program

Code:
 adm_check_slots(){     new maxslots = get_maxplayers()     new kickme = 0, playtime, unlimited = 0x7fffffff, adm_check_time     for(new i = 1; i <= maxslots; ++i){         if (!is_user_connected(i) && !is_user_connecting(i)) continue         if (get_user_flags(i) & ADMIN_RESERVATION) continue         playtime = get_user_time(i)         adm_check_time = (playtime + connecttime[i])         if(unlimited > adm_check_time){             unlimited = adm_check_time             kickme = i         }     }     return kickme }

XunTric 04-20-2005 14:35

Quote:

Originally Posted by Twilight Suzuka
Code:
 main ( val1, val2 )

I didnt get that... :P

Is val1 and val2 just examples or...?

so can i have like:
main(20,50,60)

So will it return 20, since its the lowest number?

But I want to check a variable that holds a number, and I want to check all players in the server.

In my plugin, all people got a variable called PlayerPoints, that holds a number.
How do I make it check all players, and return who that got lowest number on my PlayerPoints variable?

Will it be like this?

(I want to kick the guy with lowest playerpoints..)

Code:
new LowestPoints[33] = main(PlayerPoints[id]) server_cmd("kick %s", LowestPoints[id])

PM 04-20-2005 14:44

You could try something like:

Code:
GetLowestValID(begin, end, arr[]) {    new ilow = begin;    new vlow = arr[begin];    for (new i = begin; i <= end; ++i)    {       if (arr[i] < vlow)       {          vlow = arr[i];          ilow = i;       }    }    return ilow; }

Then, you could use:
Code:
new i = GetLowestValID(1 /* 1 is the first index to test */, 32 /* 32 will be the last index that is checked */, array);

(untested)

XunTric 04-20-2005 14:50

Umm...
That kind of code is the stuff I dont know much of yet.
(Looping, array and all that stuff...)

Could you write me an example that will check who got the lowest number on my "PlayerPoints[id]" variable?
So I dont have edit it :P

From
Copy and paste - fan :P

PM 04-20-2005 15:26

Copy & paste the function
Code:
GetLowestValID(begin, end, arr[]) {    new ilow = begin;    new vlow = arr[begin];    for (new i = begin; i <= end; ++i)    {       if (arr[i] < vlow)       {          vlow = arr[i];          ilow = i;       }    }    return ilow; }

In your code, use:
Code:
new no_idea_what_your_variable_name_should_be_but_this_long_name_might_crash_the_compiler_mwahahahah = GetLowestValID(1, 32, PlayerPoints);
And hope that it'll work.

XunTric 04-20-2005 15:50

PM: Check your PM :P

v3x 04-20-2005 16:33

It's not hard to understand at all.. :|


All times are GMT -4. The time now is 09:51.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.