Jump to content

Recommended Posts


through trial and testing I've arrived to the following format for a vehicle respawn functionality.

addMissionEventHandler ["EntityKilled", {
	params ["_killed", "_killer", "_instigator"];

	[_killed] spawn {
	switch (true) do {
	case (!alive vehCivSUV_1): {deleteVehicle vehCivSUV_1; _newVehicle2 = "C_SUV_01_F" createVehicle [1263,1298,0]; _newVehicle2 setVehicleVarName "vehCivSUV_1"; vehCivSUV_1 = _newVehicle2; publicVariable "vehCivSUV_1";};
	sleep 2;
	case (!alive vehCivSUV_2): {deleteVehicle vehCivSUV_2; _newVehicle = "C_SUV_01_F" createVehicle [1232,1298,0]; _newVehicle setVehicleVarName "vehCivSUV_2"; vehCivSUV_2 = _newVehicle; publicVariable "vehCivSUV_2";};

While testing has proven that it works decently enough in a dedicated server there's still at least one edge-case scenario that I'd like to iron out.
The edge-case is that should the two vehicles mentioned in the event handlers code be destroyed exactly at the same time the functionality does not work as expected. Should the demise of both vehicles happen at the same time the other vehicle won't be created at all (and the other that gets created will have a duplicate vehicle spawned next to it).
So while what I have now works to some degree there should be some changes made to make the functionality more robust. Maybe the switch-do is not the best solution but I have only just arrived to that and don't have off the top of my head any other solution to try.

So question for this is that: what would be a more robust way to achieve what I have now and do away with the edge-case scenario at the same time?


Another thing would be that the functionality should, if possible, incorporate at least two more vehicles in it.


edit: while I know that there's a respawn module available in the editor that can't be used for "reasons"

Share this post

Link to post
Share on other sites

This is what I would try:

addMissionEventHandler ["EntityKilled",{
    params ["_killed","_killer","_instigator"];
    _vehicles = [vehCivSUV_1,vehCivSUV_2];// Add the names of the vehicles which should respawn
    if !(_killed in _vehicles) exitWith {};// Don't run if no relevant vehicle was destroyed
    _var = vehicleVarName _killed;// get the name of the car
    _type = typeOf _killed;// "C_SUV_01_F" or whatever type of vehicle the previous one was
    deleteVehicle _killed;
    _newVeh = _type createVehicle [1263,1298,0];// Only works if there is only one respawn position
    _newVeh setVehicleVarName _var;// Set the name of the object (NOT THE SAME AS "mySUV = _newVeh;")
    missionNamespace setVariable [_var,_newVeh,true];// Now the variable also references the actual object (MP and JIP)

I kept it as simple as possible but this limits the amount of respawn positions to only one. Therefore not sure if both cars blow up when getting destroyed and respawned at the same time.

  • Like 1

Share this post

Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now