Jump to content
Sign in to follow this  

Recommended Posts

so i have working on a script that allows a player to attach explosives to a wall/vehicle and the only problem is that the action menu for the and i am sure its not the only problem IEDs don't work here is the script

btw the folder layout is as follows

mission folder>

init.sqf

attach_explosives

placement_func>

action_c4

attach_c4

fnc_get_angle

init.sqf

nul = [] execVM "attach_explosives.sqf";

attach_explosives.sqf

if (isserver) then { 


};

if (isnil("fnc_action_c4")) then {
	fnc_action_c4 = compile loadfile "placement_func\action_c4.sqf";
};




_debug = 0;

_unit = player;
nearbuildlist = [];
clearbuildlist = [];

// make units detect c4 around them to interact with

	nul = [_unit] spawn fnc_action_c4;
	nul = [_unit] spawn {

		_unit = _this select 0;
		while {alive _unit} do {

			_pos = getposATL _unit;

			buildlist = nearestobjects [_pos,["house"],300];
			nearbuildlist = nearestobjects [_pos,["house"],75];
			clearbuildlist = buildlist - nearbuildlist;	

		sleep 20;

		};

	};	

};

sleep 1;

action_c4


	private ['_unit'];
	_unit = _this select 0;


	while {alive _unit} do {

		_proximity = (getposATL _unit) nearobjects ["all",3];

		{

			if (_x iskindof "ACE_c4") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach C4","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};

			if (_x iskindof "ACE_c4_m") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach C4","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};
			if (_x iskindof "ACE_DM12B1_M") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach C4","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};

			if (_x iskindof "ACE_Pipebomb") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach Satchel","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};


			if (_x iskindof "BAF_ied_v1") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach IED","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};


			if (_x iskindof "BAF_ied_v2") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach IED","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};


			if (_x iskindof "BAF_ied_v3") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach IED","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};


			if (_x iskindof "BAF_ied_v4") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach IED","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};


			if (_x iskindof "PMC_ied_v1") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach IED","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};

			if (_x iskindof "PMC_ied_v2") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach IED","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};

			if (_x iskindof "PMC_ied_v3") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach IED","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};


			if (_x iskindof "PMC_ied_v4") then {

				_c4 = _proximity select (_proximity find _x);

				_idact = _unit addaction ["Attach IED","placement_func\attach_c4.sqf",[_unit,_c4]];
				waituntil {(_unit distance _c4) > 3};
				_unit removeaction _idact;	

			};

		} foreach _proximity;

	sleep 0.5;

	};


attach_c4

_args = _this select 3;
_unit  = _args select 0;
_item = _args select 1;
_dist = 3;
_array = [];

_upos = getposATL _unit;
_eyes = eyepos _unit;
_angle = (getdir _unit);
_zdif = ((_eyes select 2) - (_upos select 2));

if (isnil("fnc_get_angle")) then {
fnc_get_angle = compile loadfile "placement_func\fnc_get_angle.sqf"

};

if (isnil("fnc_intersects")) then {


fnc_intersects = compile "
	private ['_unit','_pos','_angle','_front'];
	_unit = _this select 0;
	_pos = _this select 1;
	_checkdist = _this select 2;
	_angle = _this select 3;

	_hyp = _checkdist;
	_adj = _hyp * (cos _angle);
	_opp = sqrt ((_hyp*_hyp) - (_adj * _adj));

	_front = if ((_angle) >=  180) then {

		[(_pos select 0) - _opp,(_pos select 1) + _adj,(_pos select 2)]

	} else {

		[(_pos select 0) + _opp,(_pos select 1) + _adj,(_pos select 2)]

	};

	_object = (lineintersectswith [_pos,_front,_unit]) select 0;

	_obstructed = if (isnil('_object')) then {false} else {true};

	[_obstructed,_front,_object]";

};

_array = [_unit,_eyes,_dist,_angle] call fnc_intersects;
_obstructed = _array select 0;
_obstruction = _array select 2;

if (!(_obstructed)) exitwith {
nul = [] spawn {hintsilent "Move closer to the wall"; sleep 5 ;hintsilent "";};
};

while {_obstructed} do {

_dist = _dist - 1;
_array = [_unit,_eyes,_dist,_angle] call fnc_intersects;
_obstructed = _array select 0;

};

_infront = _array select 1;

while {!(_obstructed)} do {

_dist = _dist + 0.1;
_array = [_unit,_eyes,_dist,_angle] call fnc_intersects;
_obstructed = _array select 0;

};

while {_obstructed} do {

_dist = _dist - 0.01;
_array = [_unit,_eyes,_dist,_angle] call fnc_intersects;
_obstructed = _array select 0;

};

_infront = _array select 1;
_infront set [2,(_infront select 2) - _zdif];

















_angle = _angle + 2;
_dist = 3;

_angle = if (_angle > 360) then {_angle - 360} else {_angle};

