Jump to content

[Release] Enhanced Vehicle Deployment (with right click option)


Recommended Posts

There are many deployable vehicle scripts out there; however, every single one of them that I've come across used multiple scripts for the deployment and packing of each vehicle. Thinking that there was a better way to do it, I started working to create "one set of scripts to rule them all". The goal was to reduce the overall size of the script by consolidating everything into a single deploy and packing script and make it a little easier to modify by server admins. I also took the opportunity to fix what I felt where exploits that players could abuse.
 

Features

  • Deployable mountain bike, motorcycle, and Mozzie.
  • Easy to configure required materials for each vehicle.
  • Right click on toolbox to deploy vehicles.
  • Stop deployment/packing of vehicles by moving.
  • Prevent packing of destroyed deployable vehicles.
  • Prevent packing of locked vehicles.
  • Allow for selling of deployable vehicles (configurable by the admin).
  • Remove deployable vehicles from hive to prevent them from respawning on reset. (Infinite parts exploit)
  • Materials are dropped on the ground when packing like the other remove actions (workbench, wreckage, weapons crates) instead of automatically added to the player's inventory.
  • Remove ammo from all vehicles when deployed. (Infinite grenades exploit with Mozzie)

Credits

  • oOSmokyOo for on which this one was developed from.
  • maca134 for his wonderful Right Click Options To Items script.
  • TheVampire whose DZMS gave me plenty of ideas on how to rework this script.
  • [VB]AWOL whose code in player_craftItem.sqf and remove.sqf I referenced for some parts of the deployment script.

Requirements

  • Knowledge of how to unpacking pbo's.
  • A text editor (Notepad++ recommended)

Installation

 

Step 1: Custom variables.sqf

 
If you do not have a custom variables.sqf, create an empty file in the custom scripts directory of your mission folder. Edit it to include the following:

EVDVehicleArray = ["MMT_Civ","TT650_Civ","CSJ_GyroC"];
dayz_allowedObjects = dayz_allowedObjects + EVDVehicleArray;

if(isServer) then {
	DZE_safeVehicle = DZE_safeVehicle + EVDVehicleArray;
};

If you already have a custom variables.sqf, then add the above code to the bottom.
 

Step 2: Custom compiles.sqf

 
If you do not have a custom compiles.sqf, create an empty file the custom scripts directory of your mission folder. Edit it to include the following:

if (!isDedicated) then {
	fnc_usec_selfActions =			compile preprocessFileLineNumbers "SCRIPT_PATH\fn_selfActions.sqf";
	player_selectSlot =				compile preprocessFileLineNumbers "SCRIPT_PATH\ui_selectSlot.sqf";
};

Where "SCRIPT_PATH" is the path of you custom scripts folder from your mission folder. If you already have a custom compiles.sql, then add/modify fnc_usec_selfActions and player_selectSlot depending on the style of custom compiles.sql you are using.
 

Step 3: Modify init.sqf

 
Next open the mission's init.sqf and search for the following:

call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\variables.sqf";

Below it, add:

call compile preprocessFileLineNumbers "SCRIPT_PATH\variables.sqf";

Next, find the following:

call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\compiles.sqf";

Below it, add:

call compile preprocessFileLineNumbers "SCRIPT_PATH\compiles.sqf";	//Compile custom functions

You now have a custom variable.sqf and compiles.sqf, which will be used by other scripts and modifications.
 

Step 4:  Custom ui_selectSlot.sqf

 
Unpack dayz_code.pbo and copy dayz_code\compile\ui_selectSlot.sqf to your custom scripts folder. Open your copied ui_selectSlot.sqf and search for the following around line 57:

_pos set [3,_height];

Above it add the following:

	// Add extra context menus
	_erc_cfgActions = (missionConfigFile >> "ExtraRc" >> _item);
	_erc_numActions = (count _erc_cfgActions);
	if (isClass _erc_cfgActions) then {
		for "_j" from 0 to (_erc_numActions - 1) do {
			_menu =  _parent displayCtrl (1600 + _j + _numActions);
			_menu ctrlShow true;
			_config =  (_erc_cfgActions select _j);
			_text =  getText (_config >> "text");
			_script =  getText (_config >> "script");
			_height = _height + (0.025 * safezoneH);
			uiNamespace setVariable ['uiControl', _control];
			_menu ctrlSetText _text;
			_menu ctrlSetEventHandler ["ButtonClick",_script];
		};
	};

