#define Trucker_TimeToFailMission "Enter your vehicle or re-attch your trailer 30"
Код:
Trucker_StartRandomJob(playerid)
{
// Check if a job could be set correctly (player must be driving a valid trucking vehicle)
if (Trucker_SetRandomJob(playerid) != 0)
{
// Setup local variables
new StartLoc[50], EndLoc[50], Load[50], RouteText[255], Float:x, Float:y, Float:z, LoadMsg[128];
// Job has started
APlayerData[playerid][JobStarted] = true;
// Set jobstep to 1 (going to load the goods)
APlayerData[playerid][JobStep] = 1;
// Get the startlocation, endlocation and the load texts
format(StartLoc, 50, ALocations[APlayerData[playerid][JobLoc1]][LocationName]);
format(EndLoc, 50, ALocations[APlayerData[playerid][JobLoc2]][LocationName]);
format(Load, 50, ALoads[APlayerData[playerid][LoadID]][LoadName]);
// Combine it all into a string for the TextDraw (the player can see this all the time) to describe the mission
format(RouteText, 255, TXT_HaulingCargoFromToPickup, Load, StartLoc, EndLoc);
// Set the TextDraw so the player can see it
TextDrawSetString(APlayerData[playerid][MissionText], RouteText);
// Grab the x, y, z positions for the first location
x = ALocations[APlayerData[playerid][JobLoc1]][LocX];
y = ALocations[APlayerData[playerid][JobLoc1]][LocY];
z = ALocations[APlayerData[playerid][JobLoc1]][LocZ];
// Create a checkpoint where the player should load the goods
SetPlayerCheckpoint(playerid, x, y, z, 7);
// Set the job-fail-time for the global vehicle-timer
APlayerData[playerid][VehicleTimerTime] = Trucker_TimeToFailMission;
// Inform the player that he must load his goods
format(LoadMsg, 128, TXT_PickupCargoAt, Load, StartLoc);
SendClientMessage(playerid, 0xFFFFFFFF, LoadMsg);
}
return 1;
}
Код:
forward GlobalTimer();
public GlobalTimer()
{
// Setup local variables
new OldVehicleID, NewVehicleID, OldTrailerID, NewTrailerID;
// Loop through all players
for (new playerid; playerid < MAX_PLAYERS; playerid++)
{
// Check if this player is logged in
if (APlayerData[playerid][LoggedIn] == true)
{
// Get the vehicle-id's from this player
OldVehicleID = APlayerData[playerid][VehicleID];
NewVehicleID = GetPlayerVehicleID(playerid);
OldTrailerID = APlayerData[playerid][TrailerID];
NewTrailerID = GetVehicleTrailer(GetPlayerVehicleID(playerid));
// Check the class of the player
switch (APlayerData[playerid][PlayerClass])
{
case Trucker:
{
// Check if the trucker has a job
if (APlayerData[playerid][JobStarted] == true)
{
// Check if the vehicletimer didn't run out yet
if (APlayerData[playerid][VehicleTimerTime] != 0)
{
// If VehicleID and TrailerID are still the same as when the player accepted the job
if ((OldVehicleID == NewVehicleID) && (OldTrailerID == NewTrailerID))
APlayerData[playerid][VehicleTimerTime] = Trucker_TimeToFailMission; // Reset the time before the mission fails
else // One (or both) aren't still the same (player lost his trailer or vehicle)
PlayerLeftVehicle(playerid); // Inform the player that he left his vehicle and that he must re-enter it
}
else // Time left has reached 0
FailJob(playerid);
}
}
case BusDriver:
{
// Check if the busdriver has a job
if (APlayerData[playerid][JobStarted] == true)
{
if (APlayerData[playerid][VehicleTimerTime] != 0)
{
// If VehicleID is still the same as when the player accepted the job
if (OldVehicleID == NewVehicleID)
APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission; // Reset the time before the mission fails
else // Player got out of his bus
PlayerLeftVehicle(playerid); // Inform the player that he left his vehicle and that he must re-enter it
}
else // Time left has reached 0
FailJob(playerid);
}
}
case Courier:
{
// Check if the courier has a job
if (APlayerData[playerid][JobStarted] == true)
{
if (APlayerData[playerid][VehicleTimerTime] != 0)
{
// If VehicleID and TrailerID are still the same as when the player accepted the job
if (OldVehicleID == NewVehicleID)
APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission; // Reset the time before the mission fails
else // Player stepped out of his vehicle
PlayerLeftVehicle(playerid); // Inform the player that he left his vehicle and that he must re-enter it
}
else // Time left has reached 0
FailJob(playerid);
}
}
case RoadWorker:
{
// Check if the roadworker has a job
if (APlayerData[playerid][JobStarted] == true)
{
// Check if the vehicletimer didn't run out yet
if (APlayerData[playerid][VehicleTimerTime] != 0)
{
// If VehicleID and TrailerID are still the same as when the player accepted the job
// In case of the "tow broken vehicle" jobtype, the mission starts without a trailer (so it's 0),
// but gets updated when the player enters the checkpoint to set the broken vehicle as trailer
if ((OldVehicleID == NewVehicleID) && (OldTrailerID == NewTrailerID))
APlayerData[playerid][VehicleTimerTime] = Job_TimeToFailMission; // Reset the time before the mission fails
else // VehicleID isn't still the same (player lost his vehicle or trailer)
PlayerLeftVehicle(playerid); // Inform the player that he left his vehicle and that he must re-enter it
}
else // Time left has reached 0
FailJob(playerid);
}
}
}
}
}
return 1;
}