SA-MP Forums Archive
OnPlayerSpawn vs. 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: OnPlayerSpawn vs. OnPlayerRequestSpawn (/showthread.php?tid=148020)



OnPlayerSpawn vs. OnPlayerRequestSpawn - cAMo - 15.05.2010

1. If OnPlayerRequestSpawn returns 0, is it possible through a glitch or hack to still spawn?

2. Are these both secure?

public OnPlayerRequestSpawn(playerid)
{
if(GetPVarInt(playerid, "logged_in") == 1)
{
return 1;
}
else
{
Login_Box(playerid);
return 0;
}
}


and


public OnPlayerSpawn(playerid)
{
if(GetPVarInt(playerid, "logged_in") == 1)
{
SetPlayerSpawnDetails(playerid);
return 1;
}
else
{
System_Kick(playerid, "Spawned Without Logging In");
return 0;
}
}

3. Is it necessary to have the if/else in OnPlayerSpawn?


Re: OnPlayerSpawn vs. OnPlayerRequestSpawn - juice.j - 15.05.2010

The second check in OnPlayerSpawn shouldn't be necessary anymore. OnPlayerRequestSpawn always gets called and your function seems quite safe.


Re: OnPlayerSpawn vs. OnPlayerRequestSpawn - cAMo - 15.05.2010

I really appreciate all of your help! One more question...

I have a custom function OnPlayerLogin...

It is called once someone logs into their account. Then it distributes all of their account variables from my MYSQL database to their PVars.

ie:

public OnPlayerLogin(playerid)
{

**all of the Pvars being set and database stuff**

if(GetPVarInt(playerid, "banned") == 1)
{
System_Ban(playerid, "Account Banned");
return 1;
}
if(GetPVarInt(playerid, "locked") == 1)
{
System_Kick(playerid, "Character Locked");
return 1;
}

**set additional pvar's and stuff***

return 1;

}


Q: Will the bolded return 1's end the function (assuming the player is locked or banned) and not continue setting the additional pvars beneath it?

Q: Hopefully it does, but should it be return 1 or return 0? Does it matter?


Re: OnPlayerSpawn vs. OnPlayerRequestSpawn - juice.j - 15.05.2010

Returns end the function at the respective line, any code below won't be executed anymore.

Whether you return 1 or 0 in custom functions doesn't matter in that case (if you do not use the return value of this function somewhere else). I prefer returning 1 as - unlike to other languages - you don't go for the phrase "I return 0 as there are 0 errors" in samp scripting anyways.

Just keep on returning 1, it's all fine.