GetPlayerIp
#1

Код:
if(!strcmp(cmdtext, "/ip", true, 3))
{
if(!cmdtext[3])return SendClientMessage(playerid, 0xFF0000FF, "Please enter an IP!");

if(IsPlayerConnected(cmdtext[4])) {


new str[128];
format(str, sizeof(str), "%s", GetPlayerIp (cmdtext[4]));
SendClientMessage (playerid, 0xFF0000FF, str);
}

else {

SendClientMessage (playerid, 0xFF0000FF, "Player is not online!");

}

return 1;


}
It always says the player is offline!
Reply
#2

pawn Код:
if(strcmp(cmd, "/getip", true) == 0)
{
    tmp = strtok(cmdtext,idx);
    new playersip[16];
    if(!strlen(tmp))
    {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"USAGE: /getip [playerid]");
            return 1;
    }
    giveplayerid = ReturnUser(tmp);
    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
    GetPlayerIp( giveplayerid,playersip,sizeof(playersip));
    format(string, sizeof(string), "|| Player: %s - IP: %s||",giveplayer, playersip);
    SendClientMessage(playerid,0xFF0000FF,string);
    return 1;
}
I strongly recommend switching over to Zcmd and sscanf2
As Zcmd is a much faster command processor.
Reply
#3

I didn't get what you actually mean, but I hope you're trying to code '/ip [playerid]'. Well here's one with zcmd and sscanf2.
pawn Код:
CMD:ip(playerid, params[])
{
 new p2;
 if(sscanf(params, "r", p2)) return SendClientMessage(playerid, 0xFF0000FF, "Usage: /ip [playerid]");
 if(p2 == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000FF, "Player is offline.");
 new ip[16];
 GetPlayerIp(p2, ip, sizeof(ip));
 new str[128], Lname[MAX_PLAYER_NAME];
 GetPlayerName(p2, Lname, sizeof(Lname));
 format(str, sizeof(str), "%s's IP:%d", Lname, ip);
 SendClientMessage(playerid, 0xFF0000, str);
 return 1;
}
Edit:late.
Reply
#4

None of the ones above work, thanks though.

Does anyone else know?
Reply
#5

Try this make sure you have
Код:
#include <sscanf2>

plugins sscanf
pawn Код:
if(strcmp(cmd, "/getip", true) == 0)
{
            new ID;
            new player1 = strval(params), string[128];
            new tmp3[50]; GetPlayerIp(player1,tmp3,50);
            if(sscanf(params, "u", ID))
            {
                SendClientMessage(playerid,COLOR_ERROR,"Syntax: /getip (playerid)");
                return 1;
            }
            if(!IsPlayerConnected(ID))
            {
                format(string,sizeof(string),"The Player ID (%d) is not connected to the server.",ID);
                SendClientMessage(playerid,COLOR_ERROR,string);
                return 1;
            }
            format(string,sizeof(string),"IP: %s", tmp3);
            SendClientMessage(playerid, -1, string);
            return 1;
        }
Reply
#6

It comes up with

Код:
C:\Users\Test23\Desktop\Server\gamemodes\Test23.pwn(479) : error 017: undefined symbol "cmd"
C:\Users\Test23\Desktop\Server\gamemodes\Test23.pwn(482) : error 017: undefined symbol "params"
C:\Users\Test23\Desktop\Server\gamemodes\Test23.pwn(484) : error 017: undefined symbol "params"
Reply
#7

Add it under OnPlayerCommandText.
Reply
#8

Now I get

Код:
C:\Users\Test23\Desktop\Server\gamemodes\Test23.pwn(482) : error 035: argument type mismatch (argument 1)
C:\Users\Test23\Desktop\Server\gamemodes\Test23.pwn(485) : error 035: argument type mismatch (argument 1)
C:\Users\Test23\Desktop\Server\gamemodes\Test23.pwn(487) : error 035: argument type mismatch (argument 1)
Reply
#9

Quote:
Originally Posted by Lordz
format(str, sizeof(str), "%s's IP:%d", Lname, ip);
ip is string not integer.
@Author - strcmp is very slow, switch to ZCMD.
Reply
#10

Just to help you out, strcmp takes alot of lines.. Just try to use zcmd (tutorial can be found here) and sscanf and foreach aswell.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)