SA-MP Forums Archive
OnPlayerStateChange help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerStateChange help (/showthread.php?tid=538946)



OnPlayerStateChange help - kesarthakur - 25.09.2014

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


Re: OnPlayerStateChange help - Ox1gEN - 25.09.2014

Well, you could use OnPlayerEnterVehicle.

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


Re: OnPlayerStateChange help - kesarthakur - 25.09.2014

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??


Re: OnPlayerStateChange help - M0HAMMAD - 25.09.2014

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;
}



Re: OnPlayerStateChange help - Beckett - 25.09.2014

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.)


Re: OnPlayerStateChange help - ranme15 - 25.09.2014

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



Re: OnPlayerStateChange help - kesarthakur - 25.09.2014

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


Re: OnPlayerStateChange help - Beckett - 25.09.2014

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.


Re: OnPlayerStateChange help - kesarthakur - 25.09.2014

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


Re: OnPlayerStateChange help - Pottus - 25.09.2014

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;
}