Jump to content
daskunk

Vehicle Respawn Module

Recommended Posts

As an aside the module says it passes [oldveh, newveh] to anything run in the expression field,

Does not say that in my editor.

And its definately new, old in the script

BIS_fnc_moduleRespawnVehicle line 426

			_initScript = if (typeName _init == typeName []) then
			{
				([_newVeh,_veh]+(_init select 1)) spawn (_init select 0);
			}
			else
			{
				[_newVeh,_veh] spawn _init;
			};
			[missionnamespace,"respawn",[_newVeh,_veh]] spawn bis_fnc_callscriptedeventhandler;

but I've always got nul from the 2nd element by the time it gets to the called script.

Yep the next statements is the deletion of the vehicle, the only thing it waits for (as long as its not respawning on the same spot) is the new vehicle init to finish. Of which the init is spawned so as long as there is some hold up there the old veh should not be null.

waituntil {scriptdone _initScript};

Share this post


Link to post
Share on other sites

Does not say that in my editor.

 

 

 

 

You're right. My mistake :)

Share this post


Link to post
Share on other sites

Is there any way to disable the module that has been initialized like this once a trigger is activated to stop the vehicle from respawning anymore?

Share this post


Link to post
Share on other sites

Is there any way to disable the module that has been initialized like this once a trigger is activated to stop the vehicle from respawning anymore?

Untried, but I assume that synchroinzeObjectsRemove can be use to break the sync between the object and the module.

Share this post


Link to post
Share on other sites

Ok, please excuse my noobiness but I have a few questions about this.

 

I have a trigger in the editor with a condition, and in the on activation field it simply calls the following script to spawn a vehicle

_pos = getMarkerPos "mkr_alpha_west_car_1";
_veh = "B_MRAP_01_hmg_F" createVehicle _pos;
[_veh,10,-1,-1,<code>,0,1,1,true] call BIS_fnc_moduleRespawnVehicle;

This seems to work perfectly fine but I have a few questions:

 

1- What do I put in for <code> if I don't want anything executed. I've tried "null" and "[]". Both don't seem to cause any issues (The vehicle respawns fine) but the debugger complains, and I don't like complaints!

2- If I want to spawn more than one vehicle, how do I attach them all to the same module like I could in the editor?

3- Without a reference to the module, how can I disable it if I want the vehicles to stop respawning once another trigger condition is met?

Share this post


Link to post
Share on other sites

1. {}

2. As discussed in #24, synchronising a vehicle to the module does not do much other than for a couple of the options, in which case you would need to name the module to be able to synchronise new vehicles to it.

The main point is that the vehicle is passed to the function with settings to enable respawning.

3. No need for a reference to the module, just call

[_veh, true] call BIS_fnc_moduleRespawnVehicle
It will remove the eventhandlers placed on the vehicle and exit.

Share this post


Link to post
Share on other sites

Man I've been racking my brain trying to figure this out and I really don't see why this is so hard. I guess I just don't really understand what a module actually is under the hood.

I'd really appreciate some help.

 

This is what I want:

1- Sector starts out neutral and is devoid of any vehicles.

2- One side captures the sector and are awarded a set of vehicles at that area as well as a new respawn position.

3- These vehicles respawn at their starting positions as long as the team maintains control of that sector.

4- These vehicles should also be respawn positions for infantry.

5- The vehicles cease to respawn once ownership of the sector switches to the other side, and that other sides' set of vehicles spawn with the same above conditions.

 

This is what I have:

1- A working sector control mechanism, that gets captured correctly

2- Triggers that correctly activate a new respawn position only for the side that owns the sector

