Jump to content
king_richard

MHQVehicleInit - Vehicle Respawn script

Recommended Posts

Glad to hear you got it working -

I am no script wizzard and you may want to double check with someone who knows more but I am pretty sure that the change I made above is correct - and I notice your script still has the _veh - I am not saying that this will solve your problem but on our version that has been working perfectly on aour dedi for a couple of weeks we have _MHQ

MHQ_vehAction1 =

{

_this addAction

["Prepare truck for weapon","support\scripts\truck_initv2.sqf",

nil, 1, false, true, "",

"alive _this && {speed _this == 0}"];

publicVariable "MHQ_vehAction1";

};

Share this post


Link to post
Share on other sites

@Doodle, glad you caught the typo and even happier to hear there's no problems! Perhaps there should be an extended version of this script for handling the more complex tracking and inits.

@Kabs, about the only thing I can think of is to use

_null = [[[_vehicle],"core\scripts\IgiLoad.sqf"],"BIS_fnc_execVM",false,true];

The only thing I've tested with calling external scripts is making sure the vehName was passed and displaying a hint on completion. I've not done much else with it. Without looking at the script that's being called, all I can say is to check and make sure there's a variable in "IgiLoad.sqf" that selects the vehicle, similar to

_veh = _this select 0;

And the fix that Doodle pointed out is still needed. Without that fix any JIP players will not get the appropriate actions.

Share this post


Link to post
Share on other sites

Just a minor update,

changed createVehicle to use the createVehicle array instead which is stated to be faster.

Share this post


Link to post
Share on other sites

Can you guys confirm this script is well, or did i miss something ?

/////////////////////////////////// V1.1 ///////////////////////////////////

/**************************************************************************

Add to vehicle's init in the editor

null = [this] execVM "scripts\MHQVehicleInit.sqf";

***************************************************************************/

_spawnDelay = 20; // Respawn timer

/**************************************************************************/

///////////////////////////////////////////////////////////////////////

/////////////////////////// VEHICLE ACTIONS ///////////////////////////

MHQ_vehAction2 =

{

_this addAction

["Prepare truck for weapon","support\scripts\truck_initv2.sqf",

nil, 1, false, true, "",

"alive _this && {speed _this == 0}"];

publicVariable "VEH_vehAction1";

};

// Keep all added actions Above Server Check

if (!isServer) exitWith {};

///////////////////////////////////////////////////////////////////////

//////////////////// INIT MHQ / Actions / Extra ///////////////////////

/**************************************************************************

List of actions, sqf's, and any other functions to call on vehicle spawn

or vehicle destroyed

***************************************************************************/

MHQ_VehicleInit =

