OnPlayerRequestSpawn - 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: OnPlayerRequestSpawn (
/showthread.php?tid=280458)
OnPlayerRequestSpawn -
Cowboy - 01.09.2011
Hello SA-MP forum.
If I try to compile this code
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
new tmp[128], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
if(PlayerInfo[playerid][pTeam] == 1)
{
format(tmp,sizeof(tmp),"%s has spawned",pName);
SendClientMessageToAll(-1,tmp);
return 1;
}
else
{
SendClientMessage(playerid, Red, "You are not in this team");
return 0;
}
return 1;
}
It'll return the unreachable code error, but if I remove one of the return it wouldn't work.
https://sampwiki.blast.hk/wiki/OnPlayerRequestSpawn
Returning 0 in this callback will prevent the player from spawning
Thanks
Re: OnPlayerRequestSpawn -
FireCat - 01.09.2011
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
new tmp[128], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
if(PlayerInfo[playerid][pTeam] == 1)
{
format(tmp,sizeof(tmp),"%s has spawned",pName);
SendClientMessageToAll(-1,tmp);
SpawnPlayer(playerid);
return 1;
}
else
{
SendClientMessage(playerid, Red, "You are not in this team");
}
return 0;
}
Re: OnPlayerRequestSpawn -
iggy1 - 01.09.2011
Returning zero will fail. This is just as good. Since its an "if else" block there is no reason to return (early).
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
new tmp[128], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
if(PlayerInfo[playerid][pTeam] == 1)
{
format(tmp,sizeof(tmp),"%s has spawned",pName);
SendClientMessageToAll(-1,tmp);
SpawnPlayer(playerid);
}
else
{
SendClientMessage(playerid, Red, "You are not in this team");
return 0;
}
return 1;
}
EDIT: just realised what you wanted. I was wrong returning zero wouldn't make it fail.