SA-MP Forums Archive
getip doesn't work properly - 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)
+--- Thread: getip doesn't work properly (/showthread.php?tid=569078)



getip doesn't work properly - saffierr - 28.03.2015

So basically, at the moment I type /getip in my server I get "49" lol.

What's wrong with the code? can someone help me with this.
Quote:

CMD:getip(playerid, params[])
{
new playerip[20];
GetPlayerIp(playerid, playerip, sizeof(playerip));
format(playerip, sizeof playerip, "%i", playerip);
SendClientMessage(playerid, COLOR_LIGHTBLUE ,playerip);
return 1;
}




Re: getip doesn't work properly - Jefff - 28.03.2015

IP is a string not number, use %s, but you don't need format if you want show only IP without other info


Re: getip doesn't work properly - saffierr - 28.03.2015

I changed the integer, thanks.
But what would it be then? if it doesn't requires a format?


Re: getip doesn't work properly - Jefff - 28.03.2015

only IP without any other info
pawn Код:
CMD:getip(playerid, params[])
{
new playerip[16];
GetPlayerIp(playerid, playerip, sizeof(playerip));
SendClientMessage(playerid, COLOR_LIGHTBLUE ,playerip);
return 1;
}
or if you want more info you need format
pawn Код:
CMD:getip(playerid, params[])
{
new playerip[30];
GetPlayerIp(playerid, playerip, sizeof(playerip));
format(playerip, sizeof playerip, "Your IP: %s", playerip);
SendClientMessage(playerid, COLOR_LIGHTBLUE ,playerip);
return 1;
}



Re: getip doesn't work properly - saffierr - 28.03.2015

::Nevermind::
It's fixed!
I just had to put %s instead of %i.
But can you explain me, How should I know ip is a %s(tring) and not %i(nteger) because integer has to do with numbers, but so does an ip lol.


Respuesta: Re: getip doesn't work properly - Juand - 28.03.2015

Quote:
Originally Posted by saffierr
Посмотреть сообщение
::Nevermind::
It's fixed!
I just had to put %s instead of %i.
But can you explain me, How should I know ip is a %s(tring) and not %i(nteger) because integer has to do with numbers, but so does an ip lol.
pawn Код:
new playerip[20];
GetPlayerIp(playerid, playerip, sizeof(playerip));
If you read that, you'll understand... are using string, not numbers.


Re: getip doesn't work properly - CalvinC - 28.03.2015

Quote:
Originally Posted by saffierr
Посмотреть сообщение
::Nevermind::
It's fixed!
I just had to put %s instead of %i.
But can you explain me, How should I know ip is a %s(tring) and not %i(nteger) because integer has to do with numbers, but so does an ip lol.
Because it contains dots, like "127.0.0.1", while an integer would only be able to hold "127001", which is incorrect.