14.10.2016, 12:44
I was wondering...which is the best way to detect when a player has detached or attached to a trailer?
Of course while a player is driving a truck.
Of course while a player is driving a truck.
//under the includes:
new playerToTrailer[MAX_PLAYERS],missionTimer[MAX_PLAYERS];
//When you start the mission (when you attached the trailer):
missionTimer[playerid] = SetTimerEx("OnPlayerDoMission",1000,1,"i",playerid);
playerToTrailer[playerid] = 10;//10 seconds to attach the trailer again
//the callback:
forward OnPlayerDoMission(playerid);
public OnPlayerDoMission(playerid)
{
new veh = GetPlayerVehicleID(playerid);
if(!IsTrailerAttachedToVehicle(veh))
{
playerToTrailer[playerid] --;
if(playerToTrailer[playerid] == 0)
{
KillTimer(missionTimer[playerid]);
SendClientMessage(playerid,-1,"Your mission is deleted! You lose the trailer");
return 1;
}
new string[145];
format(string,sizeof string,"You have only %d seconds to attach the trailer again!",playerToTrailer[playerid]);
SendClientMessage(playerid,-1,string);
return 1;
}
else
{
playerToTrailer[playerid] = 10;
}
return 1;
}
//when you finish the Mission correct:
KillTimer(missionTimer[playerid]);