AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get player index from ip argument (https://forums.alliedmods.net/showthread.php?t=221227)

seriousspot 07-19-2013 13:12

Get player index from ip argument
 
PHP Code:

new player_index cmd_target(idip_from_read_argCMDTARGET_ALLOW_SELF CMDTARGET_NO_BOTS


for example player_index should return on players index 1-32

akcaliberg 07-19-2013 13:44

Re: Get player index from ip argument
 
PHP Code:

stock ip_to_id(const ip[], without_port=1) {
    new 
players[32],inum;
    
get_players(players,inum);
    static 
idszIP[32];
    for(new 
i;i<inum;i++) {
        
id players[i];
        
get_user_ip(id,ip,31,without_port);
        if(
equal(ip,szIP)) return id;
    }
    return 
0;


I don't know if there is another more efficient way, but you can use this.

seriousspot 07-19-2013 13:53

Re: Get player index from ip argument
 
Quote:

Originally Posted by akcaliberg (Post 1994549)
PHP Code:

stock ip_to_id(const ip[], without_port=1) {
    new 
players[32],inum;
    
get_players(players,inum);
    static 
idszIP[32];
    for(new 
i;i<inum;i++) {
        
id players[i];
        
get_user_ip(id,ip,31,without_port);
        if(
equal(ip,szIP)) return id;
    }
    return 
0;


I don't know if there is another more efficient way, but you can use this.

so if i understand correctly this cycle is searching for matches and comparing input ip to all players ip that on server, on found returning of matching player id?, by the way player if i am correct the variable players should be 33 not 32?

YamiKaitou 07-19-2013 13:59

Re: Get player index from ip argument
 
Use find_player

akcaliberg 07-19-2013 14:31

Re: Get player index from ip argument
 
Quote:

Originally Posted by seriousspot (Post 1994557)
so if i understand correctly this cycle is searching for matches and comparing input ip to all players ip that on server, on found returning of matching player id?, by the way player if i am correct the variable players should be 33 not 32?

get_players ( players[32], &num, const flags = )

Anyway, use find_player, I didn't know that find_player function has a flag that allow you to search by ip.

new id = find_player("dh",ip_adress)


All times are GMT -4. The time now is 06:32.

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