Raised This Month: $ Target: $400
 0% 

Get player index from ip argument


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
seriousspot
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
Old 07-19-2013 , 13:12   Get player index from ip argument
Reply With Quote #1

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

Last edited by seriousspot; 07-19-2013 at 13:41.
seriousspot is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 07-19-2013 , 13:44   Re: Get player index from ip argument
Reply With Quote #2

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.

Last edited by akcaliberg; 07-19-2013 at 13:45.
akcaliberg is offline
seriousspot
BANNED
Join Date: Mar 2013
Location: Lithuania / Norway
Old 07-19-2013 , 13:53   Re: Get player index from ip argument
Reply With Quote #3

Quote:
Originally Posted by akcaliberg View Post
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?
seriousspot is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-19-2013 , 13:59   Re: Get player index from ip argument
Reply With Quote #4

Use find_player
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 07-19-2013 , 14:31   Re: Get player index from ip argument
Reply With Quote #5

Quote:
Originally Posted by seriousspot View Post
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)

Last edited by akcaliberg; 07-19-2013 at 14:36.
akcaliberg is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:28.


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