Step 5: Modify description.ext

 
Open description.ext in your mission folder. At the very bottom of description.ext, add:

#include "SCRIPT_PATH\extra_rc.hpp"

Step 6: Create extra_rc.hpp

 
Next, create an empty file named extra_rc.hpp in your custom scripts folder. Inside the file, add the following:

class ExtraRc {
	class ItemToolbox {
		class BuildBike {
			text = "Deploy Bike";
			script = "['MMT_Civ'] execVM 'SCRIPT_PATH\EVD\EVD_deploy.sqf'";
		};
		class BuildMotorcycle {
			text = "Deploy Motorcycle";
			script = "['TT650_Civ'] execVM 'SCRIPT_PATH\EVD\EVD_deploy.sqf'";
		};
		class BuildMozzie {
			text = "Deploy Mozzie";
			script = "['CSJ_GyroC'] execVM 'SCRIPT_PATH\EVD\EVD_deploy.sqf'";
		};
	};
};

If you already have Right Click Options To Items installed and have other scripts that use it, your extra_rc.hpp will look similar to this:

class ExtraRc {
	class ItemBloodbag {
		class Use {
			text = "Use Bloodbag";
			script = "execVM 'SCRIPT_PATH\SelfBB\SelfBB.sqf'";
		};
	};
	class ItemToolbox {
		class BuildBike {
			text = "Deploy Bike";
			script = "['MMT_Civ'] execVM 'SCRIPT_PATH\EVD\EVD_deploy.sqf'";
		};
		class BuildMotorcycle {
			text = "Deploy Motorcycle";
			script = "['TT650_Civ'] execVM 'SCRIPT_PATH\EVD\EVD_deploy.sqf'";
		};
		class BuildMozzie {
			text = "Deploy Mozzie";
			script = "['CSJ_GyroC'] execVM 'SCRIPT_PATH\EVD\EVD_deploy.sqf'";
		};
	};
};