_array = [_unit,_eyes,_dist,_angle] call fnc_intersects;
_obstructed = _array select 0;
_obstruction = _array select 2;

if (!(_obstructed)) exitwith {
nul = [] spawn {hintsilent "Move closer to the wall"; sleep 5 ;hintsilent "";};
};


while {_obstructed} do {

_dist = _dist - 1;
_array = [_unit,_eyes,_dist,_angle] call fnc_intersects;
_obstructed = _array select 0;

};

_infront2 = _array select 1;

while {!(_obstructed)} do {

_dist = _dist + 0.1;
_array = [_unit,_eyes,_dist,_angle] call fnc_intersects;
_obstructed = _array select 0;

};

while {_obstructed} do {

_dist = _dist - 0.01;
_array = [_unit,_eyes,_dist,_angle] call fnc_intersects;
_obstructed = _array select 0;

};

_infront2 = _array select 1;
_infront2 set [2,(_infront2 select 2) - _zdif];

_bdir = getdir _obstruction;
_sdir = [_infront,_infront2] call fnc_get_angle;

_dirdiff = _bdir - _sdir;
if (_dirdiff < 0) then {_dirdiff = _dirdiff + 360};

if ((_item iskindof "ACE_c4") or (_item iskindof "ACE_c4_m") or (_item iskindof "ACE_DM12B1_M")) then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	[_item,90,0] call fnc_setpitchbank;
	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,0] call fnc_setpitchbank;	
	_item setvectordir _vdir;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;
	[_item,0,270] call fnc_setpitchbank;

};

};

if ((_item iskindof "ACE_Pipebomb") or (_item iskindof "Pipebomb")) then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,90] call fnc_setpitchbank;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;

};

};

if (_item iskindof "BAF_ied_v1") then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	[_item,90,0] call fnc_setpitchbank;
	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,0] call fnc_setpitchbank;	
	_item setvectordir _vdir;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;
	[_item,0,270] call fnc_setpitchbank;

};

};

if ((_item iskindof "PMC_ied_v1") then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,90] call fnc_setpitchbank;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;

};

};

if (_item iskindof "BAF_ied_v2") then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	[_item,90,0] call fnc_setpitchbank;
	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,0] call fnc_setpitchbank;	
	_item setvectordir _vdir;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;
	[_item,0,270] call fnc_setpitchbank;

};

};

if ((_item iskindof "BAF_ied_v4") then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,90] call fnc_setpitchbank;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;

};

};
if (_item iskindof "BAF_ied_v3") then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	[_item,90,0] call fnc_setpitchbank;
	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,0] call fnc_setpitchbank;	
	_item setvectordir _vdir;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;
	[_item,0,270] call fnc_setpitchbank;

};

};

if ((_item iskindof "PMC_ied_v2") then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,90] call fnc_setpitchbank;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;

};

};
if (_item iskindof "PMC_ied_v3") then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	[_item,90,0] call fnc_setpitchbank;
	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,0] call fnc_setpitchbank;	
	_item setvectordir _vdir;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;
	[_item,0,270] call fnc_setpitchbank;

};

};

if ((_item iskindof "PMC_ied_v4") then {

if (_obstruction iskindof "LandVehicle") then {


	_cardimentions = boundingbox _obstruction;
	_carheight = ((_cardimentions select 1) select 2) - ((_cardimentions select 0) select 2);

	_c4height = if (_carheight >= 4) then {1.2} else {0.7};	

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + _c4height)];

	_vdir = vectordir _item;

	_wtmpos = _obstruction worldtomodel (getposATL _item);
	_item attachto [_obstruction,_wtmpos];

	[_item,90,90] call fnc_setpitchbank;

} else {

	_item setpos [(_infront select 0),(_infront select 1),((_upos select 2) + 1.2)];

	_item setdir _sdir;

};

};

fnc_get_angle

_obj1 = _this select 0;
_obj2 = _this select 1;

_pos1 = if ((typename _obj1) == "Array") then {_obj1} else {getposATL _obj1};
_pos2 = if ((typename _obj2) == "Array") then {_obj2} else {getposATL _obj2};


_hyp = _pos1 distance _pos2;
if (_hyp == 0) then {_hyp = 0.1};
_adj = (_pos1 select 1) - (_pos2 select 1);



_angle = if ((_pos1 select 0) > (_pos2 select 0)) then {

acos (_adj/_hyp);

} else {

360 - (acos (_adj/_hyp));

};

_angle

thanks for your help!!

Edited by TrevorMcNeill

Share this post


Link to post
Share on other sites

its fine what sucks is that that's all that's left are the ieds and it will be finished

Share this post


Link to post
Share on other sites

I couldn't implement it to test it. I kept getting errors. If you could put it in a mission and upload it I'd take another look.

Share this post


Link to post
Share on other sites
I couldn't implement it to test it. I kept getting errors. If you could put it in a mission and upload it I'd take another look.

will do here is a google doc upload but i was running mods so just depbo it and just put everything but the mission file into your own mission folder

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  

×