Skip to content

Commit

Permalink
Merge pull request #3 from matt-d-rat/story/disable-towed-vehichles-f…
Browse files Browse the repository at this point in the history
…rom-towing

Bug - Disable Multi-tow
  • Loading branch information
matt-d-rat committed May 11, 2014
2 parents 6fb28e9 + 864d407 commit 3d6ac42
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ MF-Tow is also fully compatible with the popular '=BTC=_Logistic (DayZ Epoch Ver
- Disable towing of locked vehicles (optional)
- Requires a player to have a toolbox in their inventory in order to be able to attach a tow.

## Configuring Tow Vehicles ##
## Configuration ##

### Configuring tow vehicles & towable vehicles ###

[Download](https://github.com/matt-d-rat/mf-tow/archive/master.zip) and extract the zip file to a folder called ```mf-tow```, inside you will find a file called ```init.sqf```, open this file up in a text editor.

Expand Down Expand Up @@ -54,9 +56,19 @@ So for example, we can see that the code above permits the ```ArmoredSUV_PMC```
To add a new vehicle which can be used as a towing vehicle, add a new case to the switch statement and define an array of the types of vehicles which can be towed (be careful not to have a trailing comma after the last entry in the array!):

```sqf
case "Pickup_PK_INS_DZE": {_array = ["Motorcycle","Car"];};
case "Pickup_PK_INS_DZE": {_array = ["Motorcycle","Car"];};
```

### Enabling Multi-tow ###

By default, towing vehicles which are currently towing another vehicle is disabled (patched in v1.1.1). To enable this functionality, set the ```MF_Tow_Multi_Towing``` variable in ```init.sqf``` to true.

```sqf
MF_Tow_Multi_Towing = true; // Warning, this is not recommended!
```

Although this may seem like a nice feature, in reality the only purpose it will probably serve is to allow people to troll one another. The choice is entirely yours though :-).

## Installation Guide ##

- __Download__: https://github.com/matt-d-rat/mf-tow/archive/master.zip
Expand Down Expand Up @@ -240,6 +252,10 @@ __Step 18: Repack ```dayz_server.pbo``` and upload it to your server.

### Change Log ###

#### v1.1.1 ###
- Fixed exploit which allowed players to tow vehicles which were already being towed.
- Fixed exploit which allowed players to tow vehicles which were already towing another vehicle. This functionality can be turned back on via the ```MF_Tow_Multi_Towing``` config param being set to true (default value is false). Be warned, turning this on produces "interesting" results and probably only serves as a means for trolling.

#### v1.1.0 ###
- Non-breaking changes to the check for whether the cursor target is a towable vehicle.
- Deprecated MF_Tow_Towable variable as it is no longer used as a check condition.
Expand Down
9 changes: 5 additions & 4 deletions init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
* The main script for initalising towing functionality.
*
* Created by Matt Fairbrass (matt_d_rat)
* Version: 1.1.0
* Version: 1.1.1
* MIT Licence
**/

private ["_cursorTarget", "_towableVehicles", "_towableVehiclesTotal"];

// Public variables
MF_Tow_Base_Path = "addons\mf-tow"; // The base path to the MF-Tow Folder.
MF_Tow_Distance = 10; // Minimum distance (in meters) away from vehicle the tow truck must be to tow.
MF_Tow_Base_Path = "addons\mf-tow"; // The base path to the MF-Tow Folder.
MF_Tow_Distance = 10; // Minimum distance (in meters) away from vehicle the tow truck must be to tow.
MF_Tow_Multi_Towing = false; // Allow a vehicle which is towing another vehicle already to be towed by another tow. Disabled by default.

// Functions

