Jump to content
davidoss

Release Trench digging script

Recommended Posts

Trenches , digg cover for your self if you not able to find any..

 

usage:
place scripts dirctory in your mission root directory
add lines in:

 

init.sqf

if (hasInterface) then {
	0 = [] spawn compile preprocessFileLineNumbers "scripts\lib_trenches\trenches.sqf";
	player addEventHandler ["Respawn", {
		0 = [] spawn compile preprocessFileLineNumbers "scripts\lib_trenches\trenches.sqf";
	}];
};

 

description.ext

class CfgSFX
{

	class digging_sound
	{
		sound0[] = {"scripts\lib_trenches\sounds\ShovelDigging.ogg", db-0, 1.0, 100, 0.2, 99, 99, 99};
		sounds[] = {sound0};
		empty[] = {"", 0, 0, 0, 0, 0, 0, 0};
	};

};

class CfgVehicles
{
	class player_digging_sound 
	{
		sound = "digging_sound";
	};
};

 

 

 

script overwiev:

trenches.sqf

/*
by DaVidoSS
Digging trenches for cover

usage:
place scripts directory in your mission root directory
add lines in:

init.sqf

if (hasInterface) then {
	0 = [] spawn compile preprocessFileLineNumbers "scripts\lib_trenches\trenches.sqf";
	player addEventHandler ["Respawn", {
		0 = [] spawn compile preprocessFileLineNumbers "scripts\lib_trenches\trenches.sqf";
	}];
};

description.ext

class CfgSFX
{

	class digging_sound
	{
		sound0[] = {"scripts\lib_trenches\sounds\ShovelDigging.ogg", db-0, 1.0, 100, 0.2, 99, 99, 99};
		sounds[] = {sound0};
		empty[] = {"", 0, 0, 0, 0, 0, 0, 0};
	};

};

class CfgVehicles
{
	class player_digging_sound 
	{
		sound = "digging_sound";
	};
};

*/


if !(hasInterface) exitWith {};
waitUntil {!isNull player};
waitUntil {player == player};