3- The same triggers call the following code (as well as other things, but this is the one that's relevant)

remoteExec ["CBR_fnc_spawnvehicles_west"]

4- I have a fn_spawnvehicles_west.sqf function in my mission folder with the following contents

_pos = getMarkerPos "mkr_alpha_west_car_1";
_veh = "B_MRAP_01_hmg_F" createVehicle _pos;
[_veh,10,-1,-1,[{},[]],0,1,1,true] call BIS_fnc_moduleRespawnVehicle;
sleep 30;
[_veh, true] call BIS_fnc_moduleRespawnVehicle;
hint "NO MORE RESPAWNS"

(I'm using a sleep 30, instead of the condition of ownership change, so I can test the module without having to switch sides then recapture the sector)

This spawns the vehicle fine and the vehicle respawns after 10 seconds of being destroyed fine, but after 30 seconds I get the hint as I should but the vehicle continues to respawn, so I'm not really sure how to fix this.

I also want the vehicle to be an infantry respawn position that they can select in the respawn menu, but the wiki has no information on how to use BIS_fnc_moduleRespawnPosition :/

 

Is there a better way to accomplish what I want? I mean I imagined there'd be a way I could just place the modules with the settings I want in the editor, and simply sync newly spawned vehicles to it using code to "draw the imaginary sync line". The modules work perfectly fine when I do everything in the editor, but I don't want the vehicles to exist yet.

Share this post


Link to post
Share on other sites

Also, for some reason I cannot fathom, the code is spawning 4 vehicles when I run this on a dedicated server :(

Share this post


Link to post
Share on other sites

Heres a TEST MISSION

Spent ages trying to track down why respawn positions no longer show when running a mission from a dedicated server. Show ok in the menuPosition dialog but dont show on the map.

Respawn modules are run non globally but BI have forgotten to run the marker script on clients.

true remoteExec [ "BIS_fnc_drawRespawnPositions", 0 ];
from the server is a quick fix to get them to show.
  • Like 1

Share this post


Link to post
Share on other sites

That draws them on client map? Excellent!

Share this post


Link to post
Share on other sites

This worked wonderfully! Thanks larrow!

 

I do just have one last simple question about this. How do you know the names of the variables for the modules when using getVariable/setVariable?

 

Like in

_delay = (_respawnModule getVariable ["Delay","0"]) call BIS_fnc_parsenumber;

How do you know that "Delay" is a variable in the respawn module?

Share this post


Link to post
Share on other sites

How do you know that "Delay" is a variable in the respawn module?

Me personally, by unpacking the Arma PBO's and reading through BI's scripts, which I've likely spent just as much time doing that as writing my own.

If you look at the scripts for the vehicleRespawn you will see that block of variables is a direct copy from there.

You can also use allVariables command from the debugConsole, although this can show a host of other variables but you can usually take a stab at what is what.

Place down a module and give it a name.

Fill out all the options in the module.

Preview the mission and open the debugConsole and in a watch line type..

allVariables nameGivenToModule
Then in another line type..

nameGivenToModule getvariable ["theVariableToCheck","nothing"]
Where theVariableToCheck is a name shown from the results of the first line and will display 'nothing' if its currently Nil.

Another option is to look at the module in the config viewer and find its 'function' property and then find that function in the functionViewer to read through what it reads off of the module and what it does.

For example place a module vehicleRespawn and rightClick it and select 'Find in config viewer'.

Find its 'function' property - function = "BIS_fnc_moduleRespawnVehicle";

Then open the functionsViewer and select the option 'configfile' 'All' and 'All' and find moduleRespawnVehicle (the function name minus BIS_fnc_) and read what the module does code wise.

The functionsViewer can be a little hard on the eyes being just black on white and the tab spacing a little short but you can always copy and paste into your favourite editor for syntax highlighting.

When tracking down exactly how modules work you may also want to read through the scripts under configViewer > 'configfile', 'A3', 'Modules' along with the module framework on the wiki as guide to the possible options available. Flow/entrypoint is initFunctions.sqf -> bis_fnc_initModules and Module_F init EH bis_fnc_moduleInit.

Share this post


Link to post
Share on other sites

Larrow is the Sherlock of SQF. :)

 

I wonder if anyone can recreate this problem I'm having with the VRM?

 

In the expression field, I have an execVM to an assetrespawn script that attaches the respawning vehicle to a parachute under an aircraft so it can be dropped in, you get the idea.

 

This works faultlessly most of the time, but yesterday, the vehicle was destroyed while it had a player driver. The expression field was never actioned and the RPT showed nothing of interest. I know the assetrespawn didn't run because it has diag_log debug right at it's top. I'm assuming this is due to a locality problem, but more than that, I don't know. Any ideas?

 

Thanks, Tanky -Paul-

Share this post


Link to post
Share on other sites

the vehicle was destroyed while it had a player driver.

Can you reliably repeat this, in that it does not work if the vehicle is destroyed whilst having a player as driver in your mission?

I'm assuming this is due to a locality problem

The vehicle respawn is all handled server side via MPEH so the fact that a client was driving the vehicle (which we know makes the vehicle locality change) should not cause a problem.

The only thing that may cause a vehicle to not respawn/run its init is that it is deleted/null before it gets to that point, in which case the script exits.

What do you have activating on clients when they are killed?

Im thinking something along the lines of a client killed event that does not handle the client as a unit but as a vehicle, and inadvertently deletes the vehicle before it gets to respawn!

Just thinking out loud.

Share this post


Link to post
Share on other sites

Can you reliably repeat this, in that it does not work if the vehicle is destroyed whilst having a player as driver in your mission?

I've not been able to repeat it. Arse. :(

 

The only thing that may cause a vehicle to not respawn/run its init is that it is deleted/null before it gets to that point, in which case the script exits.

What do you have activating on clients when they are killed?

Im thinking something along the lines of a client killed event that does not handle the client as a unit but as a vehicle, and inadvertently deletes the vehicle before it gets to respawn!

Just thinking out loud.

BIS revive/respawn is in use, as is ACE3. Your last theory is best to my mind. Because the vehicle had a driver, the vehicle, in the game engine's eyes becomes the player and the VRM wasn't sncyed to that.

To avoid further confusion and because I have a bug list and a feature list both growing at an alarming rate, I've done away with the VRM and used a killed EH to fire up my asset respawn script.

 

* edit. Using a killed EH still didn't work when the vehicle is non local to the server. And using an MPkilled spawned multiple instances of the assetrespawn script.

a client killed event that does not handle the client as a unit but as a vehicle, and inadvertently deletes the vehicle before it gets to respawn!

The dead vehicle never got deleted.

Share this post


Link to post
Share on other sites

Spent ages trying to track down why respawn positions no longer show when running a mission from a dedicated server. Show ok in the menuPosition dialog but dont show on the map.

Respawn modules are run non globally but BI have forgotten to run the marker script on clients.

true remoteExec [ "BIS_fnc_drawRespawnPositions", 0 ];
from the server is a quick fix to get them to show.

 

 

 

Do you happen to know how to get the marker text, to show up on the map also?

Hoping to do away with the moving marker script entirely.

Share this post


Link to post
Share on other sites

Wondering if someone could help me with an issue I'm having. It seems that the vehicle respawn module doesn't trigger the respawn event handler. I had a discussion with R3vo about it while trying to use a certain function of Eden Enhanced to execute some init commands on some vehicles after they respawn. For now it looks like I'm stuck giving each type of vehicle a different respawn module with it's own init string in the expression field. But is there some way I can set something in the expression field that will trigger the respawn event handler?

 

I'm also wondering if it's worth making a ticket on the feedback tracker to have the vehicle respawn module trigger the respawn EH. Would there be downsides to this for others scripting missions? I can see people having used the respawn EH to script stuff specific to infantry; Obviously wouldn't want to break that. Two solutions I see to that would be to either make a boolean option in the respawn module's attributes to select whether it triggers or not; Or the other option to make an entirely new event handler exclusively for vehicles. I'm a complete novice at scripting so I'd have to leave it up to more experienced individuals to discuss it with the devs. But for now I'm just hoping someone can share with me a workaround using the expression field. Will be much appreciated.

Share this post


Link to post
Share on other sites
19 hours ago, Drift_91 said:

It seems that the vehicle respawn module doesn't trigger the respawn event handler.

This is because the vehicle does NOT respawn, it is deleted and another of exactly the same type is created.

19 hours ago, Drift_91 said:

I'm also wondering if it's worth making a ticket on the feedback tracker to have the vehicle respawn module trigger the respawn EH.

No not really, as explained above the vehicle is not respawning.

 

You already have something that tells you when a vehicle is created by the module with the expression field. Just use this to call your own function that works out what type of vehicle its is and then does what ever you need to the new vehicle. .eg

//Module exectution expression
_this execVM "handleVehicleRespawn.sqf"


//handleVehicleRespawn.sqf
params[ "_newVeh", "_oldVeh" ];

switch ( typeOf _oldVeh ) do {
	
	case ( "M1A4" ) : {	//change String for proper vehicle className
		//Get decals from old vehicle
		_barrelDecal = _oldVeh getVariable [ 'rhs_decalBarrel_type','BarrelArt_Abrams_WD' ];
		_platoonDecal = _oldVeh getVariable [ 'rhs_decalPlatoon_type', 'ArmyPlt_Abrams_WD' ];

		//Store decals on new vehicle
		_newVeh setVariable [ 'rhs_decalBarrel_type','BarrelArt_Abrams_WD' ];
		_newVeh setVariable [ 'rhs_decalPlatoon_type', 'ArmyPlt_Abrams_WD' ];

		//Create new vehicle decals
		[ _newVeh, [ [ 'Label', cM1BarrelSymPlaces, _barrelDecal, 24 ] ] ] call rhsusf_fnc_decalsInit;
		[ _newVeh, [ [ 'Label', cM1PlnSymPlaces, _platoonDecal, 0 ] ] ] call rhsusf_fnc_decalsInit;
		_newVeh animate [ 'IFF_Panels_Hide', 1, true ];
	};
	
	case ( "UGV" ) : {	//change String for proper vehicle className
		createVehicleCrew _newVeh;
	};
	
};

 

Share this post


Link to post
Share on other sites
On 2017-02-17 at 7:49 PM, Larrow said:

This is because the vehicle does NOT respawn, it is deleted and another of exactly the same type is created.

No not really, as explained above the vehicle is not respawning.

 

You already have something that tells you when a vehicle is created by the module with the expression field. Just use this to call your own function that works out what type of vehicle its is and then does what ever you need to the new vehicle. .eg

Thank you, I'll try to adapt that to the latest mission I'm working on.

 

However I still feel the vehicle respawn module should be applying the previous init string and attributes to the replacement vehicle, even if it's technically not "respawning" it in the backend.

Share this post


Link to post
Share on other sites

@Larrow

Bit of a dilemma here. I put together a working script. No errors when it executes and it does what I want. Problem is it doesn't execute 90% of the time and only seems to effect the first vehicle to respawn and none after that. Even more of a problem is that the respawn module seems to only respawn each vehicle once when it's set to run this script.

 

Not sure if this is a bug in RC branch, something with my mods or if I've messed up the script in some way.

 

Here's the code btw:

Spoiler

params["_newVeh","_oldVeh"];

switch (typeOf _oldVeh) do
{
	case ("rhsusf_mrzr4_d"):
    {
		_newVeh animate ['tailgateHide',1,true];
	};

	case ("rhsusf_m1025_d"):
    {
		[_newVeh,'unitdecals_1','82ndab_505reg_1stbn_e25_w_ca'] call rhs_fnc_hmmwv_setDecal;
		[_newVeh,'unitdecals_2','blankdecal_ca'] call rhs_fnc_hmmwv_setDecal;
        _newVeh animate ['hide_CIP',1,true];
        _newVeh animate ['hide_BFT',1,true];
        _newVeh animate ['hide_Antenna',1,true];
        _newVeh animateSource ['Hide_A2Bumper',1,true];
	};

    case ("rhsusf_m1025_d_m2"):
    {
		[_newVeh,'unitdecals_1','82ndab_505reg_1stbn_e25_w_ca'] call rhs_fnc_hmmwv_setDecal;
		[_newVeh,'unitdecals_2','blankdecal_ca'] call rhs_fnc_hmmwv_setDecal;
        _newVeh animate ['hide_CIP',1,true];
        _newVeh animate ['hide_BFT',1,true];
	};

    case ("rhsusf_M978A4_usarmy_d"):
    {
        _newVeh animate ['hide_spare',1,true];
	};
    
    case ("rhsusf_m1a2sep1tuskid_usarmy"):
    {
        [_newVeh,[['Label',cM1BarrelSymPlaces,_newVeh getVariable ['rhs_decalBarrel_type','BarrelArt_Abrams_D'],8]]] call rhsusf_fnc_decalsInit;
        [_newVeh,[['Label',cM1PlnSymPlaces,_newVeh getVariable ['rhs_decalPlatoon_type','ArmyPlt_Abrams_D'],0]]] call rhsusf_fnc_decalsInit;
        _newVeh setVariable ['rhs_decalBarrel_type','BarrelArt_Abrams_D'];
        _newVeh setVariable ['rhs_decalPlatoon_type','ArmyPlt_Abrams_D'];
        _newVeh animate ['Miles_Hide',1,true];
        _newVeh animate ['IFF_Panels_Hide',1,true];
        _newVeh setVariable ['rhs_ammoslot_1_type','rhs_mag_M830'];
        _newVeh setVariable ['rhs_ammoslot_2_type','rhs_mag_M1069'];
        _newVeh setVariable ['rhs_ammoslot_3_type','rhs_mag_M829A3'];
	};
};

 

 

Share this post


Link to post
Share on other sites

To follow up on my last post the issue of vehicles only respawning once seemed to be a bug in Arma, unrelated to the script, that made it past RC but got fixed more recently.

The script still only works a portion of the time and I've submitted a bug report on it after testing with a simpler script: https://feedback.bistudio.com/T124482

 

@LarrowI apologize, I never actually thanked you for your assistance. I appreciate it; Despite the problem with it not working 100% of the time I enjoyed working on it and it wouldn't have been possible without your help. Thank you.

Share this post


Link to post
Share on other sites

Im new to scripting so spent hours searching with no luck hope someone can assist.

 

I have created mobile MHQ also allowing it to teleport.

example 1 Named:  MHQ4

in the init field location added:

this addAction ["Teleport MHQ","teleportmhq.sqf"]; this addAction ["Teleport MHQ1","teleportmhq1.sqf"];  this addAction ["Teleport MHQ3","teleportmhq3.sqf"];this addAction ["Teleport AIR","teleportair.sqf"]; this addAction ["Teleport MHQ2","teleportmhq2.sqf"]; 0 = ["AmmoboxInit",[this,true]] spawn BIS_fnc_arsenal;

This works fine but on destroying the mhq the respawn vehicle loses its name and all the script, how can I fix this.

Do I add something to the respawn module if so where and what?

 

Share this post


Link to post
Share on other sites

@bossmanheild. I'm not for scripting something for the BI vehicle respawn module. It doesn't work fine!

The good point : Your MHQ4 is passed via the respawn module. As you can see cursorTarget refers to MHQ4 after respawn.

The bad one: _this select 1 (old vehicle) passes a null-object. Good luck to do something with.

So the name is not lost. For your script, I don't have immediate, elegant solution.

 

Mine is to forget the BI module and script some other lines: https://forums.bistudio.com/forums/topic/205244-ai-vehicle-respawn-script-an-alternative-for-bi-module/#comment-3194802

At least, this code saves the addactions and arsenal. But don't mix module and this script >> 2 respawns + all wanted feature fail.

 

For someone interested in, you can test it (I already did it) and contribute with positive remarks.

Especially made if you customize your vehicle (off-road appearance, dynamic pylons under jets, colors....) .

Not saying full crew (crew + transported squads), waypoints, even loadout, virtual arsenal.... same as lost vehicle!

 

"Important" NOTE: You can put your backpacks with all your stuffs, loadouts in MHQ, this one will respawn with all equipments, all mags included. Not so bad! :drinking2:

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

×