Jump to content
king_richard

MHQVehicleInit - Vehicle Respawn script

Recommended Posts

MHQVehicleInit

What it does:

- Respawns a vehicle by simply adding " null = [this] execVM "scripts\MHQvehicleInit.sqf"; " without the surrounding " " to a vehicle in the editor

- Retains name given in the editor

- addactions on vehicle init and on respawns (actions are added in the script)

- execute seperate sqf's on init, spawn, and/or destroyed

- commented script

DOWNLOAD >> MHQVehicleInit V1.1 << DOWNLOAD

* The Extended Version - Includes an abandoned vehicle check and name checking for multiple vehicles with separated actions/code.

MHQVehicleInitExt V1.0

Change Log

* 6/01/14 -- Added the Extended version

-- Name checking feature which allows you to separate code or actions by vehicle name

-- Abandoned vehicle function checks for nearby units, if none detected than vehicle is deleted

* 3/12/14 -- createVehicle is now using the array that is supposed to be faster, no version # change

* 3/01/14 -- Name of vehicle given in Editor is now global.

-- Removed Hints and markers.

-- Functions ExecSQF and AddAction Merged into MHQ_VehicleInit, there's now a "_state" variable for on spawn and on destroyed coding sections.

* 2/20/14 -- QuickFix For: duplicated actions on player jip (on dedicated servers)

Adding an action to your MHQ, create a new function or Replace one of the defaults

MHQ_vehAction3 =
{
_this addAction
["ActionName","Scripts\YourScript.sqf",		
nil, 1, false, true, "",
"alive _this && {speed _this == 0}"];
publicVariable "MHQ_vehAction3";
};

Now Add your action to MHQ_VehicleInit as this function gets called on vehicle init and respawn

