array must be indexed (variable "playerip") - 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: array must be indexed (variable "playerip") (
/showthread.php?tid=133232)
array must be indexed (variable "playerip") -
Naxix - 11.03.2010
Hey, i was trying to do so if the server get's my ip it would say ADMIN: %s joined.
but i get this error:
Код:
(105) : error 033: array must be indexed (variable "playerip")
This is my script:
Код:
public OnPlayerConnect(playerid)
{
new playerip[16];
GetPlayerIp(playerid,playerip,sizeof(playerip));
if(playerip == [my ip])
{
new name[MAX_PLAYER_NAME],string[32];
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string),"ADMIN: %s joined",name);
SendClientMessageToAll(COLOUR_LIGHTBLUE,string);
PlayerPlaySound(playerid,1185,0,0,0);
SendClientMessage(playerid,COLOUR_YELLOW,"Welcome admin!");
return 1;
}
else
{
new name[MAX_PLAYER_NAME],string[32];
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string),"PLAYER: %s joined",name);
SendClientMessageToAll(COLOUR_LIGHTBLUE,string);
return 1;
}
}
Re: array must be indexed (variable "playerip") -
Correlli - 11.03.2010
IP is a string, so use the strcmp function to compare your IP and the IP of the player who connects.
https://sampwiki.blast.hk/wiki/Strcmp
Re: array must be indexed (variable "playerip") -
iLinx - 11.03.2010
Which line is 105?
And i can already see one thing wrong here :
Код:
if(playerip == [my ip])
You cannot compare strings / arrays using comparison operators such as == or !=, you need to use a function which will compare the two.
Код:
if(!strcmp(playerip, "your ip here"))
will compare playerip and your ip.