{

private ["_vehAction1","_vehAction2","_state","_vehicle"];

_vehicle = _this select 0;

_vehName = _this select 1;

_state = _this select 2; // 1 - onSpawn; 0 - onDestroyed;

_nameCheck = ["Offroad1", "Offroad2", "Offroad3", "Offroad4", "Offroad5", "Offroad6", "Offroad7", "Offroad8"]; // Use the actual names of the vehicles given in the editor here.

// Vehicle spawn/Init

if (_state == 1) then

{

// vehicles 3,4,5,6 will use this code

if (_vehName in _nameCheck) then

{

MU = [_vehicle,"MHQ_vehAction2",nil,true] spawn BIS_fnc_MP;

_vehicle setObjectTexture [0,"ambience\modules\images\fia_camo.paa"];

_vehicle setObjectTexture [1,"ambience\modules\images\fia_camo.paa"];

};

_nameCheck2 = ["Offroad5", "Offroad6", "Offroad7", "Offroad8"]; // Use the actual names of the vehicles given in the editor here.

// Vehicle spawn/Init

if (_state == 1) then

{

// vehicles 3,4,5,6 will use this code

if (_vehName in _nameCheck2) then

{

MU = [_vehicle,"MHQ_vehAction2",nil,true] spawn BIS_fnc_MP;

_vehicle setObjectTexture [0,"ambience\modules\images\USWoodland512.paa"];

_vehicle setObjectTexture [1,"ambience\modules\images\USWoodland512.paa"];

};

_nameCheck3 = ["Truck1", "Truck2", "Truck3", "Truck4", "Truck5", "Truck6", "Truck7", "Truck8", "Truck9", "Truck10", "Truck11", "Truck12", "Truck13", "Truck14", "Truck15", "Chopper1", "Chopper2", "Chopper3", "Chopper4"]; // Use the actual names of the vehicles given in the editor here.

// vehicles 3,4,5,6 will use this code

if (_vehName in _nameCheck3) then

{

_vehicle setObjectTexture [0,"ambience\modules\images\fia_camo.paa"];

_vehicle setObjectTexture [1,"ambience\modules\images\fia_camo.paa"];

_vehicle setObjectTexture [2,"ambience\modules\images\fia_camo.paa"];

_heli setObjectTexture [0,"ambience\modules\images\fia_camo.paa"];

_heli setObjectTexture [1,"ambience\modules\images\fia_camo.paa"];

_heli setObjectTexture [2,"ambience\modules\images\fia_camo.paa"];

};

_nameCheck4 = ["Chopper5", "Chopper6", "Chopper7", "Chopper8", "Truck18", "Truck19", "Truck20", "Truck21", "Truck22", "Truck23", "Truck24", "Truck25", "Truck26", "Truck27", "Truck28", "Truck29", "Truck30", "Truck31", "Truck32", "Truck33"]; // Use the actual names of the vehicles given in the editor here.

// vehicles 3,4,5,6 will use this code

if (_vehName in _nameCheck4) then

{

_vehicle setObjectTexture [0,"ambience\modules\images\USWoodland512.paa"];

_vehicle setObjectTexture [1,"ambience\modules\images\USWoodland512.paa"];

_vehicle setObjectTexture [2,"ambience\modules\images\USWoodland512.paa"];

_heli setObjectTexture [0,"ambience\modules\images\USWoodland512.paa"];

_heli setObjectTexture [1,"ambience\modules\images\USWoodland512.paa"];

_heli setObjectTexture [2,"ambience\modules\images\USWoodland512.paa"];

};

// vehciles one and two will use this code

if (!(_vehName in _nameCheck)) then

{

// call addaction functions

//_vehAction1 = [_vehicle,"MHQ_vehAction1",nil,true] spawn BIS_fnc_MP;

// Execute external Sqf's

// If these two don't work then you could try to use call compile with _vehName instead of _vehicle

_vehicle setObjectTexture [0,"ambience\modules\images\fia_camo.paa"];

_vehicle setObjectTexture [1,"ambience\modules\images\fia_camo.paa"];

};

};

};

// Vehicle Destroyed - If there's nothing to do then delete this if statement

/**************************************************************************

The Rest of the Script - Edit at your own risk

***************************************************************************/

_vehicle = _this select 0;

_NameCached = _this select 1;

_oNL = objNull;

// Loop until vehicle is valid

if (_vehicle == _oNL)then

{

while {_vehicle == _oNL} do { sleep 0.5; _vehicle = _this select 0;};

};

// Get vehicle name and position

_vehName = vehicleVarName _vehicle;

_vehiclepos = getPos _vehicle;

_vehicledir = getDir _vehicle;

_classname = typeOf _vehicle;

// Loop variables

_vehKilled = false;

_run = true;

// Init actions, etc

sleep 1;

call {[_vehicle,_vehName, 1] call MHQ_VehicleInit};

while {_run} do

{

sleep 1; // rest between cycles

if (!(alive _vehicle)) then

{

_vehKilled = true;

// Process Additional Destroyed functions

call {[_vehicle,_vehName, 0] call MHQ_VehicleInit};

sleep 1;

};

if (_vehKilled) then

{

sleep _spawnDelay;

deleteVehicle _vehicle;

sleep 4;

// set vehicle position and name

_vehicle = _classname createVehicle _vehiclepos;

_vehicle setPos _vehiclepos;

_vehicle setDir _vehicledir;

sleep 0.1;

// name vehicle globally

_vehicle SetVehicleVarName _vehName;

missionNameSpace setVariable [_vehName, _vehicle];

publicVariable _vehName;

// Process Additional Spawn functions

call {[_vehicle, _vehName, 1] call MHQ_VehicleInit};

// Respawn and init done!

_vehKilled = false;

};

};

i am not really sure :I Well whatever it seems not, since its not working ^ hope you can help me again Richard :/

Edited by Kabs

Share this post


Link to post
Share on other sites

Fixes

- MHQ_vehAction2 publicVariable named incorrectly

- Multiple if(_state == 1) not necessary

- Closing brackets on those if statements were missing

- Declared all name checks outside of the scope if(_state == 1) - easier to read

- Declared a new variable _nameCheckAll which adds all of the arrays together for the final if not in nameCheck

- Updated the vehicle spawn to use the createVehicle array

- undefined variable _heli changed to _vehicle

- think that about sums it up

/////////////////////////////////// V1.1 ///////////////////////////////////
/************************************************** ************************
Add to vehicle's init in the editor
null = [this] execVM "scripts\MHQVehicleInit.sqf";
************************************************** *************************/

_spawnDelay = 20; // Respawn timer

/************************************************** ************************/

///////////////////////////////////////////////////////////////////////
/////////////////////////// VEHICLE ACTIONS ///////////////////////////


MHQ_vehAction2 =
{
_this addAction
["Prepare truck for weapon","support\scripts\truck_initv2.sqf",
nil, 1, false, true, "",
"alive _this && {speed _this == 0}"];
publicVariable "MHQ_vehAction2";
};


// Keep all added actions Above Server Check
if (!isServer) exitWith {};

///////////////////////////////////////////////////////////////////////
//////////////////// INIT MHQ / Actions / Extra ///////////////////////
/************************************************** ************************
List of actions, sqf's, and any other functions to call on vehicle spawn
or vehicle destroyed
************************************************** *************************/
MHQ_VehicleInit =
{
private ["_vehAction1","_vehAction2","_state","_vehicle "];
_vehicle = _this select 0;
_vehName = _this select 1;
_state = _this select 2; // 1 - onSpawn; 0 - onDestroyed;

_nameCheck = ["Offroad1", "Offroad2", "Offroad3", "Offroad4", "Offroad5", "Offroad6", "Offroad7", "Offroad8"];
_nameCheck2 = ["Offroad5", "Offroad6", "Offroad7", "Offroad8"];
_nameCheck3 = ["Truck1", "Truck2", "Truck3", "Truck4", "Truck5", "Truck6", "Truck7", "Truck8", "Truck9", "Truck10", "Truck11", "Truck12", "Truck13", "Truck14", "Truck15", "Chopper1", "Chopper2", "Chopper3", "Chopper4"];
_nameCheck4 = ["Chopper5", "Chopper6", "Chopper7", "Chopper8", "Truck18", "Truck19", "Truck20", "Truck21", "Truck22", "Truck23", "Truck24", "Truck25", "Truck26", "Truck27", "Truck28", "Truck29", "Truck30", "Truck31", "Truck32", "Truck33"];

// to make things cleaner lets put all of these into one list for the final not in names check
_nameCheckAll = _nameCheck + _nameCheck2 + _nameCheck3 + _nameCheck4;

// Vehicle type does not matter and will still be stored in the variable _vehicle
// Vehicle spawn/Init -- Only need one instance of the _state == 1 and
if (_state == 1) then
{

	if (_vehName in _nameCheck) then
	{
	MU = [_vehicle,"MHQ_vehAction2",nil,true] spawn BIS_fnc_MP;
	_vehicle setObjectTexture [0,"ambience\modules\images\fia_camo.paa"];
	_vehicle setObjectTexture [1,"ambience\modules\images\fia_camo.paa"];
	};

	if (_vehName in _nameCheck2) then
	{
	MU = [_vehicle,"MHQ_vehAction2",nil,true] spawn BIS_fnc_MP;
	_vehicle setObjectTexture [0,"ambience\modules\images\USWoodland512.paa"];
	_vehicle setObjectTexture [1,"ambience\modules\images\USWoodland512.paa"];
	};

	if (_vehName in _nameCheck3) then
	{
	_vehicle setObjectTexture [0,"ambience\modules\images\fia_camo.paa"];
	_vehicle setObjectTexture [1,"ambience\modules\images\fia_camo.paa"];
	_vehicle setObjectTexture [2,"ambience\modules\images\fia_camo.paa"];
	_vehicle setObjectTexture [0,"ambience\modules\images\fia_camo.paa"];
	_vehicle setObjectTexture [1,"ambience\modules\images\fia_camo.paa"];
	_vehicle setObjectTexture [2,"ambience\modules\images\fia_camo.paa"];
	};

	if (_vehName in _nameCheck4) then
	{
	_vehicle setObjectTexture [0,"ambience\modules\images\USWoodland512.paa"];
	_vehicle setObjectTexture [1,"ambience\modules\images\USWoodland512.paa"];
	_vehicle setObjectTexture [2,"ambience\modules\images\USWoodland512.paa"];
	_vehicle setObjectTexture [0,"ambience\modules\images\USWoodland512.paa"];
	_vehicle setObjectTexture [1,"ambience\modules\images\USWoodland512.paa"];
	_vehicle setObjectTexture [2,"ambience\modules\images\USWoodland512.paa"];
	};

	// All other vehicle's not defined in the name checks
	if (!(_vehName in _nameCheckAll)) then
	{
	_vehicle setObjectTexture [0,"ambience\modules\images\fia_camo.paa"];
	_vehicle setObjectTexture [1,"ambience\modules\images\fia_camo.paa"];
	};
};
};

/************************************************** ************************
The Rest of the Script - Edit at your own risk
************************************************** *************************/
_vehicle = _this select 0;
_NameCached = _this select 1;
_oNL = objNull;

// Loop until vehicle is valid
if (_vehicle == _oNL)then
{
while {_vehicle == _oNL} do { sleep 0.5; _vehicle = _this select 0;};
};

// Get vehicle name and position
_vehName = vehicleVarName _vehicle;
_vehiclepos = getPos _vehicle;
_vehicledir = getDir _vehicle;
_classname = typeOf _vehicle;
// Loop variables
_vehKilled = false;
_run = true;

// Init actions, etc
sleep 1;
call {[_vehicle,_vehName, 1] call MHQ_VehicleInit};

while {_run} do
{
   sleep 1; // rest between cycles

   if (!(alive _vehicle)) then
       {
       _vehKilled = true;

       // Process Additional Destroyed functions
       call {[_vehicle,_vehName, 0] call MHQ_VehicleInit};
       sleep 1;
       };

   if (_vehKilled) then
   {
       sleep _spawnDelay;
       deleteVehicle _vehicle;
       sleep 4;

       _vehicle = createVehicle [_classname, _vehiclepos, [], 0, "NONE"];
       _vehicle setDir _vehicledir;
       sleep 0.1;
       // name vehicle globally
       _vehicle SetVehicleVarName _vehName;
       missionNameSpace setVariable [_vehName, _vehicle];
       publicVariable _vehName;

       // Process Additional Spawn functions
       call {[_vehicle, _vehName, 1] call MHQ_VehicleInit};

       // Respawn and init done!
       _vehKilled = false;
   };
};

Do note, this is untested code but should work, if not let me know and I'll put in some hints for you to check out where the code breaks down, or you can insert those hints yourself.

Share this post


Link to post
Share on other sites

This is great Richard ! Thank you very much :D i am really new to coding as you can see :Ú

will test that asap.

BTW: do you know where i could get a good C&H script? still searching for a framework wich is nice.

greetz

kabs

Share this post


Link to post
Share on other sites

Update:

i have problems with loading thoose textures in mp on my root server, they only work in editor preview atm. may this be in cause of the code Richard ?

edit: it was a global command needed. so it was the settexture code beeing wrong from me :)