MHQ_VehicleInit =
{
   private ["_vehAction1","_vehAction2","_vehAction3","_state","_vehicle"]; // added action 3
   _vehicle = _this select 0;
   _vehName = _this select 1;
   _state = _this select 2; // 1 - onSpawn; 0 - onDestroyed;

   // Vehicle spawn/Init
   if (_state == 1) then
   {
       // call addaction functions
       _vehAction1 = [_vehicle,"MHQ_vehAction1",nil,true] spawn BIS_fnc_MP;
       _vehAction2 = [_vehicle,"MHQ_vehAction2",nil,true] spawn BIS_fnc_MP;
       _vehAction3 = [_vehicle,"MHQ_vehAction3",nil,true] spawn BIS_fnc_MP; // added action 3
   };

There's also a commented line with an example for calling external sqf's.

If your interested in separating your actions for different vehicles then check out this example:

MHQ_VehicleInit =
{
   private ["_vehAction1","_vehAction2","_state","_vehicle"];
   _vehicle = _this select 0;
   _vehName = _this select 1;
   _state = _this select 2; // 1 - onSpawn; 0 - onDestroyed;

   // Use the actual names of the vehicles given in the editor here.
   _nameCheck = ["veh3", "veh4", "veh5", "veh6"];

   // Vehicle spawn/Init
   if (_state == 1) then
   {
       // vehicles 3,4,5,6 will use this code
       if (_vehName in _nameCheck) then
       {
       // call addaction function for only the vehicles in _nameCheck
           _vehAction1 = [_vehicle,"MHQ_vehAction1",nil,true] spawn BIS_fnc_MP;
       };

       // all other vehicles will use this block
       if (!(_vehName in _nameCheck)) then
       {
           // call addaction function for all vehicle's not in _nameCheck
           _vehAction2 = [_vehicle,"MHQ_vehAction2",nil,true] spawn BIS_fnc_MP; 
       };
   };
};

----------------------------------------

There's still some functions that I'd like to add or fine tune as I get more familiar with Arma script. I'm open for suggestions and discussion!

----------------------------------------

To Do:

- Vehicle Markers

- Available and Destroyed Messages

- Get those working in a dedicated enviroment

Edited by King_Richard

Share this post


Link to post
Share on other sites

Great work! made post in previous thread

going to do some testing on dedi now and report back re the naming issue.

---------- Post added at 12:42 PM ---------- Previous post was at 10:55 AM ----------

Just tested on our dedi.

Seems like its creating the actions for every player who joins

I joined server all addactions were ok

Left server and rejoined as another player and then addaction was added again - so then there was TWO ammobox addactions

Left server and rejoined as yet another player and then every action was added again so I had THREE ammobox addactions

and so on.

Hope this helps

PS I did get the scripts working that I was having issues with before - Guess it was me being dumb.

Thanks again

---------- Post added at 01:18 PM ---------- Previous post was at 12:42 PM ----------

Just had another check on dedi and I am sure it is adding a new addaction every time a player joins

Share this post


Link to post
Share on other sites

I'll look into it.

The action is being duplicated for a player disconnects and reconnects or are you saying the action duplicates every time a player joins? Have not had that happen, did notice the duplicating actions for a player who disconnects and rejoins the same mission though.

Share this post


Link to post
Share on other sites

Ah I think it was disconnect and re join - will let you know

Thanks

Share this post


Link to post
Share on other sites

Just tested and it is duplicating when a player joins. Will try to get a fix asap when I get the time to, but it may take some time.

EDIT:

Sorry about that, lot of multi-tasking right now and while I was trying to get the markers to work on a dedicated server I forgot change the server checks back. So, delete the " if (isDedicated) exitWith {}; " @line: 80. And at the top of the script add " if (!isServer) exitWith {}; ". (without the encapsulating quotations)

This should fix the duplicating actions, however, if you were using the included markers that I set up then they will no longer work on a dedicated server. I'll work on a fix for the messages, markers and update when ready.

Edited by King_Richard

Share this post


Link to post
Share on other sites

Thanks for reply - Havent had time to test it yet but will do over the weekend.

As far as you can are aware does the script, with the above edit, work as follows on a dedi server?

A: Not duplicate addactions on player connect

B: Retain the name of the vehicle if it gets destroyed and add the actions

not to fussed about the marker as I can use a script of my own for that as long as vehicle retains is name.

Really good script

Thanks in advance

Share this post


Link to post
Share on other sites

Just tried this and it seems its not retaining its name.

I destroyed the vehicle and the marker I had added stayed in the bottom left when it respawned

any idea?

Share this post


Link to post
Share on other sites

The vehicle is being deleted an re created, any chance the marker script isn't picking it back up on re spawn? If the marker script is not checking to see if the vehicle is null before attempting to locate it then it'll break.

Share this post


Link to post
Share on other sites

I am 100% sure the name is not retained.

If you try placing the vehicle with a name "MHQ" for example

Then blow up vehicle by typing in debug "MHQ setDamage 1.0;"

wait for vehicle to respawn then again in debug consol type "MHQ setDamage 1.0;"

You will see the MHQ doesnt get destroyed second time as it now has a different name - even though your attached marker has the original name

hope this helps

Share this post


Link to post
Share on other sites

Alright, I'll check it out when I get some time.

Last week I started re writing this script and as simple as it is I just haven't had time to finish and test it. Don't know if you feel like testing or not but I probably won't get around to finishing and verifying this until next week (end) sometime.

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

_spawnDelay = 25;			// Respawn timer

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

VEH_AddVehicleActions =
{
   private ["_vehAction1","_vehAction2","_vehicle"];
   _vehicle = _this select 0;

   // calls the functions to add actions to the vehicle
_vehAction1 = [_vehicle,"VEH_vehAction1",nil,true] spawn BIS_fnc_MP;
_vehAction2 = [_vehicle,"VEH_vehAction2",nil,true] spawn BIS_fnc_MP;
};
VEH_vehAction1 =
{
_this addAction
["Repair Vehicle","Scripts\repair.sqf",
nil, 1, false, true, "",
"alive _this && {speed _this == 0}"];
publicVariable "VEH_vehAction1";
};
VEH_vehAction2 =
{
_this addAction ["<t color='#ff1111'>Virtual Ammobox</t>","VAS\open.sqf",
nil, 1, false, true, "",
"alive _this && {speed _this == 0}"];
publicVariable "VEH_vehAction2";
};
VEH_ExecVehSQFs =
{
private ["_vehicle","_vehName","_state"];
_vehicle = _this select 0;
_vehName = _this select 1;
_state = _this select 2; 	// 1 - onSpawn; 0 - onDestroyed;

// Call external sqf's on vehicle init and spawn
// _null = [[[_vehicle,_vehName],"scripts\doSomething.sqf"],"BIS_fnc_execVM",false,true] spawn BIS_fnc_MP;
};

/*********************************************************************/
if (!isServer) exitWith {};
/*********************************************************************/

// Load vehicle variables
_vehicle = _this select 0;
_NameCached = _this select 1;
_oNL = objNull;
if (_vehicle == _oNL)then{while{_vehicle == _oNL}do{ sleep 0.5; _vehicle = _this select 0;};};
_vehName = vehicleVarName _vehicle;
_vehiclepos = getPos _vehicle;
_vehicledir = getDir _vehicle;
_classname = typeOf _vehicle;

// Used for storing original name after 1st pass and forcing name on respawn
sleep 1;
if (!isNil "_NameCached") then
{
_vehicle SetVehicleVarName (format ["%1", _vehName]);
publicVariable format ["%1", _vehName];
};

// Add vehicle actions
call {[_vehicle] call VEH_AddVehicleActions};
call {[_vehicle,_vehName, 1] call VEH_ExecVehSQFs};

waitUntil{sleep 1; !alive _vehicle};

/************ Respawn Vehicle *********************/
sleep _spawnDelay;

// Process any additional on destroyed scripts
call {[_vehicle,_vehName, 0] call VEH_ExecVehSQFs};

deleteVehicle _vehicle;
sleep 4;
_vehicle = _classname createVehicle _vehiclepos;
_vehicle setPos _vehiclepos;
_vehicle setDir _vehicledir;
sleep 0.1;
_vehicle SetVehicleVarName (format ["%1", _vehName]);
publicVariable format ["%1", _vehName];
sleep 1;

// End script and execute again
null = [[[_vehicle, format ["%1", _vehName]],"scripts\VehicleInit.sqf"],"BIS_fnc_execVM",false,true] spawn BIS_fnc_MP;

Don't know why this name being retained has been so stubborn! It does take a second or two for the name to register with this script, so keep that in mind if you test it out.

Thanks for testing out the other stuff and sorry about the hiccups thus far.

-- Almost forgot, notice that I called this script with vehicleInit and not the MHQvehicleInit. Was testing the two scripts together when I wrote this up.

Share this post


Link to post
Share on other sites

No need to appologise for the hiccups its all part of the fun...apparantly.

Just had a test with the most recent version and sorry to report still the same - Vehicle doesnt retain its name after being destroyed.

Out of unterest have you tried respawning it using the build in vehicle respawn module - I dont know how you would incorporate in your script but it works very well in MP on a dedi and it retains the vehicle name. Just a thought,

Share this post


Link to post
Share on other sites

Got it figured out, well sort of. One step forward, two steps back.

Ends up that setting the vehicle name is not the same as the object name. But now that I've got that portion working, it busted the rest of the script so it'll take some time for me to work out the kinks my free time.

Share this post


Link to post
Share on other sites

By "reteaining its name" I believe he more accurately means the script is retaining the vehicle's index. _vehicle refers to the vehicle, despite what its "name" may be. So, while using the script, simply refer to the vehicle as _vehicle. Or, execute a script through the respawn one, passing along the variable _vehicle. Or if you want to be specific about it and control it in-game, such as via a setDamage 1 from the console, you can define a global variable as _vehicle. For instance, here is what I did to the addVehicleAction function, which is called on every respawn.

MHQ_AddVehicleActions =
{
   private ["_vehAction1","_vehAction2","_vehicle"];
   _vehicle = _this select 0;
   testvec = _vehicle;

   // calls the functions to add actions to the vehicle
_vehAction1 = [_vehicle,"MHQ_vehAction1",nil,true] spawn BIS_fnc_MP;
_vehAction2 = [_vehicle,"MHQ_vehAction2",nil,true] spawn BIS_fnc_MP;
};

I can now refer to testvec and manipulate the vehicle in any way I please, anywhere I please.

Edited by Grimes [3rd ID]

Share this post


Link to post
Share on other sites

will try the above tomorrow and report back

thanks

Share this post


Link to post
Share on other sites

@ Grimes - Just had a quick test - (not on dedi yet) but I can report back that the vehicle is now retaining its name if you destroy it.

@ King Richard - it appears you were soo close - looks like from what grimes has posted above that you also need to add the name of the editor placed vehicle to the script

Will report back after testing on dedi

Thanks guys

Share this post


Link to post
Share on other sites

to name it globally you can use missionNameSpace command.

_vehicle = _classname createVehicle _vehiclepos;
_vehicle setPos _vehiclepos;
_vehicle setDir _vehicledir;

// name vehicle globally 
_vehicle SetVehicleVarName _vehName;
missionNameSpace setVariable [_vehName, _vehicle];
publicVariable _vehName;

Share this post


Link to post
Share on other sites

ok guys can report back that it all works perfectly.

There is one slight change that would be nice but not essential.

I have placed a vehicle named mcv in editor that is locked. When it respawns it respawns "unlocked" and chance of making the script remember the locked state of the vehicle.

would adding mcv lock true to either my init or placed in a game logic in editor keep the vehicle locked when it respawned and when someone jip'd?

thanks in dvance

Share this post


Link to post
Share on other sites
MHQ_AddVehicleActions =
{
   private ["_vehAction1","_vehAction2","_vehicle"];
   _vehicle = _this select 0;
   testvec = _vehicle;
   testvec lock true;

   // calls the functions to add actions to the vehicle
   _vehAction1 = [_vehicle,"MHQ_vehAction1",nil,true] spawn BIS_fnc_MP;
   _vehAction2 = [_vehicle,"MHQ_vehAction2",nil,true] spawn BIS_fnc_MP;
};  

Share this post


Link to post
Share on other sites

Thank you's.

What I tried the other night was > call compile format ["%1 = _classname createVehicle _vehiclepos", _vehName];

And when Grimes showed > testVec = _vehicle; < Got me thinking that I could just use > call compile format ["%1 = _vehicle", _vehName];

Seems to be working fine and will now let you call the vehicle with whatever name you've set for it in the editor. I just need to finish up some stuff but will try to get it fixed this weekend rather then next.

Nimrod_Z,

Thanks for the missionNameSpace example. Was unsure of how to use that and will also try that out later on.

I'll also compress the actions and execSQF functions into one Init function used for init/spawn or killed as well.

EDIT: Went ahead and took the time to do it now since I couldn't just let it sit there broken. The missionNameSpace is what worked for a dedicated enviroment and the script is now updated with the changes.

Edited by King_Richard

Share this post


Link to post
Share on other sites

@King Richard

Script working very well on dedicated.!

Share this post


Link to post
Share on other sites

Hey Doodle,

Hey Richard,

i am really frustrated since i dont understand how to add this script correctly. I tried it but my vehicle wasnt respawning.

1. i am unsure where to name the vehicle globaly exactly. Here is my string:

// name vehicle globally

_vehicle SetVehicleVarName _Offroad1;

missionNameSpace setVariable [_vehName, _vehicle];

publicVariable _vehName;

2. I am not really sure where to name the Vehicle in Editor for the global init access.

i just placed the name in the unit field over "init" field

my init:

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

my sqf changes(blue marked to show where i cuted/changed):

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

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

Add to vehicle's init in the editor

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

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

_spawnDelay = 1; // Respawn timer

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

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

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

MHQ_vehAction1 =

{

_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;

// Vehicle spawn/Init

if (_state == 1) then

{

// call addaction functions

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

// Execute external Sqf's

// _null = [[[_vehicle,_vehName],"scripts\doSomething.sqf"],"BIS_fnc_execVM",false,true];

};

// 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 _Offroad1;

missionNameSpace setVariable [_vehName, _vehicle];

publicVariable _vehName;

// Process Additional Spawn functions

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

// Respawn and init done!

_vehKilled = false;

};

};

