Detect if player exit car
#1

Hey.. I'm continue work on driving test and I got into a problem...
I want to make that if the player leave the car so the car respawn and he lose the driving test..
I did this but its not working...

public OnPlayerStateChange(playerid, newstate, oldstate)

pawn Код:
if(IsADMV(GetPlayerVehicleID(playerid)))
    {
        if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT || oldstate == PLAYER_STATE_PASSENGER && newstate == PLAYER_STATE_ONFOOT)
        {
            new veh;
            veh = GetPlayerVehicleID(playerid);
            DrivingTest[playerid] = 0;
            DisablePlayerCheckpoint(playerid);
            SetVehicleToRespawn(veh);
            SendClientMessage(playerid,COLOR_RED,"STATUS: You left your car, FAIL!");
            return 1;
        }
    }
Any suggestions? btw.. I tried to put it onplayerexitvehicle but still didnt work..
Reply
#2

Try this:
pawn Код:
if(IsADMV(GetPlayerVehicleID(playerid)))
    {
        if((oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER) && newstate == PLAYER_STATE_ONFOOT)
        {
            DrivingTest[playerid] = 0;
            DisablePlayerCheckpoint(playerid);
            SetVehicleToRespawn(GetPlayerVehicleID(playerid));
            SendClientMessage(playerid,COLOR_RED,"STATUS: You left your car, FAIL!");
            return 1;
        }
    }
Reply
#3

pawn Код:
if(newstate == 1 && (oldstate == 2 || oldstate == 3))
Notice the brackets.
Reply
#4

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsADMV(vehicleid))
    {
        DrivingTest[playerid] = 0;
        DisablePlayerCheckpoint(playerid);
        SetVehicleToRespawn(vehicleid);
        SendClientMessage(playerid,COLOR_RED,"STATUS: You left your car, FAIL!");
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by antonio112
Посмотреть сообщение
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsADMV(vehicleid))
    {
        DrivingTest[playerid] = 0;
        DisablePlayerCheckpoint(playerid);
        SetVehicleToRespawn(vehicleid);
        SendClientMessage(playerid,COLOR_RED,"STATUS: You left your car, FAIL!");
    }
    return 1;
}
He said, didn't working with OnPlayerExitVehicle
Reply
#6

OnPlayerExitVehicle
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsADMV(GetPlayerVehicleID(playerid))) {
        new playerState = GetPlayerState(playerid);
        if(playerState == PLAYER_STATE_PASSENGER || playerState == PLAYER_STATE_DRIVER) {
            DrivingTest[playerid] = 0;
            DisablePlayerCheckpoint(playerid);
            SetVehicleToRespawn(GetPlayerVehicleID(playerid));
            SendClientMessage(playerid,COLOR_RED,"STATUS: You left your car, FAIL!");
            return 1;
        }
    }
    // Rest of Code here
    return 1;
}
Quote:
Originally Posted by sabretur
Посмотреть сообщение
He said, didn't working with OnPlayerExitVehicle
May he had wrong code
Reply
#7

Quote:
Originally Posted by sabretur
Посмотреть сообщение
He said, didn't working with OnPlayerExitVehicle
Because he didn't know how to do it. Trust me, my code works.
Reply
#8

Edit!!
sorry didnt notice that more 5 people replied.. I'll try all of your ideas
Reply
#9

Quote:
Originally Posted by Kostas'
Посмотреть сообщение
OnPlayerExitVehicle
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsADMV(GetPlayerVehicleID(playerid))) {
        new playerState = GetPlayerState(playerid);
        if(playerState == PLAYER_STATE_PASSENGER || playerState == PLAYER_STATE_DRIVER) {
            DrivingTest[playerid] = 0;
            DisablePlayerCheckpoint(playerid);
            SetVehicleToRespawn(GetPlayerVehicleID(playerid));
            SendClientMessage(playerid,COLOR_RED,"STATUS: You left your car, FAIL!");
            return 1;
        }
    }
    // Rest of Code here
    return 1;
}

May he had wrong code
Thanks man! It worked!
and antonio.. I did exactly like you did myself and it didnt work before...

And one the way I have another problem.. just want to ask if its going to work:

pawn Код:
else if(PlayerToPoint(5.0,playerid,1638.0692,-1903.3049,13.4268))
            {
                new Float:health;
                new veh;
                veh = GetPlayerVehicleID(playerid);
                GetVehicleHealth(veh, health);
                if(health >= 700)
                {
                    SendClientMessage(playerid,COLOR_GREEN,"STATUS: You kept the vehicle almost fully unharmed, Passed.");
                    PlayerInfo[playerid][pCarLic] = 1;
                    SetVehicleToRespawn(veh);
                    DrivingTest[playerid] = 0;
                    DisablePlayerCheckpoint(playerid);
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid,COLOR_RED,"STATUS: You failed the test, better luck next time!");
                    SetVehicleToRespawn(veh);
                    DrivingTest[playerid] = 0;
                    DisablePlayerCheckpoint(playerid);
                    return 1;
                }
btw.. I have another part in my script that showing in cars the car health.. so I need to use it? or how I did its okay?

if the car health will get to 70 or lower so the player will fail..
Reply
#10

Quote:
Originally Posted by Kostas'
Посмотреть сообщение
OnPlayerExitVehicle
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsADMV(GetPlayerVehicleID(playerid))) {
        new playerState = GetPlayerState(playerid);
        if(playerState == PLAYER_STATE_PASSENGER || playerState == PLAYER_STATE_DRIVER) {
            DrivingTest[playerid] = 0;
            DisablePlayerCheckpoint(playerid);
            SetVehicleToRespawn(GetPlayerVehicleID(playerid));
            SendClientMessage(playerid,COLOR_RED,"STATUS: You left your car, FAIL!");
            return 1;
        }
    }
    // Rest of Code here
    return 1;
}

May he had wrong code
Just looking your code i want ask why you use GetPlayerVehicleID(playerid) ? it get 0 i think. Function have already getting vehicleid in params
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsADMV(vehicleid)) {
            DrivingTest[playerid] = 0;
            DisablePlayerCheckpoint(playerid);
            SetVehicleToRespawn(vehicleid);
            SendClientMessage(playerid,COLOR_RED,"STATUS: You left your car, FAIL!");
            return 1;
    }
    // Rest of Code here
    return 1;
}
I think that my code should work..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)