SA-MP Forums Archive
IP of a player. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: IP of a player. (/showthread.php?tid=274948)



IP of a player. - iGetty - 07.08.2011

I've had this before, but I can't seem to find it now? :S

I have this on when a player connects for an admin to see:

"%s has joined the server.", I would like it with:

"%s has joined the server. IP: %(what here.)", Ipgetting thing here);

But I can't seem to get it, I tried GetPlayerIp, but it just shows


pawn Код:
public OnPlayerConnect(playerid)
{
    new plrIP[16];
    GetPlayerIp(playerid, plrIP, sizeof(plrIP));
    if(!strcmp(plrIP, "127.0.0.1"))
    SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to your server, master :)");
    return 1;
}
How do I get it to SHOW the IP of a player?

Thanks.


Re: IP of a player. - JaTochNietDan - 07.08.2011

Use format and puyt the plrIP string into it. For example:

pawn Код:
new string[128];

format(string, sizeof(string), "Welcome to your server, master. IP: %s", string);
SendClientMessage(playerid, 0xFFFFFFFF, string);
Hope that helps!


Re: IP of a player. - Anzipane! - 07.08.2011

You need to format the string. (The IP is a string so you should use "%s" identifier)
Example:
pawn Код:
new plrIP[16], string[32];
    GetPlayerIp(playerid, plrIP, sizeof(plrIP));
    format(string, sizeof(string), "IP: %s", plrIP);
    SendClientMessageToAll(COLOR, string);
EDIT: oh, JaTochNietDan replied faster than me.


Re: IP of a player. - iGetty - 07.08.2011

So, if I want it to be on this:

pawn Код:
SendClientMessage(playerid, WHITE, "%s has joined the server. IP: %(what here.)");
It would be:

pawn Код:
new IPString[128];
GetPlayerIp(playerid, IPString, sizeof(IPString));
format(string, sizeof(string), "%s has joined the server. IP: %s", IPString);
SendClientMessage(playerid, WHITE, IPString);
Would that be right?, Thanks mate.


Re: IP of a player. - Anzipane! - 07.08.2011

No, you need to declare a string where you will store the formatted string, the correct way is:
pawn Код:
new IPString[16], string[128] playername[MAX_PLAYER_NAME]; // Declare a new array for storing the formatted string
GetPlayerIp(playerid, IPString, sizeof(IPString));
GetPlayerName(playerid, playername, sizeof(playername));
format(string, sizeof(string), "%s has joined the server. IP: %s", playername, IPString);
SendClientMessage(playerid, WHITE, string);
EDIT: fixed code now, I didn't see that the playername array was missing.


Re: IP of a player. - iGetty - 07.08.2011

Thanks, I get it now


Re: IP of a player. - Basicz - 07.08.2011

@Getty, you forgot GetPlayerName

pawn Код:
public OnPlayerConnect( playerid ) {
        #pragma tabsize 8 // Sorry I deleted some things before, it's 8 spaces now.

        static
            szString[ 128 ],
            szIP[ 16 ],
            szName[ 24 ]
        ;

        GetPlayerIP( playerid, szIP, 16 );
        GetPlayerName( playerid, szName, 24 );

        format( szString, 128, "%s has joined the server. ( IP : %s ).", szIP );

        foreach (Player, i) {
            if ( IsPlayerAdmin( i ) ) {
                SendClientMessage( i, -1, szString );
            }
        }

    #pragma tabsize 4
   
    return 1;
}