Jump to content
Fiddi

[RELEASE] Light advanced vehicle respawn

Recommended Posts

Light advanced vehicle respawn

 

I present to you the vehicle respawn that will change your life (probably not..), it has the capabilities to save much of the customization available in the Eden editor and apply it on respawn. You simply set up your vehicle how you want it in the editor and this applies whatever settings you want. I've made it as light as I can, it should not affect performance noticably (though with hundreds of respawnable vehicles, it could)

Multiplayer and singleplayer:

Spoiler

maxresdefault.jpg

 

Features:

Init Support

Respawn Delay

Custom Loadout/Inventory

Custom Paints

Custom Parts

Respawn Limit

Wreck Disposal

Minimal Performance Impact

 

 

 

Installation and setup:

So, onto the logistics.

 

1. Download the script in question:

Download Here!

(Included an example mission that have it set up ingame)

2. Copy over files to you mission:

Simply grab the "VehicleRespawn" folder from the archive (inside Example.VR) and place it in your mission folder.

3. Setting up to load ingame:

In your description.ext (if you don't have one, create it) add this:

class CfgFunctions {
	#include "VehicleRespawn\CfgFunctions.hpp"
};

4. Choosing which vehicles to respawn:

In the Init-field of the vehicle(s) you want to respawn put this:

[this] call FRED_fnc_vehicleRespawn;

This will respawn you vehicle when destroyed with default settings (details below).

Now you have a vehicle that will respawn when destroyed.

 

 

Additional customization:

There are options you can customize and disable at your leisure


	Parameters:
		0 : OBJECT (REQUIRED)
				- Vehicle to be monitored for respawn.
		1 : NUMBER (OPTIONAL)
				- Respawn delay in seconds. +-5-10 seconds.
					(Default: 5)
		2 : CODE (OPTIONAL)
				- Initialization for vehicle. (To call vehicle use: _this)
		3 : NUMBER (OPTIONAL)
				- Respawn Limit. Number of lives a vehicle has. Unlimited by default.
					(Default: -1)
		4 : BOOLEAN (OPTIONAL)
				- Deletes wreck on respawn. Wrecks within 
				100m of respawn point is automatically deleted, regardless of setting.
					(Default: false)
		5 : BOOLEAN (OPTIONAL)
				- Use Custom Loadout. Saves inventory and loads it on respawn. 
					(Default: true)
		6 : BOOLEAN (OPTIONAL)
				- Custom Paintjob. Saves the current paint on the vehicle and applies it on respawn. 
					(Default: true)
	
	Example:
		[this, 5, {_this allowDamage false;}, false] call FRED_fnc_vehicleRespawn;

 

There's also an option to quit respawn for a vehicle if the situation requires it. Simply execute this code on the vehicle:

Vehicle setVariable ["VRStop", true];

 

You can add vehicles for the function to respawn when the mission is already running.

 

 

If you have questions or feedback, by all means ask and tell.

 

Thanks!

 

Version History:

Spoiler

Version 1.0.1 -

     Fixed issue with missionNamespace variable.

     Small readability tweaks.

     Switched to uiSleep instead of Sleep.

 

Version 1.0 - Initial Release.

 

 

 

Spoiler

This is my first release so:

66437042.jpg

 

 

  • Like 8

Share this post


Link to post
Share on other sites

It looks nice and lightweight!  I personally use the killed event handler to trigger the respawn countdown, but this looks like a neat way of doing it too!

Share this post


Link to post
Share on other sites
4 minutes ago, wyattwic said:

It looks nice and lightweight!  I personally use the killed event handler to trigger the respawn countdown, but this looks like a neat way of doing it too!

 

The reason I didn't use the "Killed" eventhandler is because, last I checked, it didn't detect if a vehicle was destroyed by water, therefore didn't respawn the vehicle.

 

Also I sometimes accidentally remove vehicles with zeus when cleaning up stuff and this respawns it regardless, hence the extra feature of stopping the respawn.

 

Anyway, thanks for the kind words!

  • Like 1

Share this post


Link to post
Share on other sites
2 minutes ago, Fiddi said:

The reason I didn't use the "Killed" eventhandler is because, last I checked, it didn't detect if a vehicle was destroyed by water, therefore didn't respawn the vehicle.

Neato, I didn't think water killed the vehicles. I thought it just made them inoperative.  I need to test that now.

Share this post


Link to post
Share on other sites
6 minutes ago, Fiddi said:

The reason I didn't use the "Killed" eventhandler is because, last I checked, it didn't detect if a vehicle was destroyed by water, therefore didn't respawn the vehicle.

So, I just did a quick test.

 

Crashing a helicopter into water kills it via the impact.  If there is no serious impact because you "landed it" into the water, the engine is all that sustains damage.

Driving a hunter into the water only damages the engine as well.

 

I think the easy way of checking if its downed is to see if its pos is below 0, or get the damage hitpart for the engine.

 

Oh well, good luck :)