Would be nice if you guys can help me out !

PS:

@Doodle: I came to this thread trying to find a solution from the thread of "simple respawn script" where you also looked for help getting your scripts ingame after respawn http://forums.bistudio.com/showthread.php?76445-Simple-Vehicle-Respawn-Script/page17. Good to see i maybe found the way down the road ^^

What need to have is only that Addaction to work, since it didnt seem to run with simple respawn script.

Here all the lines i also need to add into the vehicles init (maybe someone can give me a proper solution):

Vehicle 1+2:

Theese needs to be runned again after respawn:

null=[this] execVM "core\scripts\IgiLoad.sqf";
this setObjectTexture [0,"ambience\modules\images\fia_camo.paa"]; this setObjectTexture [1,"ambience\modules\images\fia_camo.

Vehicle 3-6:

Theese needs to be runned again after respawn:

MU = this addAction ["Prepare truck for weapon","support\scripts\truck_initv2.sqf"];

If thoose can be handled with your script/handeled that there needs to be seperately vehicles with theese own scripts, all would be good for me :)

Greetz

Kabs

Edited by Kabs

Share this post


Link to post
Share on other sites

Click -> Image of settings in Editor

Example shown of settings on the vehicle in the editor. Setting MHQ_Alpha as the name in the editor will be the name that is retained by the script. No need to set it manually in the script! You just need to change back that line under

