Driving Test & OnPlayerExitVehicle
#1

Hello everyone,

I got a simple system I'm working on recognizing if a player is taking a driving license test and if the player leave the vehicle during the exam it should return the player to the DMV and cancel the test.

So far the returning the player to the DMV is working properly, but I'm trying to understand how to get it to know if the player is taking the test or not. Right now it kicks the player from any vehicle even if they are not doing a test.

PlayerInfo[playerid][pCarDrivingTest] gets updated when the player enters a checkpoint during the test. If the player is not taking a driving test it is per default at 0, but if a player is taking the test the value can be anywhere between 1-51 depending on how many checkpoints the driving exam got.

PHP код:
public OnPlayerExitVehicle(playeridvehicleid)
{
    if(
PlayerInfo[playerid][pCarDrivingTest] < || PlayerInfo[playerid][pTruckDrivingTest] < 1)
    {
         
GetPlayerVehicleID(playerid);
        
DestroyVehicle(vehicleid);
        
PlayerInfo[playerid][pDrivingTest] = 0;
DisablePlayerCheckpoint(playerid);
           
SetPlayerPos(playerid, -147.2725,1079.0540,19.7500);
         
SetPlayerFacingAngle(playerid88.3368);
          
SetPlayerInterior(playerid0);
          
SetCameraBehindPlayer(playerid);
        
SendClientMessage(playeridCOLOR_WHITE"{F0F8FF}You{F0F8FF} {FF6347}FAILED{FF6347} {F0F8FF}the driving test for abandoning the license vehicle.{F0F8FF}");
        return 
1;
    }
    return 
1;

So how do I get it to know if the value is anywhere above 0?
Reply
#2

You can use a global boolean variable
Код:
new bool:isTakingDrivingTest[MAX_PLAYERS];
Set it to false inside OnPlayerConnect
Код:
public OnPlayerConnect(playerid)
{
     isTakingDrivingTest[playerid] = false;
}
You can set it to true when the player starts the driving test
Код:
isTakingDrivingTest[playerid] = true;
Set it to false when the player ends the driving test or when he leaves the vehicle.
Код:
if(PlayerEndedTest)
	isTakingDrivingTest[playerid] = false;
And OnPlayerExitVehicle
Код:
public OnPlayerExitVehicle(playerid, vehicleid) 
{ 
    if(!isTakingDrivingTest[playerid]) //is the same as using: if(isTakingDrivingTest[playerid] == false)
    { 
        GetPlayerVehicleID(playerid); //This line should be deleted because you're not storing its result in any variable so is useless
        DestroyVehicle(vehicleid); 
        PlayerInfo[playerid][pDrivingTest] = 0; 
		DisablePlayerCheckpoint(playerid); 
        SetPlayerPos(playerid, -147.2725,1079.0540,19.7500); 
        SetPlayerFacingAngle(playerid, 88.3368); 
        SetPlayerInterior(playerid, 0); 
        SetCameraBehindPlayer(playerid); 
        SendClientMessage(playerid, COLOR_WHITE, "{F0F8FF}You{F0F8FF} {FF6347}FAILED{FF6347} {F0F8FF}the driving test for abandoning the license vehicle.{F0F8FF}"); 
        return 1; 
    } 
    return 1; 
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)