Jump to content
Sign in to follow this  
demonized

Deploy Static weapon / object [script]

Recommended Posts

Deploy Static v 1.1

This script adds one or several actions to the player unit, wich then can deploy a static weapon or object of choice on the battlefield.

can be used to build mg tripods, mortars, sandbags, really any kind of object ingame.

it works much like mg nests machinegunners can deploy in domination 1.57.

though code is not based on that code.

player can have several actions, but only one object can be built at a time.

need to remove old object before building a new one, also only the building player can remove it, but anyone can use it.

there is a few options you can set in top of script, explanations in script below.

examples and instructions also in top of script.

Fully tested in SP and MP editor with respawns, untested on dedi server.

script auto adjusts to SP or MP games.

Note: player units must be named (in the unit placement window, name part top right), i think i had some issues when using non named player units.

Notes:

Should be fully JIP compatible.

Atm if a player builds a object and leaves the game in MP, the object will remain until end of mission or that player joins again and removes it.

also each object gets a marker with descriptive name on it so it can be easily located.

JIP on markers is unknown, when someone gets it tested on a dedi server, i can fix that, probably needs to gather all markers in a global array and create them again for any JIPs.

Changelog v 1.1

* added multiple actions option.

* added custom relative dir option.

v 1.0

* first release.

Bugs / Issues

* once a static is built, some of them (those from the weapon bags collection) can be disasembled into bags, most likely this will break the script, workaround is being worked on, probably enough to have a small script run on the object and then rename bags if such a thing happens.

save this below as deployweapon.sqf in your mission folder

/*
Deploy static v 1.1
by Demonized

place this in init.sqf
DMZ_Deploy_Static = [];

Name the unit, place this in init of unit:
_null = ["className_of_weapon",this,"start"] execVM "deployweapon.sqf";
replace className_of_weapon with any kind of static weapon of choise.

example:
_null = ["M2HD_mini_TriPod_US_EP1",this,"start"] execVM "deployweapon.sqf";
wait for "build meter" to be filled, or raise weapon or move to abort, applies for bot assembling and disasembling.

optional:
	relative position: by default direction of object is same as player (forward) 0 - 360 is valid values.
	add after "className" a direction in relation to player to force direction of static, for example for bunkers, sandbags etc.
	example object facing right of player:
	_null = [["className_of_weapon",90],this,"start"] execVM "deployweapon.sqf";

	additional actions, add option for player to deploy numerous types of statics, note only one can be deployed at a time.
	add in extra classnames in a array [["className_of_weapon1",direction],["className_of_weapon2"]] direction is optional, only use if you wish another direction than the player.
	example 3 total options for player, where first and 2 object has default direction forward from player, nr 3 has right of player (90)
	_null = [[["TOW_TriPod_US_EP1"],["M2HD_mini_TriPod_US_EP1"],["M252_US_EP1",90]],this,"start"] execVM "deployweapon.sqf";

Script is compatible with SP and MP missions.
Not tested on dedi server but should be ok.
Also designed to handle JIP, but again untested on dedi server.
I have no idea if it will work on Arma 2 alone, created using Arma2 CO.

save this below as deployweapon.sqf in your mission folder.
*/


_anim = "AmovPercMstpSrasWrflDnon_AinvPknlMstpSlayWrflDnon";  // this is the transition animation used, change to whatever transition animation desired.  other animations found here: http://community.bistudio.com/wiki/ArmA2:_Moves   -  or search armaholic for animationviewer.
_timer = 0;		// this is the life the static has in seconds before it will despawn automatically and give the user the ability back, set to 0 for never, (default 0 = no timer, needs to be undeployed).
_buildTimer = 10; // this is the timer to assemble/disassemble, set to 10 for now to show bar correctly.
_mount = false;	// set this to true to imediatly move in as gunner after build is completed.

waitUntil {!isNil ("DMZ_Deploy_Static")};
_unit = _this select 1;
if (_unit != player) exitWith {};

