Remove player from Admin's vehicles
#1

Hello all, i made a small script to remove players from Admin's vehicles but it doesn't work -_-
Can you tell me what is the problem please ?

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if (IsPlayerInVehicle(playerid, 3))
{
if (IsPlayerAdmin(playerid), = 0))
{
SendClientMessage(playerid, COLOR_RED, "This vehicle is an Admin's vehicle you can't drive it");
RemovePlayerFromVehicle(playerid);
}
}
Reply
#2

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(vehicleid == 3 && !IsPlayerAdmin(playerid))
    {
        SendClientMessage(playerid, COLOR_RED, "This vehicle is an Admin's vehicle you can't drive it");
        RemovePlayerFromVehicle(playerid);
    }
    return 1;
}
Reply
#3

Thanx but player isn't removed.
Is there a system to freeze player who want enter in Admin's vehicle for 5 seconds ?
Reply
#4

The problem is that OnPlayerEnterVehicle is called as soon as the person attempts to enter a vehicle. RemovePlayerFromVehicle only works when the person is in the vehicle, but in this case it is being called before the person is even in the vehicle. (Did you also know you can cancel the enter vehicle action, but the callback will still be called?)

So the alternative is to use another method to detect when the player has fully sat in the vehicle, we can do this with OnPlayerStateChange, for example:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER) // Check if the players state has changed to that of a driver
    {
        if(GetPlayerVehicleID(playerid) == 3 && !IsPlayerAdmin(playerid)) // Only changed the vehicleid part to the GetPlayerVehicleID function because vehicleid is not passed in OnPlayerStateChange, so we need to get it
        {
            SendClientMessage(playerid, COLOR_RED, "This vehicle is an Admin's vehicle you can't drive it");
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
Note: Moved to Scripting Discussion, you posted in the wrong section.
Reply
#5

Thank a lot
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)