OnPlayerEnterVehicle | Question
#1

I'm trying to make the vehicle only restrict users from entering if they're attempting to get in the driver seat BUT the script is stopping both driver and passenger...How can i make it only driver and allow passenger??

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    for(new i = 0; i < 12; i++)
    {
        if(vehicleid == LSPDVehicles[i]) //If the vehicleid is an LSPD vehicle
        {
            if(PlayerInfo[playerid][pFaction] != 1)
            {
                ClearAnimations(playerid);
                SendClientMessage(playerid, -1, "This vehicle is faction restricted.");
            }
        }
    }
    return 1;
}
Reply
#2

Use This !!!
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
Reply
#3

change
pawn Код:
if(PlayerInfo[playerid][pFaction] != 1)
to

pawn Код:
if(PlayerInfo[playerid][pFaction] != 1 && GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
Reply
#4

I tried it like this
Код:
            if(PlayerInfo[playerid][pFaction] != 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                ClearAnimations(playerid);
                SendClientMessage(playerid, COLOR_GREY, "This vehicle is faction restricted.");
            }
But it now allows passengers and drivers to enter.... Can you help me a bit more?

I tried both states

GetPlayerState(playerid) == PLAYER_STATE_DRIVER)

GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
Reply
#5

https://sampwiki.blast.hk/wiki/OnPlayerEnterVehicle

Quote:

This callback is called when a player BEGINS to enter a vehicle, not when they HAVE entered it. See OnPlayerStateChange.

Use this:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);

    switch(newstate)
    {
        case PLAYER_STATE_DRIVER:
        {
            for(new i = 0; i < 12; i++)
            {
                if(vehicleid == LSPDVehicles[i] && PlayerInfo[playerid][pFaction] != 1)
                {
                    RemovePlayerFromVehicle(playerid);
                    SendClientMessage(playerid, -1, "This vehicle is faction restricted.");
                    break;
                }
            }
        }
    }

    return true;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)