Edited by Kabs

Share this post


Link to post
Share on other sites

@ Kabs -

Pretty sure the texture issue is not the script - have a look round for an answer as I have seen other people with this issue on servers - I think there might be a setObjectTextureglobal - Do let us know here if you do find a solutiuon for the textures on a server as its something I would be intrested in knowing,

@King Richard

Script working perfectly - Just a thought I notice the addactions are available when you are in the drivers / passenger seat. Might be a nice option to choose whether acctions are available when you are in the vehicle or you HAVE to be outside of the vehicle.

Share this post


Link to post
Share on other sites
@ Kabs -

I think there might be a setObjectTextureglobal

well yeah i allready figured that out as u can red above ;)

addactions are available when you are in the drivers / passenger seat. Might be a nice option to choose whether acctions are available when you are in the vehicle or you HAVE to be outside of the vehicle.

jep, true. it seems unrealistic in any way. but i would set this optional too for good.

Share this post


Link to post
Share on other sites

@Kabs,

Good to hear it's working. As Doodle pointed out, perhaps the setObjectTextureGlobal command is what your looking for? A lot of things I've yet to tinker with and locality is one of those things that I can only learn through experience. But when you find a solution to something like that please do post what worked for you, may help the next guy.

@Doodle,

If you'd like to add further conditions to the actions you can do so in the function itself. You'll notice I've structured the function into 3 lines for the action,

