[Include] OnPlayerSpawnEx (OPSex) - Make everything easy
#1

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(playeridhasspawned)
{
    if(
hasspawned == FIRST_SPAWN//If player's first spawn)
    
{
        
ShowPlayerDialog(playerid123DIALOG_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(playeridhasspawned)
{
    
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
Reply
#2

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..
Reply
#3

Which is more save in energy?

This include or that one, Emmet_

Not sure maybe the same.

Anyway thanks.
Reply
#4

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;
}
Reply
#5

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

pawn Код:
if (firstSpawn == 0)
Reply
#6

Hmm,
i learn something today, Thanks..
Reply
#7

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..
Reply
#8

What a short name you given to this include "OPSex" [-_[-
Reply
#9

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!
Reply
#10

Nice xD
Reply
#11

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.
Reply
#12

LoL
i came here thinking that this is a sex script
The Title "OPSex" is trolling
Reply
#13

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.
Reply
#14

v1.1 updated!!
Reply
#15

Off topic:
On reading the first line of this thread, I was like:
Reply
#16

lol ^

Erm, good work there buddy
Reply
#17

Thank you.
Reply
#18

Very well Romel. Its really useful to me and others although.
Reply
#19

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)