PDA

View Full Version : When the vehicle is destroyed Mission ends


cloudysky
12/06/2017, 03:44 PM
Hello,

I'm currently making a mission for ambulance where the crew load up supplies into it before taking it back to base.

However, I don't know how to get it so if the ambulance is destroyed (and the players survive) the mission ends and checkpoints are removed.

I've had a look at the OnVehicleDeath function but I don't want it to end everytime an ambulance is destroyed, only when it has been loaded up.

Thanks

FailerZ
12/06/2017, 03:58 PM
If I understand:
You need to make a variable like
//On top
new bool:IsAmbLoaded[MAX_VEHICLES];
Once you load the ambulance in your script set it to true with
IsAmbLoaded[vehicleid] = true; //The vehicleid is the ambulance
and do the check onvehicledeath like
public OnVehicleDeath(vehicleid, killerid)
{
if(GetVehicleModel(vehicleid) == 416 && IsAmbLoaded[vehicleid] == true)
{
//Mission failed
IsAmbLoaded[vehicleid] = false; //Don't forget to reset the var to false after the mission end
}
}

Vince
12/06/2017, 04:08 PM
The best way to approach this depends on a lot of factors: whether a mission involves one player or multiple players, whether there is just one ambulance, a predetermined number of ambulances or an indeterminate number of ambulances and whether each crew manages exactly one ambulance.

I would probably create an enum structure somewhat similar to:

#define MAX_AMBULANCE_CREW (4)

enum AmbulanceMission
{
ambulanceId, // contains vehicleid of ambulance
crewIds[MAX_AMBULANCE_CREW], // contains crew members playerids
loaded
}

new gMissionInstances[5][AmbulanceMission]; // 5 being the maximum number of missions that can be started simultaneously


public OnVehicleDeath(vehicleid, killerid)
{
for(new i; i < sizeof gMissionInstances; i++)
{
if(gMissionInstance[i][ambulanceId] == vehicleid)
{
TriggerAmbulanceMissionFailed(i); // trigger a function that says instance "i" failed
break;
}
}
}


TriggerAmbulanceMissionFailed(instance)
{
for(new i; i < MAX_AMBULANCE_CREW; i++)
{
GameTextForPlayer(gMissionInstances[instance][crewIds][i], "~r~Mission Failed", 9000, 0);
}
}

cloudysky
12/06/2017, 04:49 PM
Hi thanks for the replies,

Only the driver can use the command to start the mission. The command can be used in any ambulance on the server.

I'll have a read through it all and make sure I understand it.

Thanks again.