// deploy/undeploy show progress function.
_build = {
_unit = _this select 0;
if (_unit != player) exitWith {};
_anim = _this select 1;
_timer = _this select 2;
_perc = _timer/10;
_sel = 0;
if ("teardown" in _this) then {_sel = 9};
_bar = [["|________"], ["||________"], ["|||_______"], ["||||______"], ["|||||_____"], ["||||||____"], ["|||||||___"], ["||||||||__"], ["|||||||||_"], ["||||||||||"]];
_unit playMove _anim;
waitUntil {(animationState _unit) == _anim};
waitUntil {(animationState _unit) != _anim};
//_state = (animationState _unit);  // use to dynamically get end anim of animation transition used, for now its hardcoded below.
_state = "ainvpknlmstpslaywrfldnon";
while {_timer != 0} do {
	if ((animationState _unit) == _state) then {
		_text = format["Building %1 \n %2 \n \n move to abort",(_this select 3),(_bar select _sel)];
		cutText [_text,"PLAIN",0];	// this is for text center screen, wich will disapear after completion.
		//hintSilent _text;		// this is for discrete hint in top right corner, wich will stay long time after completion.
		if ("teardown" in _this) then {_sel = _sel - 1} else {_sel = _sel + 1};
		sleep 1; _timer = _timer - 1;
	} else {
		_timer = 0;
		_unit setVariable ["abort", false, true];
		_unit setVariable ["static", true, true];
		waitUntil {!(_unit getVariable ["abort", true])};
	};
	cutText ["","PLAIN",2];
};
};

// status check function.
_statusChk = {
if (_this != player) exitWith {};
_type = "none";
_wep = "none";
_uid = "none";
if (_this in playableUnits) then {_uid = getPlayerUID _this} else {_uid = vehicleVarName _this};
{if (_uid in _x) then {_type = _x select 1;_wep = _x select 2}} foreach DMZ_Deploy_Static;
[_type,_wep]
};

// status change function.
_status_change = {
{if ((_this select 0) in _x) then {_x set [2,(_this select 1)]}} foreach DMZ_Deploy_Static;
publicVariable "DMZ_Deploy_Static";
};