Share this post


Link to post
Share on other sites
22 minutes ago, wyattwic said:

So, I just did a quick test.

 

Crashing a helicopter into water kills it via the impact.  If there is no serious impact because you "landed it" into the water, the engine is all that sustains damage.

Driving a hunter into the water only damages the engine as well.

 

I think the easy way of checking if its downed is to see if its pos is below 0, or get the damage hitpart for the engine.

 

Oh well, good luck :)

 

That would mean I need the loop anyways.

 

And did you wait until the helicopter landed on the bottom of the sea? That's when the model change to wreck but the eventhandler doesn't fire.

Share this post


Link to post
Share on other sites
Just now, Fiddi said:

 

That would mean I need the loop anyways.

 

And did you wait until the helicopter landed on the bottom of the sea? That's when the model change to wreck but the eventhandler doesn't fire.

I landed in water just deep enough to submerge everything, maybe 5 meters deep, in a MH9.   It didnt transition into a wreck.

 

Im off for now, but ill try it later tonight.

 

Share this post


Link to post
Share on other sites

@Fiddi Not a bad little script, although if you're looking to improve it, i recommend using uiSleep instead of sleep (uiSleep goes off of real time, sleep goes off of in-game time, and if the server is running at 1-5 FPS, it could be a long time) and, I like that you used params, and count. and also, you probably don't need to ASLToAGL [0,0,100], just create it at [0,0,0] the vehicle will get teleported fast enough anyways, because every script command halts the script engine until the command is done. less commands, the better. and as for this clump of mess:

_delay = _vehicleData select 0;
_init = _vehicleData select 1;
_loadout = _vehicleData select 2;
_name = _vehicleData select 3;
_position = _vehicleData select 4;
_direction = _vehicleData select 5;
_type = _vehicleData select 6;
_inventory = _vehicleData select 7;
_savePaint = _vehicleData select 8;
_paint = _vehicleData select 9;
_parts = _vehicleData select 10;
_deleteWreck = _vehicleData select 11;
_limitEnabled = _vehicleData select 12;

throw it in a params

_vehicleData params [
  "_delay",
  "_init",
  "_loadout",
  "_name",
  "_position",
  "_direction",
  "_type",
  "_inventory",
  "_savePaint",
  "_paint",
  "_parts",
  "_deleteWreck",
  "_limitEnabled"
];
if (isNil "_delay") exitWith { false };

the exitWith is a just-incase factor. 

Share this post


Link to post
Share on other sites
8 minutes ago, stokesgamingmc said:

*SNIP*

 

Thanks for the advice.

I can't believe I didn't think of params when writing that, I looked at it many times and thought that it must be a better way to do it, and there it was!

 

As for the ASLToAGL, when testing in multiplayer sometimes there were inconsistent results with vehicles being water-damaged when spawning and the engine wouldn't start (even after setDamage 0). Since I added that it hasn't happened, neither for client or host.

Share this post


Link to post
Share on other sites
Just now, Fiddi said:

 

Thanks for the advice.

I can't believe I didn't think of params when writing that, I looked at it many times and thought that it must be a better way to do it, and there it was!

 

As for the ASLToAGL, when testing in multiplayer sometimes there were inconsistent results with vehicles being water-damaged when spawning and the engine wouldn't start (even after setDamage 0). Since I added that it hasn't happened, neither for client or host.

huh, it could be because you've scheduled it, execution time can generally go from 0.01~ MS to 5ms after scheduling it.

Share this post