Expand Down Expand Up @@ -94,7 +95,7 @@ _towableVehiclesTotal = count (_towableVehicles);
// Add the action to the players scroll wheel menu if the cursor target is a vehicle which can tow.
if(_towableVehiclesTotal > 0) then {
if (s_player_towing < 0) then {
if(!(_cursorTarget getVariable ["MFTowInTow", false])) then {
if(!(_cursorTarget getVariable ["MFTowIsTowing", false])) then {
s_player_towing = player addAction ["Attach Tow", format["%1\tow_AttachTow.sqf", MF_Tow_Base_Path], _cursorTarget, 0, false, true, "",""];
} else {
s_player_towing = player addAction ["Detach Tow", format["%1\tow_DetachTow.sqf", MF_Tow_Base_Path], _cursorTarget, 0, false, true, "",""];
Expand Down
15 changes: 13 additions & 2 deletions tow_AttachTow.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* The action for attaching the tow to another vehicle.
*
* Created by Matt Fairbrass (matt_d_rat)
* Version: 1.1.0
* Version: 1.1.1
* MIT Licence
**/

Expand Down Expand Up @@ -48,6 +48,16 @@ if(_IsNearVehicle > 0) then {
cutText [format["Cannot tow %1 because it is locked.", _vehicleNameText], "PLAIN DOWN"];
};

// Check that the vehicle we want to tow is not already being towed by something else.
if((_vehicle getVariable ["MFTowInTow", false])) exitWith {
cutText [format["Cannot tow %1 because it is already being towed by another vehicle.", _vehicleNameText], "PLAIN DOWN"];
};

// Check that the vehicle we want to tow is not already towing something else
if(!MF_Tow_Multi_Towing && (_vehicle getVariable ["MFTowIsTowing", false])) exitWith {
cutText [format["Cannot tow %1 because it is already towing another vehicle.", _vehicleNameText], "PLAIN DOWN"];
};

_finished = false;

[_towTruck] call MF_Tow_Animate_Player_Tow_Action;
Expand Down Expand Up @@ -125,7 +135,8 @@ if(_IsNearVehicle > 0) then {
// Detach the player from the tow truck
detach player;

_towTruck setVariable ["MFTowInTow", true, true];
_vehicle setVariable ["MFTowInTow", true, true];
_towTruck setVariable ["MFTowIsTowing", true, true];
_towTruck setVariable ["MFTowVehicleInTow", _vehicle, true];

cutText [format["%1 has been attached to %2.", _vehicleNameText, _towTruckNameText], "PLAIN DOWN"];
Expand Down
16 changes: 9 additions & 7 deletions tow_DetachTow.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* The action for detaching the tow from another vehicle.
*
* Created by Matt Fairbrass (matt_d_rat)
* Version: 1.1.0
* Version: 1.1.1
* MIT Licence
**/

private ["_vehicle","_started","_finished","_animState","_isMedic","_vehicleNameText","_towTruckNameText","_towTruck","_inTow","_hasToolbox"];
private ["_vehicle","_started","_finished","_animState","_isMedic","_vehicleNameText","_towTruckNameText","_towTruck","_isTowing","_hasToolbox"];

if(DZE_ActionInProgress) exitWith { cutText [(localize "str_epoch_player_96") , "PLAIN DOWN"] };
DZE_ActionInProgress = true;
Expand All @@ -20,14 +20,14 @@ _towTruck = _this select 3;
_towTruckNameText = [_towTruck] call MF_Tow_Get_Vehicle_Name;

// exit if no vehicle is in tow.
_inTow = _towTruck getVariable ["MFTowInTow", false];
_isTowing = _towTruck getVariable ["MFTowIsTowing", false];

if(_inTow) then {
if(_isTowing) then {

// Select the vehicle currently in tow
_vehicle = _towTruck getVariable ["MFTowVehicleInTow", objNull];

if(!(isNull _towTruck)) then {
if(!(isNull _vehicle)) then {
_vehicleNameText = [_vehicle] call MF_Tow_Get_Vehicle_Name;
_finished = false;
_hasToolbox = "ItemToolbox" in (items player);
Expand Down Expand Up @@ -75,14 +75,16 @@ if(_inTow) then {

detach _vehicle;
detach player;
_towTruck setVariable ["MFTowInTow", false, true];

_vehicle setVariable ["MFTowInTow", false, true];
_towTruck setVariable ["MFTowIsTowing", false, true];
_towTruck setVariable ["MFTowVehicleInTow", objNull, true];
cutText [format["%1 has been detached from %2.", _vehicleNameText, _towTruckNameText], "PLAIN DOWN"];

_vehicle setvelocity [0,0,1];
};
} else {
_towTruck setVariable ["MFTowInTow", false, true];
_towTruck setVariable ["MFTowIsTowing", false, true];
_towTruck setVariable ["MFTowVehicleInTow", objNull, true];
};
} else {
Expand Down

0 comments on commit 3d6ac42

Please sign in to comment.