getip doesn't work properly
#1

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;
}

Reply
#2

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

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

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;
}
Reply
#5

::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.
Reply
#6

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.
Reply
#7

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)