_uid = "none";
if (player in playableUnits) then {_uid = getPlayerUID player} else {_uid = vehicleVarName player};
if ("start" in _this) then {
_type = [];
_wep = "not";
if ((count DMZ_Deploy_Static) != 0 AND ({_uid in _x} count DMZ_Deploy_Static) != 0) then {
	while {alive _unit AND _wep != "none"} do {
		_ret = _unit call _statusChk;
		_type = _ret select 0;
		_wep = _ret select 1;
		sleep 1;
	};
} else {
	_type = _this select 0;
	DMZ_Deploy_Static = DMZ_Deploy_Static + [[_uid,_type,"none"]];
	publicVariable "DMZ_Deploy_Static";

	if (_unit in playableUnits) then {
		_idx = _unit addMPEventHandler ["MPRespawn", {
			_unit = _this select 0;
			_null = _unit spawn {
				waitUntil {alive _this};
				if (_this != player) exitWith {};
				_uid = "none";
				if (_this in playableUnits) then {_uid = getPlayerUID _this} else {_uid = vehicleVarName _this};
				_wep = "none";
				_type = [];
				_loop = true;
				while {_loop} do {
					{if (_uid in _x) then {_type = _x select 1;_wep = _x select 2;if (_wep == "none") then {	_loop = false}}} foreach DMZ_Deploy_Static;
					sleep 1;
				};
				_null = [_type,player,"start"] execVM "deployweapon.sqf";
			};
		}];
	};
};
if (alive _unit) then {
	player setVariable ["static", true, true];
	{
		_dir = 0;
		_obj = _x select 0;
		if ((count _x) == 2) then {_dir = _x select 1};
		_vDName = getText(configFile >> "cfgVehicles" >> _obj >> "displayName");
		_name = format["<t color = '#0000FF'>Build %1</t>",_vDName];
		_id = player addAction [_name, "deployweapon.sqf", [_obj,_vDName,_dir,"deploy"], 1, false, true, "", "alive _this AND (vehicle _this) == _this AND _target == _this AND _this getVariable ['static', true]"];
	} foreach _type;
};
} else {
_obj = _this select 0;
_id = _this select 2;
_arg = _this select 3;
if ("deploy" in _arg) then {
	_unit setVariable ["static", false, true];
	_dir = getDir _unit;
	_pos = getPos _unit;
	_cd = _dir mod 360;
	_newX = (_pos select 0) + (sin _cd * 1);
	_newY = (_pos select 1) + (cos _cd * 1);
	_newZ = (_pos select 2)-0.03;

	_unit setVariable ["static", false, true];
	_action = [_unit,_anim,_buildTimer,(_arg select 1)] spawn _build;
	waitUntil {scriptDone _action};

	if (_unit getVariable ["abort", true]) then {
		_vName = format["DMZ_Static_Weapon_%1",_unit];
		_wep = createVehicle [(_arg select 0), [0,0,500], [], 0, "NONE"];
		_wep SetVehicleVarName _vName;
		_wep Call Compile Format ["%1=_This ; PublicVariable ""%1""",_vName];

		_marker = createMarker[_vName,[0,0,0]];
		_marker setMarkerShape "ICON";
		_marker setMarkerType "DOT";
		_marker setMarkerColor "ColorBlue";
		_vDName = format["%1s %2",(name player),(getText(configFile >> "cfgVehicles" >> (typeOf _wep) >> "displayName"))];
		_marker setMarkerText _vDName;

		_null = [_uid,(vehicleVarName _wep)] spawn _status_change;
		if (_timer != 0) then {
			_null = [_wep,_unit,_timer,_uid,_marker] spawn {
				_obj = _this select 0;
				_unit = _this select 1;
				_uid = _this select 3;
				sleep (_this select 2);
				if (!isNull _obj) then {deleteVehicle _obj};
				deleteMarker (_this select 4);
				_unit setVariable ["static", true, true];
				{if (_uid in _x) then {_x set [2, "none"]}} foreach DMZ_Deploy_Static;
				publicVariable "DMZ_Deploy_Static";
			};
		};
		if ((count _Arg) == 4) then {_dir = _dir + (_arg select 2)};
		_wep setDir _dir;
		_wep setPos [_newX,_newY,_newZ];
		_con = format["_this == %1 AND (vehicle _this) == _this",_unit];
		_wep addAction ["Remove weapon", "deployweapon.sqf",[], 1, false, true, "", _con];
		if (_mount) then {_unit assignAsGunner _wep; _unit moveInGunner _wep};
		_marker setMarkerPos (getPos _wep);
	} else {
		hint "static setup aborted";
		_unit setVariable ["static", true, true];
		_unit setVariable ["abort", true, true];
	};
} else {
	_action = [_unit,_anim,_buildTimer,(typeOf _obj),"teardown"] spawn _build;
	waitUntil {scriptDone _action};
	if (_unit getVariable ["abort", true]) then {
		deleteMarker (vehicleVarName _obj);
		deleteVehicle _obj;
		_unit setVariable ["static", true, true];
		_null = [_uid,"none"] spawn _status_change;
	};
};
};

Edited by Demonized
added note about naming player unit

Share this post


Link to post
Share on other sites

Very nice Script Demonized!

Thank-you for making it!

I'll be able to throw this on a dedi server soon, and I can tell you what the problems maybe.

-Bigshot

Share this post


Link to post
Share on other sites

This looks great Demonized, ill dl and check it out.

Thanks.

Share this post


Link to post
Share on other sites

Hello I have goggled after a script like for a long time and I found this and just want to tell you that it works fine. I have a question: Is there a way to make you able to place more then just one object or set a limit? as I'm working on a survival map there you are defending a small town and it's going to be MP.

Share this post


Link to post
Share on other sites

Yes you can place more then one static weapon, you need to edit a few little things.

THis is my edited version:

*I have changed sqf name and the unit name in the script so will have to change that back. The unit name in this script is 'Eng1'.

//unit init:   _null = [[["mash",0]],this,"start", 9] execVM "deploy.sqf"; this setGroupid ["Bravo 1"];

//init.sqf:  DMZ_Deploy_Static = [];



_anim = "AmovPercMstpSrasWrflDnon_AinvPknlMstpSlayWrflDnon";  // this is the transition animation used, change to whatever transition animation desired.  other animations found here: [url]http://community.bistudio.com/wiki/ArmA2:_Moves[/url]   -  or search armaholic for animationviewer.
_timer = 0;        // this is the life the static has in seconds before it will despawn automatically and give the user the ability back, set to 0 for never, (default 0 = no timer, needs to be undeployed).
_buildTimer = 2; // this is the timer to assemble/disassemble, set to 10 for now to show bar correctly.
_mount = false;    // set this to true to imediatly move in as gunner after build is completed.