// name vehicle globally to:

_vehicle SetVehicleVarName _vehName;

Also, when you removed the destroyed statement in the function MHQ_VehicleInit you also took out the closing bracket.

MHQ_VehicleInit =
{
private ["_vehAction1","_vehAction2","_state","_vehicle "];
_vehicle = _this select 0;
_vehName = _this select 1;
_state = _this select 2; // 1 - onSpawn; 0 - onDestroyed;

// Vehicle spawn/Init
if (_state == 1) then
{
// call addaction functions
_vehAction1 = [_vehicle,"MHQ_vehAction1",nil,true] spawn BIS_fnc_MP;
// Execute external Sqf's
   _null = [[[_vehicle,_vehName],"core\scripts\IgiLoad.sqf"],"BIS_fnc_execVM",false,true];
   // 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"];
};
}; // << This got deleted

As for comparing multiple vehicles, using this script you'd have to compare their names and decide what you want to do if the name matches. Not a function I was planning on implementing. But I'll think about it since it could come in handy. Got my hands tied up in some other stuff atm though that is itching at me.

EDIT: what I had in mind works, lucky, lol. Give me a minute to put it together and I'll show an example with your stuff.... Here's an example for ya:

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";
};

MHQ_VehicleInit =
{
   private ["_vehAction1","_vehAction2","_state","_vehicle"];
   _vehicle = _this select 0;
   _vehName = _this select 1;
   _state = _this select 2; // 1 - onSpawn; 0 - onDestroyed;

   _nameCheck = ["veh3", "veh4", "veh5", "veh6"]; // 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;
       };

       // 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 
           _null = [[[_vehicle,_vehName],"core\scripts\IgiLoad.sqf"],"BIS_fnc_execVM",false,true]; 
           // 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"]; 
       };
   };
};