player addAction [
	"<t>Dig Trench </t><img size='1' image='\a3\ui_f\data\IGUI\Cfg\Actions\Obsolete\ui_action_turnin_ca'/>",
	{
		params [["_target",objNull,[objNull]],["_unit",objNull,[objNull]]];
		(AGLToASL (_unit modelToWorldVisual [0,1.5,0])) params ["_vx","_vy","_vz"];
		if !(isNull (objectParent _unit)) exitWith {0 = [[format ["<t  size='.8'> %1</t>","Really? While driving?"],1,1,5]] spawn BIS_fnc_EXP_camp_SITREP};
		if (surfaceIsWater (position _unit)) exitWith {0 = [[format ["<t  size='.8'> %1</t>","Oh come on, you cant be that stupid!"],1,1,5]] spawn BIS_fnc_EXP_camp_SITREP}; 
		if !(count (lineIntersectsObjs [(AGLToASL (_unit modelToWorldVisual [0,1.5,0])), [_vx,_vy,(_vz + 20)]]) == 0) exitWith {0 = [[format ["<t  size='.8'> %1</t>","Open your eyes, no suitable space here!"],1,1,5]] spawn BIS_fnc_EXP_camp_SITREP};
		if (!(isTouchingGround _unit ) || {((getPosATL _unit) select 2) > 0.2}) exitWith {0 = [[format ["<t  size='.8'> %1</t>","Ok, but hit the ground first!"],1,1,5]] spawn BIS_fnc_EXP_camp_SITREP};
		if (isOnRoad (ASLToAGL (getPosASL _unit))) exitWith {0 = [[format ["<t  size='.8'> %1</t>","Sorry, solid ground here!"],1,1,5]] spawn BIS_fnc_EXP_camp_SITREP}; 
		_unit setVariable ["digging",true,false];
		_unit playMove "AinvPknlMstpSnonWnonDnon_medic_1";
		//playSound3D [getMissionPath "scripts\lib_trenches\sounds\ShovelDigging.ogg", _unit, false, getPosASL _unit, 3, 1, 25];// in MP others cant hear the shovel - switched to soundsource
		private _diggsnd = createSoundSource ["player_digging_sound", _unit, [], 0];
		waituntil { animationState _unit == "ainvpknlmstpsnonwnondnon_medic_1"};
		sleep 4;
		private _trench = createVehicle ["Land_ShellCrater_02_small_F",_target modelToWorld [0,2,0], [], 0, "CAN_COLLIDE"];
		deleteVehicle _diggsnd;
		_trench setDir (getDir _target - 90);
		private _radGrad = ([getPos _trench, getDir _target] call BIS_fnc_terrainGradAngle)/30;
		_trench setVectorUp (surfacenormal (getPosATL _trench));
		private _posASL = getPosASL _trench; 
		_trench setPosASL [_posASL  select 0,_posASL select 1, ((_posASL select 2) + _radGrad)];
		_unit setVariable ["digging",nil,false];
		_unit setVariable ["mytrench",_trench,false];
		0 = [_trench,
			[
				"<t>Remove Trench </t><img size='1' image='\a3\ui_f\data\IGUI\Cfg\Actions\Obsolete\ui_action_turnout_ca'/>",
				{
					params [["_target",objNull,[objNull]],["_unit",objNull,[objNull]]];
					_unit setVariable ["digging",true,false];
					_unit playMove "AinvPknlMstpSnonWnonDnon_medic_1";
					//playSound3D ["A3\sounds_f\characters\human-sfx\01_medikit1.wss", _unit, false, getPosASL _unit, 3, 1, 25]; // in MP others cant hear the shovel - switched to soundsource
					private _diggsnd = createSoundSource ["player_digging_sound", _unit, [], 0];
					waituntil { animationState _unit == "ainvpknlmstpsnonwnondnon_medic_1"};
					sleep 4;
					deleteVehicle _target;
					deleteVehicle _diggsnd;
					_unit setVariable ["digging",nil,false];
				},nil,0,true,true,"","(isNil {_this getVariable 'digging'})",3,false,"",""
			]
		] remoteExec ["addAction", [0,-2] select isDedicated,_trench];	
	},nil,0,false,true,"",
	"isNull (_this getVariable ['mytrench',objNull]) &&  {isNil {_this getVariable 'digging'}} && {((animationState _this) in 
	[
		'amovpknlmstpsraswpstdnon',
		'amovpknlmstpslowwpstdnon',
		'amovppnemstpsraswpstdnon',
		'amovpknlmstpsraswrfldnon',
		'amovpknlmstpslowwrfldnon',
		'amovppnemstpsraswrfldnon',
		'amovpknlmstpsraswlnrdnon',
		'amovpknlmstpsnonwnondnon',
		'amovppnemstpsnonwnondnon'
	])}", -1, false, "", ""];
	
0 = [[format ["<t  size='.8'> %1</t>","TRENCH Started"],1,1,5]] spawn BIS_fnc_EXP_camp_SITREP;

 

 

Trenches

  • Thanks 5

Share this post


Link to post
Share on other sites

Cool love the idea! Some screenshots and maybe a video for demonstration would be inspiring.

How would you "dig" a trench though, do you need a shovel from something, like say ACE, or does the script add one?

 

Wouldn't a foxhole be more ideal, i mean a trench is fairly big, i remember in OFP's mod  Liberation 1941-45 there was a menu with various trench types

you could build, and when you chose it, and started digging, you could even assign AI to dig it, and each thing you chose it would say how

long it would take to create in the menu, was pretty cool especially for OFP!

  • Like 1

Share this post


Link to post
Share on other sites

Hi,

 not sure if a mod if stopping this working for me, but i have followed the instructions above and i get no addaction to build a trench. No errors, no nothing.

 

When i start my mission i noticed the it says trench started in the bottom right, but other than that nothing.

 

Any ideas?

Share this post


Link to post
Share on other sites

It starts because it says TTRENCHES on the left side of the screen but no addAction on player or anything?

Share this post


Link to post
Share on other sites

Adding to this thread, for the two previous comments asking and pointing out that the script or the ability to dig a trench

dont work for them, you have to crouch for the addaction to show in your action menu.

 

Also adding to this, i installed this script, tested it out, figured out how to dig the trench, now the original script in the OP

will only allow you to build (dig) one trench, however i went to my friend Rydygier with an idea on how to increase the number

of trenches you can build, and now its possible.   Credits: Rydygier

 

For those of you whom are interested in this script and its function, i have a video below here demonstrating

how it works, and review the script, theres also a link below the video here where i have uploaded the script as you

see it in the video with the ability to build more then one trench.

Download the updated version: LINK

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

This and this need to get married. Have the trench make a depression and put the crater stuff around the top or not, it doesn't have to. I have no clue how to do it.

 

  • Like 1

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

×