Help Get player with highest id

GoodMan

Active member
Joined
Jun 4, 2014
Messages
147
Reaction score
0
Hello ugbase, i request help to learn how to get the online player with highest number ID.

note: i know that "0C8A: samp 1@ = get_max_player_id streamed_only 0" gets the total of connected players and i can use that number to do what i want, BUT it doesn't work in my case, because the server i play on adds it's own npcs and these have ids between players, as example, if there are 100 connected players, the highest id from connected player is something like 188. this number is not precise.
What i try to achieve is the loop once, get highest number, and then rewrite 20@ to that value, i know how to do everything except get highest id number.
Code:
{$CLEO .cs}

0000: NOP
0B34: samp register_client_command "fc" @MAXPLAYER
20@ = 450


WHILE TRUE
    WAIT 0
    IF 20@ <> 0
    THEN
        IF 0AB0: key_pressed 32
        THEN PRINTF "%d" 100 20@
        END
        FOR 0@ = 0 TO 20@ STEP 1
            IF AND
                8B64:  samp is_player 0@ npc
                0B23: samp is_player_connected 0@
            THEN
                0B36: samp 1@ = get_player_nickname 0@
                IF 8C29: $NOT_USED = stristr string1 1@ string2 "npc" // ignore npcs
                THEN
                    IF OR
                        0C14: 1@ "someone"
                    THEN
                        gosub @Rendstuff
                    END
                    // and then another 200 conditions like prevous one.
                END
            END
        END
    END
END

:MAXPLAYER
WAIT 0
0B35: samp 12@ = get_last_command_params
0AD4: 13@ = scan_string 12@ format "%d" 14@
0085: 20@ = 14@ // (int)
PRINTF "%d" 2000 20@
Samp.CmdRet()
 

Hidend

Expert
Joined
Mar 4, 2013
Messages
645
Reaction score
48
It's a mess because i dont use cleo since ages but you get the idea, add the npc check if needed too:

{$CLEO .cs}
0000: NOP
repeat
wait 0
until 0AFA: is_samp_available

while true
wait 0
0AB1: call_scm_func @MAXPLAYER 0 returnedValue 0@
0AF8: samp add_message_to_chat "max player id is %d" color -1 0@
wait 5000
end

:MAXPLAYER
var 0@: Int
for 2@ = 1000 downto 0
if
0B23: samp is_player_connected 2@
then
0@ = 2@
break
end
end

0AB2: ret 1 0@
 

GoodMan

Active member
Joined
Jun 4, 2014
Messages
147
Reaction score
0
THANKS BOSS, IT WORKED PERFECT, I NEVER THOUGHT ABOUT COUNTING BACKWARDS LOL.

I ADDAPTED IT TO MY SCRIPT LIKE THIS


Code:
WHILE TRUE
    WAIT 0
    
    IF 0AB0: key_pressed 32 // SPACEBAR
    THEN
        REPEAT
        WAIT 0
        UNTIL 8AB0: key_pressed 32 // SPACEBAR                 
        0AB1: call_scm_func @MAXPLAYER 0 returnedValue 20@
        0085: 28@ = 20@
        PRINTF "~G~ LOOP = 0 TO %d" 2000 28@
    END
END

:MAXPLAYER
WAIT 0
FOR 16@ = 480 DOWNTO 0
    IF 0B23: samp is_player_connected 16@
    THEN
        0B36: samp 1@ = get_player_nickname 16@
        IF 8C29: $NOT_USED = stristr string1 1@ string2 "_npc_"
        THEN
        0085: 20@ = 16@
        BREAK
        END
    END
END
0AB2: ret 1 20@
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,258
Solutions
6
Reaction score
924
Location
Lithuania
THANKS BOSS, IT WORKED PERFECT, I NEVER THOUGHT ABOUT COUNTING BACKWARDS LOL.

I ADDAPTED IT TO MY SCRIPT LIKE THIS


Code:
WHILE TRUE
    WAIT 0
   
    IF 0AB0: key_pressed 32 // SPACEBAR
    THEN
        REPEAT
        WAIT 0
        UNTIL 8AB0: key_pressed 32 // SPACEBAR                
        0AB1: call_scm_func @MAXPLAYER 0 returnedValue 20@
        0085: 28@ = 20@
        PRINTF "~G~ LOOP = 0 TO %d" 2000 28@
    END
END

:MAXPLAYER
WAIT 0
FOR 16@ = 480 DOWNTO 0
    IF 0B23: samp is_player_connected 16@
    THEN
        0B36: samp 1@ = get_player_nickname 16@
        IF 8C29: $NOT_USED = stristr string1 1@ string2 "_npc_"
        THEN
        0085: 20@ = 16@
        BREAK
        END
    END
END
0AB2: ret 1 20@

PHP:
0C8A: samp 31@ = get_max_player_id streamed_only FALSE
 
Top