- the first is the name and sqf to execute

- second line is the Bis stuff that generally stays the same for most actions: arguments, priority, showWindow, hideOnUse, shortcut

- the third line is the condition that must be true for the action to be available

more detailed info needed: addAction

Now if you'd like to make it so that you can only use the action while outside of the vehicle than you could try:

MHQ_vehAction2 =
{
   _this addAction ["<t color='#ff1111'>Virtual Ammobox</t>","VAS\open.sqf",
   nil, 1, false, true, "",
   "alive _this && {vehicle player == player} && {speed _this == 0}"];
   publicVariable "MHQ_vehAction2";
};

Change the == to != to make it so you have to be inside of the vehicle. I believe their was a vehicle cargo command to so you could possibly set up so that only players in the cargo could use the actions while inside of the vehicle. Do not recall the exact command off the top of my head.

Share this post


Link to post
Share on other sites

hey richard,

would it be possible to inbound a script for left behind vehicles to respawn ?

greetz

kabs

Share this post


Link to post
Share on other sites

Kabs,

I am unsure of what your requesting. Could you expand on left behind vehicles.

Share this post


Link to post
Share on other sites

deserted vehicles ;)

thoose wich left behind by players for whatever reason on the battlefield. they should respawn as in simple respawn script.

Greetz