Link to post
Share on other sites

Updated!

 

Version 1.0.1 -

     Fixed issue with missionNamespace variable.

     Small readability tweaks.

     Switched to uiSleep instead of Sleep.

Share this post


Link to post
Share on other sites
6 minutes ago, Fiddi said:

Updated!

 

Version 1.0.1 -

     Fixed issue with missionNamespace variable.

     Small readability tweaks.

     Switched to uiSleep instead of Sleep.

:D

 

// edit, @Fiddi you only changed one sleep to uiSleep 

!((_x select 0) isEqualType "")

Share this post


Link to post
Share on other sites

great stuff :)

 

will benefit communities and scenario designers with a number of respawning vehicles who dont want lots of unnecessary scripts running (which is the case with normal vehicle respawn modules).

 

few small suggestions:

 

- tag all your global variables

- use setVectorUpAndDir instead of setDir (allows people to have vehicles respawn on slopes and uneven terrain without issue).

- maybe randomize slightly your spawn position [0,0,100], i can see some issues with simulation enabled vehicles being there at roughly the same time. something like [random -100,random -100,(100 + (random 100))]

- handling vehicle abandonment

 

 

As you say, we cannot yet use a purely event-handler based respawn system due to the underwater bug ... we do have a new Deleted event handler coming (1.68) but still doesn't cover the underwater vics, and also doesn't handle abandonment so a thread is required anyways.

Share this post


Link to post
Share on other sites
10 hours ago, stokesgamingmc said:

:D

 

// edit, @Fiddi you only changed one sleep to uiSleep 

!((_x select 0) isEqualType "")

 

IsEqualType! Great, I missed that one!

 

I figured that uiSleep might not be the best option everywhere, since it goes on regardless of other mission activity, and the sleep regulates (a small bit) when code should be executed in respect to the performance load. Besides, if a server is running 1-5 fps, it has bigger problems than exact respawn delays. Thanks anyway for the feedback, I'll test some variations just to be sure and see how it works!

 

4 hours ago, fn_Quiksilver said:

- tag all your global variables

- use setVectorUpAndDir instead of setDir (allows people to have vehicles respawn on slopes and uneven terrain without issue).

- maybe randomize slightly your spawn position [0,0,100], i can see some issues with simulation enabled vehicles being there at roughly the same time. something like [random -100,random -100,(100 + (random 100))]

- handling vehicle abandonment

 

Thanks!

The first three I can do easily, the last is a bit tricky.

I've played around with it some, but couldn't find a way that suited both the usability and the performance requirement. For example, if all players are x meters away how long till the vehicle is considered abandoned? The timer must be restarted every time a player enters the radius since otherwise a vehicle could disappear right when you're approaching it, which would be infuriating. And what if you have AI teammates that could use a ride home when you're dead? You have to detect them too. There's a number of factors to weigh in. Also to couple this with when the vehicle is destroyed.

It can most certainly be done but I think not without making another loop which would effectively make this a lot heavier than it now is, but I'll see what I can do.

 

Personally, when I play we always have Zeus so it's easy to pop in there and make the vehicle respawn that way, which in my opinion is the most convenient option (though "immersion" breaking).

 

Speaking of immersion, would be cool if the respawn event would be that a helicopter comes with the vehicle airlifted and drops it where it should be. Could be neat. Disclaimer: NOT PLANNED! :D

 

  • Like 1

Share this post


Link to post
Share on other sites

At worst you can just have abandonment as an optional system, protected by a global var. 

 

I wouldn't use a vehicle respawn system which doesnt have abandonment management. Yes its not free performance-wise, will cost some CPU time to evaluate abandonment, but a vehicle to me is as pretty much gone if no one can find it :)

 

for abandonment this is a handy new engine function https://community.bistudio.com/wiki/inAreaArray

 

I usually set abandonment around 500m-1000m, if no players in that radius then either delete or reset

Share this post


Link to post
Share on other sites
17 minutes ago, fn_Quiksilver said:

At worst you can just have abandonment as an optional system, protected by a global var. 

 

I wouldn't use a vehicle respawn system which doesnt have abandonment management. Yes its not free performance-wise, will cost some CPU time to evaluate abandonment, but a vehicle to me is as pretty much gone if no one can find it :)

 