waitUntil {!isNil ("DMZ_Deploy_Static")};
_unit = _this select 1;
if (_unit != Eng1) exitWith {};

// deploy/undeploy show progress function.
_build = {
   _unit = _this select 0;
   if (_unit != Eng1) exitWith {};
   _anim = _this select 1;
   _timer = _this select 2;
   _perc = _timer/10;
   _sel = 0;
   if ("teardown" in _this) then {_sel = 9};
   _bar = [["|________"], ["||________"], ["|||_______"], ["||||______"], ["|||||_____"], ["||||||____"], ["|||||||___"], ["||||||||__"], ["|||||||||_"], ["||||||||||"]];
   _unit playMove _anim;
   waitUntil {(animationState _unit) == _anim};
   waitUntil {(animationState _unit) != _anim};
   //_state = (animationState _unit);  // use to dynamically get end anim of animation transition used, for now its hardcoded below.
   _state = "ainvpknlmstpslaywrfldnon";
   while {_timer != 0} do {
       if ((animationState _unit) == _state) then {
           _text = format["Building %1 \n %2 \n \n move to abort",(_this select 3),(_bar select _sel)];
           cutText [_text,"PLAIN",0];    // this is for text center screen, wich will disapear after completion.
           //hintSilent _text;        // this is for discrete hint in top right corner, wich will stay long time after completion.
           if ("teardown" in _this) then {_sel = _sel - 1} else {_sel = _sel + 1};
           sleep 1; _timer = _timer - 1;
       } else {
           _timer = 0;
           _unit setVariable ["abort", false, true];
           _unit setVariable ["static", true, true];
           waitUntil {!(_unit getVariable ["abort", true])};
       };
       cutText ["","PLAIN",2];
   };
};

// status check function.
_statusChk = {
   if (_this != Eng1) exitWith {};
   _type = "none";
   _wep = "none";
   _uid = "none";
   if (_this in playableUnits) then {_uid = getPlayerUID _this} else {_uid = vehicleVarName _this};
   {if (_uid in _x) then {_type = _x select 1;_wep = _x select 2}} foreach DMZ_Deploy_Static;
   [_type,_wep]
};

// status change function.
_status_change = {
   {if ((_this select 0) in _x) then {_x set [2,(_this select 1)]}} foreach DMZ_Deploy_Static;
   publicVariable "DMZ_Deploy_Static";
};

