SA-MP Forums Archive
When the vehicle is destroyed Mission ends - 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: When the vehicle is destroyed Mission ends (/showthread.php?tid=635723)



When the vehicle is destroyed Mission ends - cloudysky - 12.06.2017

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


Re: When the vehicle is destroyed Mission ends - FailerZ - 12.06.2017

If I understand:
You need to make a variable like
PHP код:
//On top
new bool:IsAmbLoaded[MAX_VEHICLES]; 
Once you load the ambulance in your script set it to true with
PHP код:
IsAmbLoaded[vehicleid] = true//The vehicleid is the ambulance 
and do the check onvehicledeath like
PHP код:
public OnVehicleDeath(vehicleidkillerid

    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 
    





Re: When the vehicle is destroyed Mission ends - Vince - 12.06.2017

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:
PHP код:
#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 
PHP код:
public OnVehicleDeath(vehicleidkillerid)
{
    for(new 
isizeof gMissionInstancesi++)
    {
        if(
gMissionInstance[i][ambulanceId] == vehicleid)
        {
            
TriggerAmbulanceMissionFailed(i); // trigger a function that says instance "i" failed
            
break;
        }
    }

PHP код:
TriggerAmbulanceMissionFailed(instance)
{
    for(new 
iMAX_AMBULANCE_CREWi++)
    {
        
GameTextForPlayer(gMissionInstances[instance][crewIds][i], "~r~Mission Failed"90000);
    }




Re: When the vehicle is destroyed Mission ends - cloudysky - 12.06.2017

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.