OnPlayerStateChange help
#1

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( oldstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_DRIVER)
    {
        if(IsAdminv(GetPlayerVehicleID(playerid)))
        {
            if(PlayerInfo[playerid][Admin] < 1)
            {
            new vehicleid;
            vehicleid= GetPlayerVehicleID(playerid);
            DestroyVehicle(vehicleid);
            SendClientMessage(playerid, 0xFF0000FF, ""RED"ERROR:"GREY" Unauthorized Vehicle");
            }
        }
    }
    return 1;
}

stock IsAdminv(vehicleid)
{
    new result;
    new model = GetVehicleModel(vehicleid);
    switch(model)
    {
        case 425, 432, 447, 430, 449, 476, 520, 537, 538, 569, 570, 577, 590, 592, 610: result = model;
        default: result = 0;
    }
    return result;
}
this code is deleting the vehicles when they enter in them or spawn them on foot but when they spawn these vehicles while in a vehicle then the script isnt deleting the vehicle

please help me

thanks in advance
Reply
#2

Well, you could use OnPlayerEnterVehicle.

This'll make stuff alot easier instead of checking for player states.
Reply
#3

Quote:
Originally Posted by Ox1gEN
Посмотреть сообщение
Well, you could use OnPlayerEnterVehicle.

This'll make stuff alot easier instead of checking for player states.
will it work when player put in vehicle from server sided script??
Reply
#4

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER) // Edited
    {
        if(IsAdminv(GetPlayerVehicleID(playerid)))
        {
            if(PlayerInfo[playerid][Admin] < 1)
            {
            new vehicleid;
            vehicleid= GetPlayerVehicleID(playerid);
            DestroyVehicle(vehicleid);
            SendClientMessage(playerid, 0xFF0000FF, ""RED"ERROR:"GREY" Unauthorized Vehicle");
            }
return 1; // Added
        }
    }
    return 1;
}
Reply
#5

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( oldstate == PLAYER_STATE_ONFOOT || newstate == PLAYER_STATE_DRIVER)
    {
        if(IsAdminv(GetPlayerVehicleID(playerid)))
        {
            if(PlayerInfo[playerid][Admin] < 1)
            {
            new vehicleid;
            vehicleid= GetPlayerVehicleID(playerid);
            DestroyVehicle(vehicleid);
            SendClientMessage(playerid, 0xFF0000FF, ""RED"ERROR:"GREY" Unauthorized Vehicle");
            }
        }
    }
    return 1;
}
If his old state is DRIVER then new state is driver? this is impossible. You gotta check if he was on foot then he got in a vehicle (State changed to DRIVER.)
Reply
#6

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( oldstate == PLAYER_STATE_ONFOOT || newstate == PLAYER_STATE_DRIVER)
    {
        if(IsAdminv(GetPlayerVehicleID(playerid)))
        {
            if(PlayerInfo[playerid][Admin] < 1)
            {
            new vehicleid;
            vehicleid= GetPlayerVehicleID(playerid);
            DestroyVehicle(vehicleid);
            SendClientMessage(playerid, 0xFF0000FF, ""RED"ERROR:"GREY" Unauthorized Vehicle");
            }
        }
    }
    return 1;
}
If his old state is DRIVER then new state is driver? this is impossible. You gotta check if he was on foot then he got in a vehicle (State changed to DRIVER.)
It makes no sense, you probably meant && instead of ||.
Anyways, another option is also available:
PHP код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER
Reply
#7

this code is deleting the vehicles when they enter in them or spawn them on foot but when they spawn these vehicles while in a vehicle then the script isnt deleting the vehicle
Reply
#8

Quote:
Originally Posted by kesarthakur
Посмотреть сообщение
this code is deleting the vehicles when they enter in them or spawn them on foot but when they spawn these vehicles while in a vehicle then the script isnt deleting the vehicle
What basically you're checking is..


IF PLAYER WAS IN A VEHICLE..


>>>>

Then he got TPed into another one.

>>>>

Delete 2nd vehicle.
Reply
#9

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
What basically you're checking is..


IF PLAYER WAS IN A VEHICLE..


>>>>

Then he got TPed into another one.

>>>>

Delete 2nd vehicle.
it isn't deleting the second one
Reply
#10

I can see the issue now your not saving any reference to the old vehicle of course.

pawn Код:
static CurrVehicleID[MAX_PLAYERS];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        if(IsAdminv(CurrVehicleID[playerid]))
        {
            if(PlayerInfo[playerid][Admin] < 1)
            {
                if(oldstate == PLAYER_STATE_DRIVER) DestroyVehicle(CurrVehicleID[playerid]);
                SendClientMessage(playerid, 0xFF0000FF, ""RED"ERROR:"GREY" Unauthorized Vehicle");
            }
        }
        CurrVehicleID[playerid] = GetPlayerVehicleID(playerid);

    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)