_uid = "none";
if (Eng1 in playableUnits) then {_uid = getPlayerUID player} else {_uid = vehicleVarName Eng1};
if ("start" in _this) then {
   _type = [];
   _wep = "not";
   if ((count DMZ_Deploy_Static) != 0 AND ({_uid in _x} count DMZ_Deploy_Static) != 0) then {
       while {alive _unit AND _wep != "none"} do {
           _ret = _unit call _statusChk;
           _type = _ret select 0;
           _wep = _ret select 1;
           sleep 1;
       };
   } else {
       _type = _this select 0;
       DMZ_Deploy_Static = DMZ_Deploy_Static + [[_uid,_type,"none"]];
       publicVariable "DMZ_Deploy_Static";

       if (_unit in playableUnits) then {
           _idx = _unit addMPEventHandler ["MPRespawn", {
               _unit = _this select 0;
               _null = _unit spawn {
                   waitUntil {alive _this};
                   if (_this != Eng1) exitWith {};
                   _uid = "none";
                   if (_this in playableUnits) then {_uid = getPlayerUID _this} else {_uid = vehicleVarName _this};
                   _wep = "none";
                   _type = [];
                   _loop = true;
                   while {_loop} do {
                       {if (_uid in _x) then {_type = _x select 1;_wep = _x select 2;if (_wep == "none") then {    _loop = false}}} foreach DMZ_Deploy_Static;
                       sleep 1;
                   };
                   _null = [_type,Eng1,"start"] execVM "deploy_engineer1.sqf";
               };
           }];
       };
   };
   if (alive _unit) then {
       Eng1 setVariable ["static", true, true];
       {
           _dir = 0;
           _obj = _x select 0;
           if ((count _x) == 2) then {_dir = _x select 1};
           _vDName = getText(configFile >> "cfgVehicles" >> _obj >> "displayName");
           _name = format["<t color = '#0000FF'>Build %1</t>",_vDName];
           _id = Eng1 addAction [_name, "deploy_engineer1.sqf", [_obj,_vDName,_dir,"deploy"], 1, false, true, "", "alive _this AND (vehicle _this) == _this AND _target == _this AND _this getVariable ['static', true]"];
       } foreach _type;
   };
} else {
   _obj = _this select 0;
   _id = _this select 2;
   _arg = _this select 3;
   if ("deploy" in _arg) then {
       _unit setVariable ["static", false, true];
       _dir = getDir _unit;
       _pos = getPos _unit;
       _cd = _dir mod 360;
       _newX = (_pos select 0) + (sin _cd * 1);
       _newY = (_pos select 1) + (cos _cd * 1);
       _newZ = (_pos select 2)-0.03;

//Switch for single build or multi build (fals,true) is single, (true,true) is multi
       _unit setVariable ["static", true, true];
       _action = [_unit,_anim,_buildTimer,(_arg select 1)] spawn _build;
       waitUntil {scriptDone _action};

       if (_unit getVariable ["abort", true]) then {
           _vName = format["DMZ_Static_Weapon_%1",_unit];
           _wep = createVehicle [(_arg select 0), [0,0,500], [], 0, "NONE"];
           _wep SetVehicleVarName _vName;
           _wep Call Compile Format ["%1=_This ; PublicVariable ""%1""",_vName];

         //  _marker = createMarker[_vName,[0,0,0]];
         //  _marker setMarkerShape "ICON";
         //  _marker setMarkerType "DOT";
         //  _marker setMarkerColor "ColorBlue";
         //  _vDName = format["%1s %2",(name Eng1),(getText(configFile >> "cfgVehicles" >> (typeOf _wep) >> "displayName"))];
         //  _marker setMarkerText _vDName;

           _null = [_uid,(vehicleVarName _wep)] spawn _status_change;
           if (_timer != 0) then {
               _null = [_wep,_unit,_timer,_uid,_marker] spawn {
                   _obj = _this select 0;
                   _unit = _this select 1;
                   _uid = _this select 3;
                   sleep (_this select 2);
                   if (!isNull _obj) then {deleteVehicle _obj};
                   deleteMarker (_this select 4);
                   _unit setVariable ["static", true, true];
                   {if (_uid in _x) then {_x set [2, "none"]}} foreach DMZ_Deploy_Static;
                   publicVariable "DMZ_Deploy_Static";
               };
           };
           if ((count _Arg) == 4) then {_dir = _dir + (_arg select 2)};
           _wep setDir _dir;
           _wep setPos [_newX,_newY,_newZ];
           _con = format["_this == %1 AND (vehicle _this) == _this",_unit];
           _wep addAction ["Remove fortification", "deploy_engineer1.sqf",[], 1, false, true, "", _con];
           if (_mount) then {_unit assignAsGunner _wep; _unit moveInGunner _wep};
           _marker setMarkerPos (getPos _wep);
       } else {
          // hint "static setup aborted";
           _unit setVariable ["static", true, true];
           _unit setVariable ["abort", true, true];
       };
   } else {
       _action = [_unit,_anim,_buildTimer,(typeOf _obj),"teardown"] spawn _build;
       waitUntil {scriptDone _action};
       if (_unit getVariable ["abort", true]) then {
           deleteMarker (vehicleVarName _obj);
           deleteVehicle _obj;
           _unit setVariable ["static", true, true];
           _null = [_uid,"none"] spawn _status_change;
       };
   };
};

Share this post


Link to post
Share on other sites
Yes you can place more then one static weapon, you need to edit a few little things.

THis is my edited version:

*I have changed sqf name and the unit name in the script so will have to change that back. The unit name in this script is 'Eng1'.

//unit init:   _null = [[["mash",0]],this,"start", 9] execVM "deploy.sqf"; this setGroupid ["Bravo 1"];

//init.sqf:  DMZ_Deploy_Static = [];