Step 7: Custom fn_selfActions.sqf

 
Copy dayz_code\compile\fn_selfActions.sqf to your custom scripts folder. Open your copied fn_selfActions.sqf and search for the following:

	// All Traders
	if (_isMan and !_isPZombie and _traderType in serverTraders) then {

Above it, add the following:

	//Pack Vehicles
	if (_typeOfCursorTarget in EVDVehicleArray and _hasToolbox and !(locked _cursorTarget) and (damage _cursorTarget < 1)) then {
		if (s_player_packvehicle < 0) then {
			s_player_packvehicle = player addAction ["Pack Vehicle", "SCRIPT_PATH\EVD\EVD_pack.sqf",_cursorTarget, 0, false, true, "",""];
		};
	} else {
		player removeAction s_player_packvehicle;
		s_player_packvehicle = -1;
	};

Step 8: The finishing touches

 
Download the attached file and unzip it into your custom scripts directory. Edit EVD\EVD_deploy.sqf and EVD\EVD_pack.sqf and change SCRIPT_PATH to the path of your custom scripts directory. Finally, edit EVD\EVD_common.sqf to configure the script to suit your tastes. If you add more vehicles as deplorable, you will need to add the class names to EVDVehicleArray in your custom variables.sqf, modify extra_rc.hpp to add an additional option, and add the required materials to the EVDGetMaterials function in EVD\EVD_common.sqf.
 

Future plans

 
A few features that did not make it into this release are the ability to save deployable vehicles to the hive, a check to make sure the vehicle is unoccupied when packed, and the option to turn on or off the able to deploy/pack a vehicle while in combat (the latter gave me a bugger of a time despite it appearing to be a simple matter).

EVD.zip

Link to comment
Share on other sites

Some notes:
 

1. You should mention that you need to edit EVD\EVD_Deploy.sqf, line 5 and change SCRIPT_PATH to match your server

2. Same with EVD_Pack.sqf

3. Maybe just define the variable SCRIPT_PATH so it's easy to configure the entire package.  You may want to change the variable name but it would cut down implementation time significantly. 

 

As an added bonus, the pack feature works for spawned vehicles too, so I'm going to change my menu to say "Dismantle Vehicle" if you don't mind.

 

As a suggestion, you could add a chance that you break something taking it apart.  Also, I didn't notice a requirement for a toolbox.  For realism you may want to add that in.

 

Great job though, I like this feature.  If you want to check it out on my server let me know.

Link to comment
Share on other sites

Some notes:

 

1. You should mention that you need to edit EVD\EVD_Deploy.sqf, line 5 and change SCRIPT_PATH to match your server

2. Same with EVD_Pack.sqf

3. Maybe just define the variable SCRIPT_PATH so it's easy to configure the entire package.  You may want to change the variable name but it would cut down implementation time significantly.

I actually mention that SCRIPT_PATH needs to be changed in both EVD\EVD_deploy.sqf and EVD\EVD_pack.sqf in the very last step. Perhaps it is not worded clearly enough.

 

As an added bonus, the pack feature works for spawned vehicles too, so I'm going to change my menu to say "Dismantle Vehicle" if you don't mind.

Whatever floats your boat. I had thought about changing the menu name, but was to far into it already to make such a change across the entire script. (Yes, I am that OCD).

 

As a suggestion, you could add a chance that you break something taking it apart.

An interesting idea. Perhaps even tie the fail rate to the amount of damage to the part/vehicle.

P.S. Now that you mention it, I probably do need to check the state of the wheels and/or windscreens on the vehicle before dropping the parts.

 

Also, I didn't notice a requirement for a toolbox.  For realism you may want to add that in.

It shouldn't work if you don't have a toolbox. In fact, you shouldn't even get the pack menu if it is not in your inventory. But it was one of those things I forgot to test. Edited by TheFarix
Link to comment
Share on other sites

Hi, TheFarix, well done with the script.

You might be interested in this part:

	_offset = [0,5,0]; // 5 meters Y
	_worldPos = player modelToWorld _offset; // in front of player
        _object = _type createVehicle (_worldPos);
   	_object setVariable ["ObjectID",_objectID, true];
   	_object setVariable ["ObjectUID",_objectID, true];
 	_degrees = getDir player; //find out which direction player is looking at
	_object setDir _degrees; //rotate vehicle to match player's direction
Link to comment
Share on other sites

@Bambit: yes, hence the _offset value, you are actually using something similar, however if spawning multiple vehicles, the above code will automatically reposition them so they don't end up spawning on top of other objects.

Attachto on the otherhand ignores that, while nice for bikes, at current offset set to 1m, larger vehicles like aircraft might kill the player.

Edited by raymix
Link to comment
Share on other sites

Did you include the section involving custom variables.sqf? Did you link your custom variables.sqf in your init.sqf? What anti-hack are you running?

 

P.S. Another thing you may want to try is in EVD\EVD_deploy.sqf just after:

				_object addEventHandler ["GetIn",{
					_nil = [nil,(_this select 2),"loc",rTITLETEXT,"Warning: This vehicle will disappear on server restart!","PLAIN DOWN",5] call RE;
				}];

Add:

				PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
Link to comment
Share on other sites

Does anyone have a way of making the requirement for the bike a toolbox? Meaning that the toolbox is used up in the process and given back on packing. I've managed to make it so that it has no material requirements but adding the 'ItemToolbox' to the list doesn't work as a requirement I believe it's  because it only searches the magazines for the materials. 

Link to comment
Share on other sites

Sorry, I clicked 'post' too early :D

I updated it with the proper command for packing

 

No problem thanks a bunch I was trying to figure out how to change it to search though the tool belt instead, this is a much simpler work around.

Link to comment
Share on other sites

Sorry, I clicked 'post' too early :D

I updated it with the proper command for packing

A better way is this

 

In EVD\EVD_deploy.sqf, change

		if (_finished) then {

to

		_hasToolbox = "ItemToolbox" in items player;
		if (_finished and _hasToolbox) then {
			player removeWeapon "ItemToolbox";

In EVD\EVD_pack.sqf, find:

			} forEach _materials;

After it, add:

			_item addWeaponCargoGlobal ["ItemToolbox", 1];

The reasons for this are two fold. First, you don't loose your toolbox if you cancel your build action. It also check to make sure you have at toolbox before removing it from your inventory. Second, the toolbox will drop like all other materials when the vehicle is packed/deconstructed. Otherwise, you will not get the toolbox back because you already have one in your inventory as one is required to pack/deconstruct the vehicle.

Link to comment
Share on other sites

 

In EVD_pack.sqf

Add this:

player addWeapon "ItemToolbox";

After this

[1,1] call dayz_HungerThirst;
player playActionNow "Medic";

In EVD_deploy.sqf

Add this:

player removeWeapon "ItemToolbox";

After this:

[1,1] call dayz_HungerThirst;
player playActionNow "Medic";

 

Hold up, just realized that you need a toolbox to pack it so I edited out "and _hasToolbox"  from the first line on the pack option in fn_selfActions.sqf

 

	//Pack Vehicles
	if (_typeOfCursorTarget in EVDVehicleArray and _hasToolbox and !(locked _cursorTarget) and (damage _cursorTarget < 1)) then {
		if (s_player_packvehicle < 0) then {
			s_player_packvehicle = player addAction ["Pack Vehicle", "SCRIPT_PATH\EVD\EVD_pack.sqf",_cursorTarget, 0, false, true, "",""];
		};
	} else {
		player removeAction s_player_packvehicle;
		s_player_packvehicle = -1;
	};

 

I also realized that if you interrupt the progress at any point it doesn't give you the toolbox back, or for packing you can begin and then abort and effectively clone tool boxes to fix the deploy I put this

                                player removeWeapon "ItemToolbox";

after 

				player reveal _object;

in EVD\EVDdeploy.sqf

 

To fix this on packing I put this

                        player addWeapon "ItemToolbox";

after 

		_radius = 1;

there we go all fixed :)

 

NOTE :

With this method you won't get a toolbox if you already have one, for a method that drops the extra on the floor look here :

 

In EVD\EVD_pack.sqf, find:

            } forEach _materials;

