Driving Test & OnPlayerExitVehicle - 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: Driving Test & OnPlayerExitVehicle (
/showthread.php?tid=634471)
Driving Test & OnPlayerExitVehicle -
freddiebox - 19.05.2017
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(playerid, vehicleid)
{
if(PlayerInfo[playerid][pCarDrivingTest] < 1 || PlayerInfo[playerid][pTruckDrivingTest] < 1)
{
GetPlayerVehicleID(playerid);
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;
}
So how do I get it to know if the value is anywhere above 0?
Re: Driving Test & OnPlayerExitVehicle -
Aly - 19.05.2017
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;
}