Note: Untested so hopefully your actions work on the correct vehicles!

On a side note to Doodle, have you had any problems with the actions? I just noticed that I miss typed the publicVariable "VEH_vehAction1"; should be "MHQ_vehAction1" and also 2.

Edited by King_Richard

Share this post


Link to post
Share on other sites

@ KingRichard - All working fine on our dedi, I did notice the couple of typos and amended that at this end. Really like the script! - Though now I see an option for multiple vehicles it's got me thinking.

@Kabs - cant help with the scripts running after the vehicle has respawned as we dont use that option. A couple of things in your code I "THINK" might be wrong are

Change youe respawn time to at least 20 sec - 1 sec might be too short as the vehicle may just keep respawning and the getting destroyed as the od wreck has not had time to delete.

Also I think that the below code should be

MHQ_vehAction1 =

{

_this addAction

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

nil, 1, false, true, "",

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

publicVariable "VEH_vehAction1";

};

IN RED

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";

};

You dont need to name the vehicle in the script only name the vehilce in the editor - in the vehicles NAME field.

Sorry I can tbe of more help

Share this post


Link to post
Share on other sites

Hey Richard,

just tested this and its all working fine, but one thingy is not working:

// Execute external Sqf's

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

isnt generating. i dont know whats the reason, but might be the code line not accepting.

Again my sqf:

/////////////////////////////////// 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"]; // 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"];

};

// 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

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

// 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 didnt gave vehicle 1 and 2 any names (if this was correct?), i think it doenst know where to place this could also be the problem. I have more vehicles than the 1-6. 2 more offroaders and 1 heli.

Hope you can help me sorting this out, i love this script so far. it could overrun the simple respawn script easily IMO. For sure it would need more functionality as respawn times for seperate vehicles. that would be also a step forward to this.

@Doodle: half the way went good after clean up the errors mentioned by Richard. So it seems "MHQ_vehAction1"; wasnt the problem.

Edited by Kabs

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

×