After it, add:

            _item addWeaponCargoGlobal ["ItemToolbox", 1];

The reasons for this are two fold. First, you don't loose your toolbox if you cancel your build action. It also check to make sure you have at toolbox before removing it from your inventory. Second, the toolbox will drop like all other materials when the vehicle is packed/deconstructed. Otherwise, you will not get the toolbox back because you already have one in your inventory as one is required to pack/deconstruct the vehicle.

Method by TheFarix, I take NO credit for this
Link to comment
Share on other sites

I put this:

_menu ctrlSetTextColor [1,0,0,1];

Here:
 

// Add extra context menus
	_erc_cfgActions = (missionConfigFile >> "ExtraRc" >> _item);
	_erc_numActions = (count _erc_cfgActions);
	if (isClass _erc_cfgActions) then {
		for "_j" from 0 to (_erc_numActions - 1) do {
			_menu =  _parent displayCtrl (1600 + _j + _numActions);
			_menu ctrlShow true;
			_config =  (_erc_cfgActions select _j);
			_text =  getText (_config >> "text");
			_script =  getText (_config >> "script");
			_height = _height + (0.025 * safezoneH);
			uiNamespace setVariable ['uiControl', _control];
			_menu ctrlSetText _text;
                         IN HERE
			_menu ctrlSetEventHandler ["ButtonClick",_script];
		};
	};
Link to comment
Share on other sites

 

I put this:

_menu ctrlSetTextColor [1,0,0,1];

Here:

 

// Add extra context menus
	_erc_cfgActions = (missionConfigFile >> "ExtraRc" >> _item);
	_erc_numActions = (count _erc_cfgActions);
	if (isClass _erc_cfgActions) then {
		for "_j" from 0 to (_erc_numActions - 1) do {
			_menu =  _parent displayCtrl (1600 + _j + _numActions);
			_menu ctrlShow true;
			_config =  (_erc_cfgActions select _j);
			_text =  getText (_config >> "text");
			_script =  getText (_config >> "script");
			_height = _height + (0.025 * safezoneH);
			uiNamespace setVariable ['uiControl', _control];
			_menu ctrlSetText _text;
                         IN HERE
			_menu ctrlSetEventHandler ["ButtonClick",_script];
		};
	};

Thanks  ;)

Link to comment
Share on other sites

Nice work!

 

Suggestions:

 

It does allow you to pack items while people are driving them.  Change it to check for a driver/pilot.

Add a jerrycan to the recipes for the motorcycle and mozzie, or people get free fuel to siphon.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...