_anim = "AmovPercMstpSrasWrflDnon_AinvPknlMstpSlayWrflDnon";  // this is the transition animation used, change to whatever transition animation desired.  other animations found here: [url]http://community.bistudio.com/wiki/ArmA2:_Moves[/url]   -  or search armaholic for animationviewer.
_timer = 0;        // this is the life the static has in seconds before it will despawn automatically and give the user the ability back, set to 0 for never, (default 0 = no timer, needs to be undeployed).
_buildTimer = 2; // this is the timer to assemble/disassemble, set to 10 for now to show bar correctly.
_mount = false;    // set this to true to imediatly move in as gunner after build is completed.

waitUntil {!isNil ("DMZ_Deploy_Static")};
_unit = _this select 1;
if (_unit != Eng1) exitWith {};

// deploy/undeploy show progress function.
_build = {
   _unit = _this select 0;
   if (_unit != Eng1) exitWith {};
   _anim = _this select 1;
   _timer = _this select 2;
   _perc = _timer/10;
   _sel = 0;
   if ("teardown" in _this) then {_sel = 9};
   _bar = [["|________"], ["||________"], ["|||_______"], ["||||______"], ["|||||_____"], ["||||||____"], ["|||||||___"], ["||||||||__"], ["|||||||||_"], ["||||||||||"]];
   _unit playMove _anim;
   waitUntil {(animationState _unit) == _anim};
   waitUntil {(animationState _unit) != _anim};
   //_state = (animationState _unit);  // use to dynamically get end anim of animation transition used, for now its hardcoded below.
   _state = "ainvpknlmstpslaywrfldnon";
   while {_timer != 0} do {
       if ((animationState _unit) == _state) then {
           _text = format["Building %1 \n %2 \n \n move to abort",(_this select 3),(_bar select _sel)];
           cutText [_text,"PLAIN",0];    // this is for text center screen, wich will disapear after completion.
           //hintSilent _text;        // this is for discrete hint in top right corner, wich will stay long time after completion.
           if ("teardown" in _this) then {_sel = _sel - 1} else {_sel = _sel + 1};
           sleep 1; _timer = _timer - 1;
       } else {
           _timer = 0;
           _unit setVariable ["abort", false, true];
           _unit setVariable ["static", true, true];
           waitUntil {!(_unit getVariable ["abort", true])};
       };
       cutText ["","PLAIN",2];
   };
};

// status check function.
_statusChk = {
   if (_this != Eng1) exitWith {};
   _type = "none";
   _wep = "none";
   _uid = "none";
   if (_this in playableUnits) then {_uid = getPlayerUID _this} else {_uid = vehicleVarName _this};
   {if (_uid in _x) then {_type = _x select 1;_wep = _x select 2}} foreach DMZ_Deploy_Static;
   [_type,_wep]
};

// status change function.
_status_change = {
   {if ((_this select 0) in _x) then {_x set [2,(_this select 1)]}} foreach DMZ_Deploy_Static;
   publicVariable "DMZ_Deploy_Static";
};

