OnPlayerEnterVehicle being weird?
#1

EDIT: DON'T post alternatives such as OnPlayerStateUpdate, I'm not asking for that, if I wanted to do it with OPSU I would do it

so I'm trying to "update" my OnPlayerEnterVehicle with my "Speedometer" and Fuel, however I'm encountering REALLY strange problem

  • Entering Vehicle as a Driver
    • What Should Happen:
      1. Check if I can enter vehicle
      2. if no: Stop Function, SendClientMessage "0"
      3. else: Set pDriver to 1, Display Textdraws, Enters Vehicle, SendClientMessage "1"
    • What Happens:
      1. Check if I can enter vehicle
      2. if no: Stop Function, SendClientMessage "0"
      3. else: Enters Vehicle
  • Entering Vehicle as a Passenger
    • What Should Happen
      1. Display Textdraws
    • What Happens
      1. Display Textdraws


from this we can all clearly see that my code stops after this control statement "if" and even ELSE don't runs

pawn Код:
if(CanEnterVehicle(playerid, vehicleid) == 0) // runs
        {
            SendClientMessage(playerid, -1, "0"); // runs
            return 1; // runs
        }
        else
            SendClientMessage(playerid, -1, "1"); // NEVER and nothing else below this
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(ispassenger == 0)
    {
        if(CanEnterVehicle(playerid, vehicleid) == 0)
        {
            SendClientMessage(playerid, -1, "0");
            return 1;
        }
        else
            SendClientMessage(playerid, -1, "1");
        pDriver[playerid] = 1;
    }
    FuelTimer[playerid] = SetTimerEx("VehicleFuelUpdate", 15000, 1, "ii", playerid, vehicleid);
    TextDrawSetOutline(tSpeed[playerid], 1);
    TextDrawShowForPlayer(playerid, tSpeed[playerid]);
    new str[32];
    format(str, sizeof(str), "%d l", Fuel[vehicleid]);
    TextDrawSetString(tFuel[playerid], str);
    TextDrawSetOutline(tFuel[playerid], 1);
    TextDrawShowForPlayer(playerid, tFuel[playerid]);
    SpeedTimer[playerid] = SetTimerEx("VehicleUpdate", 400, 1, "ii", playerid, vehicleid);
    return 1;
}

CanEnterVehicle(playerid, vehicleid)
{
    if(LockedCar[vehicleid] == 1 && PlayerCar[playerid] == vehicleid) // "==" for testing purposes, ignore it, ty
    {
        TogglePlayerControllable(playerid, true);
        CustomShowTextDraw(playerid, TextDrawCreate(10.0, 250.0, "This Vehicle is Locked!"), 125, 5, 1);
        return 0;
    }
    for(new i = 0; i < strlen(AirVehicle); i++)
    {
        if(vehicleid == AirVehicle[i])
        {
            if(PilotLicence[playerid] == 0)
            {
                CustomShowTextDraw(playerid, TextDrawCreate(10.0, 250.0, "You can't pilot air vehicles without the Pilot Licence!"), 175, 5, 1);
                TogglePlayerControllable(playerid, true);
                return 0;
            }
        }
    }
    if(DriverLicence[playerid] == 0)
    {
        TogglePlayerControllable(playerid, true);
        CustomShowTextDraw(playerid, TextDrawCreate(10.0, 250.0, "You can't drive vehicles without the Driver Licence!"), 175, 5, 1);
        return 0;
    }
    return 1;
}
Reply
#2

try to add { after else and } after SendClientMessage
Reply
#3

Quote:
Originally Posted by IceMeteor
Посмотреть сообщение
try to add { after else and } after SendClientMessage
you're new in programming right?
Reply
#4

I still do recommend using OnPlayerStateChange, because a player can still abort the entering even after OnPlayerEnterVehicle is called. If this happens, you will end up with a bugged system.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
I still do recommend using OnPlayerStateChange, because a player can still abort the entering even after OnPlayerEnterVehicle is called. If this happens, you will end up with a bugged system.
I was "playing" with EnterVehicle and StateChange for like 1 hour until I managed to get it to work with EnterVehicle (I haven't sleep for like 20 hours now), but then I noticed that it will appear even when vehicle is locked :/ but here's another problem: I still need to check if vehicle is locked, and since nothing will run after that I have to use it at the end of EnterVehicle callback, but I have to use it at start since it's the first thing I have to do, so I have to fix "CanEnterVehicle" function somehow

edit: so I commented out everything except that function so I can test it and changed "== 0" to "== 1" so it should sendclientmessage 0 when I CAN enter vehicle

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(ispassenger == 0)
    {
        if(CanEnterVehicle(playerid, vehicleid) == 1)
        {
            SendClientMessage(playerid, -1, "0");
            //return 1;
        }
        else
            SendClientMessage(playerid, -1, "1");
        //pDriver[playerid] = 1;
    }
    /*FuelTimer[playerid] = SetTimerEx("VehicleFuelUpdate", 15000, 1, "ii", playerid, vehicleid);
    TextDrawSetOutline(tSpeed[playerid], 1);
    TextDrawShowForPlayer(playerid, tSpeed[playerid]);
    new str[32];
    format(str, sizeof(str), "%d l", Fuel[vehicleid]);
    TextDrawSetString(tFuel[playerid], str);
    TextDrawSetOutline(tFuel[playerid], 1);
    TextDrawShowForPlayer(playerid, tFuel[playerid]);
    SpeedTimer[playerid] = SetTimerEx("VehicleUpdate", 400, 1, "ii", playerid, vehicleid);*/

    return 1;
}
nothing happens -.-'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)