OnPlayerSpawnEx (OPSex) - Make everything easy -
JaKe Elite - 15.10.2012
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;
}
Other Notes
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
OnPlayerSpawnEx has 2 parameters
Код:
playerid - the player (the one who will spawn)
hasspawned - checks if player has the FIRST_SPAWN or the SEC_SPAWN
OnPlayerSpawnEx works the same like OnPlayerSpawn but the difference is the parameters is added.
You could also do like this
PHP код:
public OnPlayerSpawnEx(playerid, hasspawned)
{
printf("[debug] OnPlayerSpawnEx results parameters of hasspawned: %d", hasspawned);
return 1;
}
It can be also used for classes.
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");
Downloadlink
Pastebin - v1.0
Mediafire - v1.0
Pastebin - v1.1
Mediafire - v1.1
Thank you for using OnPlayerSpawnEx (OPSex).inc
Re: OnPlayerSpawnEx (OPSex) - Make everything easy - Emmet_ - 15.10.2012
Or you can do this:
pawn Код:
new bool:g_FirstSpawn[MAX_PLAYERS];
public OnPlayerSpawn(playerid)
{
if (!g_FirstSpawn[playerid])
{
SendClientMessage(playerid, -1, "You've just spawned for the first time!");
g_FirstSpawn[playerid] = true;
}
giveplayermoney
setplayerteam
more code
...
}
Nice work I guess..
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
JaKe Elite - 15.10.2012
Which is more save in energy?
This include or that one, Emmet_
Not sure maybe the same.
Anyway thanks.
Re: OnPlayerSpawnEx (OPSex) - Make everything easy - Emmet_ - 15.10.2012
Quote:
Originally Posted by Romel
Which is more save in energy?
This include or that one, Emmet_
Not sure maybe the same.
Anyway thanks.
|
Not sure, however, this include won't work.
pawn Код:
public OnPlayerConnect(playerid)
{
varSpawn[playerid] = FIRST_SPAWN;
return 1;
}
When the player connects without spawning, your include will think they spawned for the first time, so when they spawn for the first time, your include marks it as a second spawn from that player.
You should do it like this:
pawn Код:
public OnPlayerSpawn(playerid)
{
if (varSpawn[playerid] < 2)
{
varSpawn[playerid] ++;
}
return CallLocalFunction("OnPlayerSpawnEx", "dd", playerid, varSpawn[playerid]);
}
And maybe an IsPlayerSpawned function?
pawn Код:
#define IsPlayerSpawned(%0) varSpawn[%0]
For example, we can use it under OnPlayerSpawn:
pawn Код:
public OnPlayerSpawn(playerid)
{
if (IsPlayerSpawned(playerid) == FIRST_SPAWN)
{
// Spawned for the first time
}
More code here...
return 1;
}
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
JaKe Elite - 15.10.2012
Well yeah i'm planning to add IsPlayerSpawned.
Will add it to next version.
Anyway ******, if (firstSpawn)
I think it would only check if the variable is created.
i'm right?
I do not use that kind of code.
i always do
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
JaKe Elite - 15.10.2012
Hmm,
i learn something today, Thanks..
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
JaKe Elite - 15.10.2012
the next version of OPSex would be in Saturday.
I will not be full time online on Sunday cause i've to prepare something for Monday.
It's Private ok..
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
Niko_boy - 15.10.2012
What a short name you given to this include "OPSex" [-_[-
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
fiki574 - 16.10.2012
Quote:
Originally Posted by Niko_boy
What a short name you given to this include "OPSex" [-_[-
|
The first thing I thought that this include contains callback "OnPlayerSex", but I was wrong :3
Anyways, there's no need for an include like that, you could simply do as Emmet_/****** said!
But again, gj!
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
razvan20100 - 16.10.2012
Nice xD
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
Lordzy - 16.10.2012
Nice, but this can also be used in OnPlayerSpawn itself by creating variables.
For example,
pawn Код:
new spawned[MAX_PLAYERS];
public OnPlayerSpawn(playerid)
{
spawned[playerid]++; //Counts the spawned rates +1.
SendFormattedMessage(playerid, -1, "Spawned times:%d", spawned[playerid]);
//Other stuffs.
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
spawned[playerid] = 0;
//Other stuffs.
return 1;
}
Nice work though.
Re: OnPlayerSpawnEx (OPSex) - Make everything easy - HuSs3n - 16.10.2012
LoL
i came here thinking that this is a sex script
The Title "OPSex" is trolling
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
JaKe Elite - 19.10.2012
Well yeah, OPSex, i was planning to make it OPSEx to make it more detailable.
But in my mind, i want to name it OPSex so i do it as a troll.
Anyway yes you could do a variable.
But it's pretty waste..
Anyway Thanks guys.
Sorry if my english grammar sucks.
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
JaKe Elite - 19.10.2012
v1.1 updated!!
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
RajatPawar - 19.10.2012
Off topic:
On reading the first line of this thread, I was like:
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
Mafioso97 - 19.10.2012
lol ^
Erm, good work there buddy
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
JaKe Elite - 20.10.2012
Thank you.
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
Excips - 23.10.2012
Very well Romel. Its really useful to me and others although.
Re: OnPlayerSpawnEx (OPSex) - Make everything easy -
Skillet` - 23.10.2012
Nice idea but the code is very short to call it an include,wouldn't it better to release it in Useful Snippets ? (or am I wrong ?)
Quote:
Originally Posted by Niko_boy
What a short name you given to this include "OPSex" [-_[-
|
On(e) Player S*x