_uid = "none";
if (Eng1 in playableUnits) then {_uid = getPlayerUID player} else {_uid = vehicleVarName Eng1};
if ("start" in _this) then {
   _type = [];
   _wep = "not";
   if ((count DMZ_Deploy_Static) != 0 AND ({_uid in _x} count DMZ_Deploy_Static) != 0) then {
       while {alive _unit AND _wep != "none"} do {
           _ret = _unit call _statusChk;
           _type = _ret select 0;
           _wep = _ret select 1;
           sleep 1;
       };
   } else {
       _type = _this select 0;
       DMZ_Deploy_Static = DMZ_Deploy_Static + [[_uid,_type,"none"]];
       publicVariable "DMZ_Deploy_Static";

       if (_unit in playableUnits) then {
           _idx = _unit addMPEventHandler ["MPRespawn", {
               _unit = _this select 0;
               _null = _unit spawn {
                   waitUntil {alive _this};
                   if (_this != Eng1) exitWith {};
                   _uid = "none";
                   if (_this in playableUnits) then {_uid = getPlayerUID _this} else {_uid = vehicleVarName _this};
                   _wep = "none";
                   _type = [];
                   _loop = true;
                   while {_loop} do {
                       {if (_uid in _x) then {_type = _x select 1;_wep = _x select 2;if (_wep == "none") then {    _loop = false}}} foreach DMZ_Deploy_Static;
                       sleep 1;
                   };
                   _null = [_type,Eng1,"start"] execVM "deploy_engineer1.sqf";
               };
           }];
       };
   };
   if (alive _unit) then {
       Eng1 setVariable ["static", true, true];
       {
           _dir = 0;
           _obj = _x select 0;
           if ((count _x) == 2) then {_dir = _x select 1};
           _vDName = getText(configFile >> "cfgVehicles" >> _obj >> "displayName");
           _name = format["<t color = '#0000FF'>Build %1</t>",_vDName];
           _id = Eng1 addAction [_name, "deploy_engineer1.sqf", [_obj,_vDName,_dir,"deploy"], 1, false, true, "", "alive _this AND (vehicle _this) == _this AND _target == _this AND _this getVariable ['static', true]"];
       } foreach _type;
   };
} else {
   _obj = _this select 0;
   _id = _this select 2;
   _arg = _this select 3;
   if ("deploy" in _arg) then {
       _unit setVariable ["static", false, true];
       _dir = getDir _unit;
       _pos = getPos _unit;
       _cd = _dir mod 360;
       _newX = (_pos select 0) + (sin _cd * 1);
       _newY = (_pos select 1) + (cos _cd * 1);
       _newZ = (_pos select 2)-0.03;

//Switch for single build or multi build (fals,true) is single, (true,true) is multi
       _unit setVariable ["static", true, true];
       _action = [_unit,_anim,_buildTimer,(_arg select 1)] spawn _build;
       waitUntil {scriptDone _action};

       if (_unit getVariable ["abort", true]) then {
           _vName = format["DMZ_Static_Weapon_%1",_unit];
           _wep = createVehicle [(_arg select 0), [0,0,500], [], 0, "NONE"];
           _wep SetVehicleVarName _vName;
           _wep Call Compile Format ["%1=_This ; PublicVariable ""%1""",_vName];

         //  _marker = createMarker[_vName,[0,0,0]];
         //  _marker setMarkerShape "ICON";
         //  _marker setMarkerType "DOT";
         //  _marker setMarkerColor "ColorBlue";
         //  _vDName = format["%1s %2",(name Eng1),(getText(configFile >> "cfgVehicles" >> (typeOf _wep) >> "displayName"))];
         //  _marker setMarkerText _vDName;

           _null = [_uid,(vehicleVarName _wep)] spawn _status_change;
           if (_timer != 0) then {
               _null = [_wep,_unit,_timer,_uid,_marker] spawn {
                   _obj = _this select 0;
                   _unit = _this select 1;
                   _uid = _this select 3;
                   sleep (_this select 2);
                   if (!isNull _obj) then {deleteVehicle _obj};
                   deleteMarker (_this select 4);
                   _unit setVariable ["static", true, true];
                   {if (_uid in _x) then {_x set [2, "none"]}} foreach DMZ_Deploy_Static;
                   publicVariable "DMZ_Deploy_Static";
               };
           };
           if ((count _Arg) == 4) then {_dir = _dir + (_arg select 2)};
           _wep setDir _dir;
           _wep setPos [_newX,_newY,_newZ];
           _con = format["_this == %1 AND (vehicle _this) == _this",_unit];
           _wep addAction ["Remove fortification", "deploy_engineer1.sqf",[], 1, false, true, "", _con];
           if (_mount) then {_unit assignAsGunner _wep; _unit moveInGunner _wep};
           _marker setMarkerPos (getPos _wep);
       } else {
          // hint "static setup aborted";
           _unit setVariable ["static", true, true];
           _unit setVariable ["abort", true, true];
       };
   } else {
       _action = [_unit,_anim,_buildTimer,(typeOf _obj),"teardown"] spawn _build;
       waitUntil {scriptDone _action};
       if (_unit getVariable ["abort", true]) then {
           deleteMarker (vehicleVarName _obj);
           deleteVehicle _obj;
           _unit setVariable ["static", true, true];
           _null = [_uid,"none"] spawn _status_change;
       };
   };
};

:colgate: Thanks man It was a pain to change every thing but it works fine now I will be able to continue to build om my mission. Again Thank you!

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
Sign in to follow this  

×