for abandonment this is a handy new engine function https://community.bistudio.com/wiki/inAreaArray

 

I usually set abandonment around 500m-1000m, if no players in that radius then either delete or reset

 

I will look into it! As you said it would have to be optional and be chosen on a vehicle to vehicle basis, with the radius customizable of course.

  • Like 1

Share this post


Link to post
Share on other sites
13 hours ago, Fiddi said:

 

IsEqualType! Great, I missed that one!

 

I figured that uiSleep might not be the best option everywhere, since it goes on regardless of other mission activity, and the sleep regulates (a small bit) when code should be executed in respect to the performance load. Besides, if a server is running 1-5 fps, it has bigger problems than exact respawn delays. Thanks anyway for the feedback, I'll test some variations just to be sure and see how it works!

 

Usually if you have 60+ players, the server FPS can tank a lot. even with just a vanilla arma server. but if 1-5 FPS is the case, you may have to wait an extra 30 minutes just for a vehicle to appear :P A FSM is probably a better option, that way you can remove a lot of overhead from the scripting Engine, and put it all in a "separate engine", keep in mind, if a FSM is not built correctly, it can

  1. not work at all.
  2. crash arma
  3. kill fps
  4. cause memory leaks

Share this post


Link to post
Share on other sites

So sorry guys, but I honestly can't get my head around all the scripting ever since Op Flashpoint... I just suck at it...

 

On 2/10/2017 at 6:34 PM, Fiddi said:

Additional customization:

There are options you can customize and disable at your leisure



	Parameters:
		0 : OBJECT (REQUIRED)
				- Vehicle to be monitored for respawn.
		1 : NUMBER (OPTIONAL)
				- Respawn delay in seconds. +-5-10 seconds.
					(Default: 5)
		2 : CODE (OPTIONAL)
				- Initialization for vehicle. (To call vehicle use: _this)
		3 : NUMBER (OPTIONAL)
				- Respawn Limit. Number of lives a vehicle has. Unlimited by default.
					(Default: -1)
		4 : BOOLEAN (OPTIONAL)
				- Deletes wreck on respawn. Wrecks within 
				100m of respawn point is automatically deleted, regardless of setting.
					(Default: false)
		5 : BOOLEAN (OPTIONAL)
				- Use Custom Loadout. Saves inventory and loads it on respawn. 
					(Default: true)
		6 : BOOLEAN (OPTIONAL)
				- Custom Paintjob. Saves the current paint on the vehicle and applies it on respawn. 
					(Default: true)
	
	Example:
		[this, 5, {_this allowDamage false;}, false] call FRED_fnc_vehicleRespawn;

 

 

Need some help with the example: [this, 5, {_this allowDamage false;}, false] call FRED_fnc_vehicleRespawn;

 

how do you actually enable/disable the additional options?

Share this post


Link to post
Share on other sites

I am somewhat confused as to how it works but in my init line on my vehicle I have

 

[this, 20, false, true, true] call FRED_fnc_vehicleRespawn;

 

This gives me a 20 second delay if it gets destroyed and the true,true part gives me the same loadout and paintjob on respawn.

Share this post


Link to post
Share on other sites

Still works. Throws errors about the paint but I think it has something to do with that apc having so many different paint jobs in game. Maybe not who knows. Took out this   if _savePaint then {[_newVehicle, _paint, _parts] call BIS_fnc_initVehicle};  from fn_vehicleMonitor.sqf  and used this in vehicle init  [this, 5, {_this allowDamage true;}, 1] call FRED_fnc_vehicleRespawn; and it went away.

 

I am probably putting the wrong thing in the vehicle init or something. I cannot limit number of respawns. The fact that the ammo loadout comes back just like it was every time, thats all I ever wanted really. After it respawns 2 or 3 times times the loadout goes to default. If I put allowdamage false after the 2nd or third respawn it becomes invincible.

 

[this, 15, {_this allowDamage true;}, 5]   I put that in, after 5 I get default loadout but it still respawns

Share this post


Link to post
Share on other sites

Using pierremgi's vehicle respawn module, if you tick keep the appearance and pylons the loadout is restored to original. I thought keep actions and arsenal would do that but it does not.

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

×