GetPlayerState - Help!
#1

I had make some cmd which is used only when player is spawned, but when player spawn, cmd don't work it sendclientmessage:You can use rescue if you not spawned

So does I need to add anything OnPlayerStateChange or?

pawn Код:
COMMAND:rescue(playerid, params[])
{
    if (APlayerData[playerid][LoggedIn] == true)
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_SPAWNED)
        {
                 // CMD
        }
        else
            SendClientMessage(playerid, 0xFF0000FF, "You can use rescue if you not spawned");
    }
    else
        return 0;
       
    return 1;
}
Reply
#2

Okay, first off, the function GetPlayerVehicleID gets you the vehicle's ID.

Let me say that one more time, the vehicle's ID....Appearently you do not differentiate between a vehicle model and a vehicle ID
https://sampwiki.blast.hk/wiki/Vehicle_Model_ID_List - Vehicle Model List, there is no Vehicle Model ID 0 in SAMP...

A vehicle ID is assigned to every vehicle spawned in the server, works more or less like the playerid, it specifies a vehicle in the server. If you wanna know what VEHICLE MODEL a player is in, use this:
https://sampwiki.blast.hk/wiki/GetVehicleModel

Correct usage:
pawn Код:
new vid; // name this whatever you want, this is the variable we'll assign to the vehicleid of the player.
vid = GetPlayerVehicleID(playerid) // under the cmd
if(GetVehicleModel(vid) == VEHICLE) // This is checking the model of vid, the vehicle id the player is in, as I said each spawned vehicle in the server has its own specific ID
//change "VEHICLE" to whatever vehicle you want.
Note: if you wanna know if he is not in any car, use the following function:
https://sampwiki.blast.hk/wiki/IsPlayerInAnyVehicle
Hope this helps.
Reply
#3

Sorry but, i know that and I missed code sry, look this is problem

PLAYER_STATE_SPAWNED

coz it get player state like he isn't spawned, but he clicked on button "Spawn"
Reply
#4

I can't really remember the name of the author though.
pawn Код:
stock IsPlayerSpawned( playerid )
{
    new
        state_ = GetPlayerState( playerid )
    ;
    return ( state_ != PLAYER_STATE_NONE && state_ != PLAYER_STATE_WASTED && state_ != PLAYER_STATE_SPECTATING );
}
Reply
#5

Quote:
Originally Posted by AntonioCroatia
Посмотреть сообщение
Sorry but, i know that and I missed code sry, look this is problem

PLAYER_STATE_SPAWNED

coz it get player state like he isn't spawned, but he clicked on button "Spawn"
If you wanna check if a player is or isn't spawned, just create a new boolean, and assign it to him, and then it'll vary whether he actually IS or isn't spawned.
pawn Код:
new bool:Spawned[MAX_PLAYERS] = false; // a boolean can only be set to "true", or "false".
public OnPlayerConnect(playerid)
{
     Spawned[playerid] = false;
     return 1;
}
public OnPlayerSpawn(playerid)
{
     Spawned[playerid] = true;
     return 1;
}
// and under the cmd check if Spawned[playerid] == true, else he isn't spawned so send him an error message.
// NOTE: Do not directly use this snippet, you must edit it to sync with your script, example:
//if he's going to a tutorial, then under OnPlayerSpawn, check if he isn't going to a tutorial, if so, assign it to true, else assign it to false or this will be pointless.
Reply
#6

Quote:
Originally Posted by Sandiel
Посмотреть сообщение
If you wanna check if a player is or isn't spawned, just create a new boolean, and assign it to him, and then it'll vary whether he actually IS or isn't spawned.
pawn Код:
new bool:Spawned[MAX_PLAYERS] = false; // a boolean can only be set to "true", or "false".
public OnPlayerConnect(playerid)
{
     Spawned[playerid] = false;
     return 1;
}
public OnPlayerSpawn(playerid)
{
     Spawned[playerid] = true;
     return 1;
}
// and under the cmd check if Spawned[playerid] == true, else he isn't spawned so send him an error message.
// NOTE: Do not directly use this snippet, you must edit it to sync with your script, example:
//if he's going to a tutorial, then under OnPlayerSpawn, check if he isn't going to a tutorial, if so, assign it to true, else assign it to false or this will be pointless.
And let's say a player is bugged after the death and he is not spawned back. What you've got so far is not working properly, in OnPlayerDeath set it to false.

Though, I'd recommend the function I posted above!
Reply
#7

Quote:
Originally Posted by _Zeus
Посмотреть сообщение
And let's say a player is bugged after the death and he is not spawned back. What you've got so far is not working properly, in OnPlayerDeath set it to false.

Though, I'd recommend the function I posted above!
I suppose I neglected that fact, I forgot about it sorry, but both of the codes above work, just in different ways.
Reply
#8

Hey. No need for all that fuss. PLAYER_STATE_SPAWNED is used only the very moment when player is spawning. I recommend you replacing it with if(7 > state >0){ ... this way, all states when player is spawned are processed (basically excluding wasted & spectating & none).
Reply
#9

Quote:
Originally Posted by Sandiel
Посмотреть сообщение
If you wanna check if a player is or isn't spawned, just create a new boolean, and assign it to him, and then it'll vary whether he actually IS or isn't spawned.
pawn Код:
new bool:Spawned[MAX_PLAYERS] = false; // a boolean can only be set to "true", or "false".
public OnPlayerConnect(playerid)
{
     Spawned[playerid] = false;
     return 1;
}
public OnPlayerSpawn(playerid)
{
     Spawned[playerid] = true;
     return 1;
}
// and under the cmd check if Spawned[playerid] == true, else he isn't spawned so send him an error message.
// NOTE: Do not directly use this snippet, you must edit it to sync with your script, example:
//if he's going to a tutorial, then under OnPlayerSpawn, check if he isn't going to a tutorial, if so, assign it to true, else assign it to false or this will be pointless.
It's working, but i need to put in OnPlayerDeath and so on...

Quote:
Originally Posted by _Zeus
Посмотреть сообщение
And let's say a player is bugged after the death and he is not spawned back. What you've got so far is not working properly, in OnPlayerDeath set it to false.

Though, I'd recommend the function I posted above!
Sorry, but i tried this, and it's not working, same like before
Reply
#10

Weird, because it does work just fine on me. Anyway, Sandiel's suggestion is also fine. Just add the OnPlayerDeath too and it's good.

pawn Код:
public OnPlayerDeath( playerid, killerid, reason )
{
    Spawned[playerid] = false;
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)