Kabs

Share this post


Link to post
Share on other sites

I will look into running a deserted check and make that part of the extended version I suppose. Won't be hard to implement, it's just the frequency of running a player within area check is what I'd like to play with or atleast leave it easily adjustable. Not sure when I'll get around to implementing that though.

Share this post


Link to post
Share on other sites

Been busy but finally got around to adding the abandoned vehicle check. Also included the code for checking names of vehicles so you can separate actions per vehicle.

MHQVehicleInitExt V1.0

Link is also on the first post of the thread. Distance check is only set to 20, so you can see it in action and so I could test it out. It will also only check for one side. Let me know if there's anything else to add or fix and I'll put her on my todo list.

Share this post


Link to post
Share on other sites

I've attempted to use this most recent version of this script as the basis for our group's MHQ. Almost everything works perfectly, the only notable exception is that when the MHQ respawns, like all other respawn systems in ArmA 3, the 'new' vehicle does not have the original name - in this case "MHQ_Alpha".

I've tested this by having a repeating radio alpha trigger calling;

MHQ_Alpha setDamage 1;

This manages to blow up the first MHQ but does not do the same for subsequent respawns. The weird thing is that at an earlier point, i'm fairly certain this worked - has there been some fundamental change that prevents units from being named a specific name when they respawn?

Any help or even better, a working example, would be really appreciated.

Thanks.

Share this post


Link to post
Share on other sites

Sorry for the delayed response. I have not been on arma lately but will check it out as soon as I can and hopefully get a fix up.

And yes it was working pre-patch. I'll do some digging and let ya know.

EDIT: I tested in a local MP session and it worked fine. But unable to test in a dedicated server environment at the moment.

Edited by King_Richard

Share this post


Link to post
Share on other sites

I'm trying to get this to work on Invade and Annex 3.2.0  Tanoa

No mater what i try it wont work does anyone know if this still works with the current release client?

Using the new spawn system / GUI also

 

Thanks in advance

Jim

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

×