15.10.2012, 10:37
(
Последний раз редактировалось JaKe Elite; 19.10.2012 в 09:27.
Причина: Update.
)
OnPlayerSpawnEx (OPSex) - Make everything easy
v1.1 is just released today more features like detecting if player respawn
Introduction
Well i'm bored today,
While browsing in the forum, i have idea.
I build this include for scripters.
Ex.
A Scripter wants a dialog pop up OnPlayerSpawn (Will not show the dialog again after death)
instead of creating global player variables (variables). OnPlayerSpawnEx is build to do that.
Example
PHP код:
public OnPlayerSpawnEx(playerid, hasspawned)
{
if(hasspawned == FIRST_SPAWN) //If player's first spawn)
{
ShowPlayerDialog(playerid, 123, DIALOG_STYLE_MSGBOX, "Debug", "It work", "Yes", "");
}
else if(hasspawned == SEC_SPAWN) //if player's second spawn (even 3rd etc.. spawn)
{
SendClientMessage(playerid, -1, "It's your second spawn!");
}
else if(hasspawned == RESPAWN) //if player respawn (only called when SetPlayerToRespawn is called)
{
SendClientMessage(playerid, -1, "You've respawned!");
varSpawn[playerid] = FIRST_SPAWN; //you've to do this so OnPlayerSpawnEx stops detecting you respawning even you didn't respawn.
}
return 1;
}
I also notice that the include disables OnPlayerSpawn.
OnPlayerSpawn will not called anymore.
So i suggest you to put all your codes from OnPlayerSpawn to OnPlayerSpawnEx.
Other notes, I don't found a bug..
How to use it
First of all, When player connects OnPlayerSpawnEx parameter, hasspawned is set to 0.
To avoid the problems. hasspawned is set to 1 after OnPlayerSpawnEx is called.
Код:
0 = FIRST_SPAWN 1 = SEC_SPAWN 2 = RESPAWN
Код:
playerid - the player (the one who will spawn) hasspawned - checks if player has the FIRST_SPAWN or the SEC_SPAWN
You could also do like this
PHP код:
public OnPlayerSpawnEx(playerid, hasspawned)
{
printf("[debug] OnPlayerSpawnEx results parameters of hasspawned: %d", hasspawned);
return 1;
}
SetPlayerToRespawn(playerid)
It works the same like SpawnPlayer, doesn't work OnPlayerConnect, OnPlayerRequestClass..
It sets the hasspawned to RESPAWN, you've to set hasspawned to 0 by yourself to avoid the problems.
Note: If hasspawned (varSpawn) is not set back to 0 after player spawn, in next spawn the include will detect the player that he respawn.
IsPlayerSpawned(playerid)
It works the same like other native functions of SA-MP
pawn Код:
if(IsPlayerSpawned(playerid) == FIRST_SPAWN) print("[debug] 0");
Pastebin - v1.0
Mediafire - v1.0
Pastebin - v1.1
Mediafire - v1.1
Thank you for using OnPlayerSpawnEx (OPSex).inc