Jump to content

[RELEASE] MF-Tow 1.0.7


Harkness

Recommended Posts

From what I see this was made by user matt-d-rat about 6 years ago. All i did was light up a few smokes and update all the old variable names to get it running on our 1062 + 107 servers from which we use a lot of scripts from here so here is a contribution back from me. I only added Epoch Vehicles in there.

Original Instructions

Original Thread

All you need to do is follow matt-d-rats Original Instructions above, But instead of using the old files he made use my edited versions below

mf-tow\init.sqf

Spoiler

/**
 * mf-tow/init.sqf
 * The main script for initalising towing functionality. 
 *
 * Created by Matt Fairbrass (matt_d_rat)
 * Version: 1.1.2
 * 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_Multi_Towing         = false;                // Allow a vehicle which is towing another vehicle already to be towed by another tow. Disabled by default.

// Functions

/**
 * Returns an array of towable objects which can be pulled by the tow truck.
 * Configure this as required to set which vehicles can pull which types of other vehicles.
 **/
MF_Tow_Towable_Array =
{
    private ["_array","_towTruck"];
    _towTruck = _this select 0;
    _array = [];
    
    switch (typeOf _towTruck) do
{
    // ATVs
        case "ATV_CZ_EP1":                         {_array = ["Motorcycle"];};
        case "ATV_US_EP1":                         {_array = ["Motorcycle"];};
    // Cars
        case "car_hatchback":                    {_array = ["Motorcycle","Car"];};
        case "car_sedan":                        {_array = ["Motorcycle","Car"];};
        case "GLT_M300_LT":                        {_array = ["Motorcycle","Car"];};
        case "GLT_M300_ST":                        {_array = ["Motorcycle","Car"];};
        case "Lada1":                            {_array = ["Motorcycle","Car"];};
        case "Lada1_TK_CIV_EP1":                {_array = ["Motorcycle","Car"];};
        case "Lada2":                            {_array = ["Motorcycle","Car"];};
        case "Lada2_TK_CIV_EP1":                {_array = ["Motorcycle","Car"];};
        case "LadaLM":                            {_array = ["Motorcycle","Car"];};
        case "UAZ_CDF":                            {_array = ["Motorcycle","Car"];};
        case "UAZ_INS":                            {_array = ["Motorcycle","Car"];};
        case "UAZ_MG_TK_EP1_DZE":                {_array = ["Motorcycle","Car"];};
        case "UAZ_RU":                            {_array = ["Motorcycle","Car"];};
        case "UAZ_Unarmed_TK_CIV_EP1":            {_array = ["Motorcycle","Car"];};
        case "UAZ_Unarmed_TK_EP1":                {_array = ["Motorcycle","Car"];};
        case "UAZ_Unarmed_UN_EP1":                {_array = ["Motorcycle","Car"];};
        case "VWGolf":                            {_array = ["Motorcycle","Car"];};
        case "Skoda":                            {_array = ["Motorcycle","Car"];};
        case "SkodaBlue":                        {_array = ["Motorcycle","Car"];};
        case "SkodaGreen":                        {_array = ["Motorcycle","Car"];};
        case "SkodaRed":                        {_array = ["Motorcycle","Car"];};
        case "VolhaLimo_TK_CIV_EP1":            {_array = ["Motorcycle","Car"];};
        case "Volha_1_TK_CIV_EP1":                {_array = ["Motorcycle","Car"];};
        case "Volha_2_TK_CIV_EP1":                {_array = ["Motorcycle","Car"];};
        case "S1203_ambulance_EP1":                {_array = ["Motorcycle","Car"];};
        case "S1203_TK_CIV_EP1":                {_array = ["Motorcycle","Car"];};
        case "LandRover_CZ_EP1":                {_array = ["Motorcycle","Car"];};
        case "LandRover_MG_TK_EP1_DZE":            {_array = ["Motorcycle","Car"];};
        case "LandRover_Special_CZ_EP1_DZE":    {_array = ["Motorcycle","Car"];};
        case "LandRover_TK_CIV_EP1":            {_array = ["Motorcycle","Car"];};
        case "datsun1_civil_1_open_DZE":        {_array = ["Motorcycle","Car"];};
        case "datsun1_civil_2_covered_DZE":        {_array = ["Motorcycle","Car"];};
        case "datsun1_civil_3_open_DZE":        {_array = ["Motorcycle","Car"];};
        case "hilux1_civil_1_open_DZE":            {_array = ["Motorcycle","Car"];};
        case "hilux1_civil_2_covered_DZE":        {_array = ["Motorcycle","Car"];};
        case "hilux1_civil_3_open_DZE":            {_array = ["Motorcycle","Car"];};
        case "Offroad_DSHKM_Gue_DZE":            {_array = ["Motorcycle","Car"];};
        case "Pickup_PK_GUE_DZE":                {_array = ["Motorcycle","Car"];};
        case "Pickup_PK_INS_DZE":                {_array = ["Motorcycle","Car"];};
        case "Pickup_PK_TK_GUE_EP1_DZE":        {_array = ["Motorcycle","Car"];};
        case "HMMWV_Ambulance":                    {_array = ["Motorcycle","Car"];};
        case "HMMWV_Ambulance_CZ_DES_EP1":        {_array = ["Motorcycle","Car"];};
        case "HMMWV_DES_EP1":                    {_array = ["Motorcycle","Car"];};
        case "HMMWV_DZ":                        {_array = ["Motorcycle","Car"];};
        case "HMMWV_M1035_DES_EP1":                {_array = ["Motorcycle","Car"];};
        case "HMMWV_M1151_M2_CZ_DES_EP1_DZE":    {_array = ["Motorcycle","Car"];};
        case "HMMWV_M998A2_SOV_DES_EP1_DZE":    {_array = ["Motorcycle","Car"];};
        case "ArmoredSUV_PMC_DZE":                {_array = ["Motorcycle","Car"];};
        case "SUV_Blue":                        {_array = ["Motorcycle","Car"];};
        case "SUV_Camo":                        {_array = ["Motorcycle","Car"];};
        case "SUV_Charcoal":                    {_array = ["Motorcycle","Car"];};
        case "SUV_Green":                        {_array = ["Motorcycle","Car"];};
        case "SUV_Orange":                        {_array = ["Motorcycle","Car"];};
        case "SUV_Pink":                        {_array = ["Motorcycle","Car"];};
        case "SUV_Red":                            {_array = ["Motorcycle","Car"];};
        case "SUV_Silver":                        {_array = ["Motorcycle","Car"];};
        case "SUV_TK_CIV_EP1":                    {_array = ["Motorcycle","Car"];};
        case "SUV_White":                        {_array = ["Motorcycle","Car"];};
        case "SUV_Yellow":                        {_array = ["Motorcycle","Car"];};
    // Trucks
        case "Kamaz_DZE":                        {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "KamazRefuel_DZ":                    {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "UralRefuel_TK_EP1_DZ":            {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "Ural_CDF":                        {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "Ural_TK_CIV_EP1":                    {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "Ural_UN_EP1":                        {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "V3S_Open_TK_CIV_EP1":                {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "V3S_Open_TK_EP1":                    {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "V3S_Refuel_TK_GUE_EP1_DZ":        {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "MtvrRefuel_DES_EP1_DZ":            {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "MTVR_DES_EP1":                    {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
    // Tractors
        case "tractor":                         {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
        case "TowingTractor":                     {_array = ["Motorcycle","Car","Truck","Wheeled_APC","Tracked_APC","Air"];};
    };    
    _array
};

/**
 * Animate the player in a towing action, whilst attaching them to the tow vehicle to ensure safety.
 **/
MF_Tow_Animate_Player_Tow_Action =
{
    private ["_towTruck","_offsetZ"];
    _towTruck = _this select 0;
    _offsetZ = 0.1;
    
    // Bounding box on UAZ is screwed, offset z-axis correctly
    if(_towTruck isKindOf "UAZ_Base") then {
        _offsetZ = 1.8;
    };
    
    [player,20,true,(getPosATL player)] spawn player_alertZombies; // Alert nearby zombies
    ["Working",0,[20,40,15,0]] call dayz_NutritionSystem; // Use some hunger and thirst to perform the action
    
    // Attach the player to the tow truck temporarily for safety so that they aren't accidentally hit by the vehicle when it gets attached
    player attachTo [_towTruck, 
        [
            (boundingBox _towTruck select 1 select 0),
            (boundingBox _towTruck select 0 select 1) + 1,
            (boundingBox _towTruck select 0 select 2) - (boundingBox player select 0 select 2) + _offsetZ
        ]
    ];

    player setDir 270;
    player setPos (getPos player);
    player playActionNow "Medic"; // Force the animation
};

MF_Tow_Get_Vehicle_Name =
{
    private ["_vehicle", "_configVeh", "_vehicleName"];
    _vehicle = _this select 0;
    
    _configVeh = configFile >> "cfgVehicles" >> TypeOf(_vehicle);
    _vehicleName = getText(_configVeh >> "displayName");
    
    _vehicleName
};

// Initialise script
_cursorTarget = cursorTarget;
_towableVehicles = [_cursorTarget] call MF_Tow_Towable_Array;
_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 ["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, "",""];            
        };
    };

else {
    player removeAction s_player_towing;
    s_player_towing = -1;
};

mf-tow\tow_AttachTow.sqf

Spoiler

/**
 * mf-tow/tow_AttachTow.sqf
 * The action for attaching the tow to another vehicle. 
 *
 * Created by Matt Fairbrass (matt_d_rat)
 * Version: 1.1.2
 * MIT Licence
 **/

private ["_vehicle","_started","_finished","_animState","_isMedic","_abort","_vehicleNameText","_towTruckNameText","_findNearestVehicles","_findNearestVehicle","_IsNearVehicle","_towTruck","_towableVehicles","_towableVehiclesTotal","_vehicleOffsetY","_towTruckOffsetY","_offsetZ","_hasToolbox"];

if(dayz_actionInProgress) exitWith { cutText [(localize "str_epoch_player_96") , "PLAIN DOWN"] };
dayz_actionInProgress = true;

player removeAction s_player_towing;
s_player_towing = 1;

// Tow Truck
_towTruck = _this select 3;
_towableVehicles = [_towTruck] call MF_Tow_Towable_Array;
_towableVehiclesTotal = count (_towableVehicles);
_towTruckNameText = [_towTruck] call MF_Tow_Get_Vehicle_Name;

// Get all nearby vehicles that can be towed by the towTruck within the minimum tow distance
_findNearestVehicles = nearestObjects [_towTruck, _towableVehicles, MF_Tow_Distance];
_findNearestVehicle = [];
{
    if (alive _x && _towTruck != _x) then {
        _findNearestVehicle set [(count _findNearestVehicle),_x];
    };
} foreach _findNearestVehicles;
        
_IsNearVehicle = count (_findNearestVehicle);

if(_IsNearVehicle > 0) then {
    // select the nearest one
    _vehicle = _findNearestVehicle select 0;
    _vehicleNameText = [_vehicle] call MF_Tow_Get_Vehicle_Name;
    _hasToolbox = "ItemToolbox" in (items player);
    
    // Check the player has a toolbox
    if(!_hasToolbox) exitWith {
        cutText ["Cannot attach tow without a toolbox.", "PLAIN DOWN"];
    };
    
    // Check if the vehicle we want to tow is locked
    if((_vehicle getVariable ["MF_Tow_Cannot_Tow", false])) exitWith {
        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"];
    };
    
    // Check if the vehicle has anyone in it
    if ((count (crew _vehicle)) != 0) exitWith {
        cutText [format["Cannot tow %1 because it has people in it.", _vehicleNameText], "PLAIN DOWN"];
    };
    
    _finished = false;
    
    [_towTruck] call MF_Tow_Animate_Player_Tow_Action;
    
    r_interrupt = false;
    _animState = animationState player;
    r_doLoop = true;
    _started = false;

    while {r_doLoop} do {
        _animState = animationState player;
        _isMedic = ["medic",_animState] call fnc_inString;
        if (_isMedic) then {
            _started = true;
        };
        
        if (_started and !_isMedic) then {
            r_doLoop = false;
            _finished = true;
        };
        
        // Check if anyone enters the vehicle while we are attaching the tow and stop the action
        if ((count (crew _vehicle)) != 0) then {
            cutText [format["Towing aborted because the %1 was entered by another player.", _vehicleNameText], "PLAIN DOWN"];
            r_interrupt = true;
        };
        
        if (r_interrupt) then {
            detach player;
            r_doLoop = false;
        };
        
        sleep 0.1;
    };
    r_doLoop = false;

    if(!_finished) then {
        r_interrupt = false;
            
        if (vehicle player == player) then {
            [objNull, player, rSwitchMove,""] call RE;
            player playActionNow "stop";
        };
        _abort = true;
    };

    if (_finished) then {
        if(((vectorUp _vehicle) select 2) > 0.5) then {
            if( _towableVehiclesTotal > 0 ) then {
                _towTruckOffsetY = 0.8;
                _vehicleOffsetY = 0.8;
                _offsetZ = 0.1;
                
                // Calculate the offset positions depending on the kind of tow truck                
                switch(true) do {
                    case (_towTruck isKindOf "ArmoredSUV_Base_PMC");
                    case (_towTruck isKindOf "SUV_Base_EP1") : {
                        _towTruckOffsetY = 0.9;
                    };
                    case (_towTruck isKindOf "UAZ_Base" && !(_vehicle isKindOf "UAZ_Base")) : {
                        _offsetZ = 1.8;
                    };
                };
                
                // Calculate the offset positions depending on the kind of vehicle
                switch(true) do {
                    case (_vehicle isKindOf "Truck" && !(_towTruck isKindOf "Truck")) : {
                        _vehicleOffsetY = 0.9;
                    };
                    case (_vehicle isKindOf "UAZ_Base" && !(_towTruck isKindOf "UAZ_Base")) : {
                        _offsetZ = -1.8;
                    };
                };
                    
                // Attach the vehicle to the tow truck
                _vehicle attachTo [ _towTruck,
                    [
                        0,
                        (boundingBox _towTruck select 0 select 1) * _towTruckOffsetY + (boundingBox _vehicle select 0 select 1) * _vehicleOffsetY,
                        (boundingBox _towTruck select 0 select 2) - (boundingBox _vehicle select 0 select 2) + _offsetZ
                    ]
                ];
                
                detach player;
                _vehicle lock true; // Disable entering the vehicle while it is in tow.
                
                _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"];
            };    
        } else {
            cutText [format["Failed to attach %1 to %2.", _vehicleNameText, _towTruckNameText], "PLAIN DOWN"];
        };
    };
} else {
    cutText [format["No vehicles nearby to tow. Move within %1m of a vehicle.", MF_Tow_Distance], "PLAIN DOWN"];
};
dayz_actionInProgress = false;
s_player_towing = -1;

mf-tow\tow_DetachTow.sqf

Spoiler

/**
 * mf-tow/tow_DetachTow.sqf
 * The action for detaching the tow from another vehicle. 
 *
 * Created by Matt Fairbrass (matt_d_rat)
 * Version: 1.1.2
 * MIT Licence
 **/
 
private ["_vehicle","_started","_finished","_animState","_isMedic","_vehicleNameText","_towTruckNameText","_towTruck","_isTowing","_hasToolbox"];

if(dayz_actionInProgress) exitWith { cutText [(localize "str_epoch_player_96") , "PLAIN DOWN"] };
dayz_actionInProgress = true;

player removeAction s_player_towing;
s_player_towing = 1;

// Tow Truck
_towTruck = _this select 3;
_towTruckNameText = [_towTruck] call MF_Tow_Get_Vehicle_Name;

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

if(_isTowing) then {

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

    if(!(isNull _vehicle)) then {
        _vehicleNameText = [_vehicle] call MF_Tow_Get_Vehicle_Name;
        _finished = false;        
        _hasToolbox = "ItemToolbox" in (items player);
        
        // Check the player has a toolbox
        if(!_hasToolbox) exitWith {
            cutText ["Cannot dettach tow without a toolbox.", "PLAIN DOWN"];
        };
        
        [_towTruck] call MF_Tow_Animate_Player_Tow_Action;

        r_interrupt = false;
        _animState = animationState player;
        r_doLoop = true;
        _started = false;

        while {r_doLoop} do {
            _animState = animationState player;
            _isMedic = ["medic",_animState] call fnc_inString;
            if (_isMedic) then {
                _started = true;
            };
            if (_started and !_isMedic) then {
                r_doLoop = false;
                _finished = true;
            };
            if (r_interrupt) then {
                detach player;
                r_doLoop = false;
            };
            sleep 0.1;
        };
        r_doLoop = false;

        if(!_finished) then {
            r_interrupt = false;
            
            if (vehicle player == player) then {
                [objNull, player, rSwitchMove,""] call RE;
                player playActionNow "stop";
            };
        };

        if (_finished) then {
            detach _vehicle;
            detach player;
            _vehicle lock false; // Enable players to re-enter the vehicle now it has been detached.
                        
            _vehicle setVariable ["MFTowInTow", false, true];
            _towTruck setVariable ["MFTowIsTowing", false, true];
            _towTruck setVariable ["MFTowVehicleInTow", objNull, true];
            cutText [format["%1 has been detached from %2. Start engine to save new possition", _vehicleNameText, _towTruckNameText], "PLAIN DOWN"];
            
            _vehicle setvelocity [0,0,1];
        };
    } else {
        _towTruck setVariable ["MFTowIsTowing", false, true];
        _towTruck setVariable ["MFTowVehicleInTow", objNull, true];    
    };
} else {
    cutText ["No vehicles in tow.", "PLAIN DOWN"];
};
dayz_actionInProgress = false;
s_player_towing = -1;

 

Link to comment
Share on other sites

  • 4 months later...
  • 2 weeks later...

I'm putting a LAN server together and slowly implementing scripts. This works although a bit of a game breaker in term of realism of towing a C130 down narrow forest roads

since altered two lines to make attach/detach  blue in menu  in init.sqf lines 170, 172

 s_player_towing = player addAction [("<t color=""#0000ff"">" + ("Attach Tow") +"</t>"), format["%1\tow_AttachTow.sqf", MF_Tow_Base_Path], _cursorTarget, 0, false, true,"",""];

 

  s_player_towing = player addAction [("<t color=""#0000ff"">" + ("Detach Tow") +"</t>"), format["%1\tow_DetachTow.sqf", 

 

dzc130.jpg

Edited by noswal
added info
Link to comment
Share on other sites

  • 3 months later...

Hey there. I'm having trouble adding this to my 1.0.7 server. I used the original install instructions and the edited mf-tow files but it doesn't seem to be working. Does anyone have files and install instructions that can be used for Epoch 1.0.7?

Thanks!

Vlad

Link to comment
Share on other sites

  • 3 months later...

I need to do this again for my 107 server so i will have another look at it. its not hard to update outdated variables though. i think if i remember right the epoch devs post all the ones that have change to a text file in the Documents folder. id be more worried about that epoch antihack. i had a right pain in the but with infistar last time i did this

Link to comment
Share on other sites

On 1/24/2021 at 8:00 AM, noswal said:

I'm putting a LAN server together and slowly implementing scripts. This works although a bit of a game breaker in term of realism of towing a C130 down narrow forest roads

since altered two lines to make attach/detach  blue in menu  in init.sqf lines 170, 172

 s_player_towing = player addAction [("<t color=""#0000ff"">" + ("Attach Tow") +"</t>"), format["%1\tow_AttachTow.sqf", MF_Tow_Base_Path], _cursorTarget, 0, false, true,"",""];

 

  s_player_towing = player addAction [("<t color=""#0000ff"">" + ("Detach Tow") +"</t>"), format["%1\tow_DetachTow.sqf", 

 

dzc130.jpg

If you search for " MF_Tow_Towable_Array " you can modify which vehicles

Link to comment
Share on other sites

On 4/30/2021 at 5:30 PM, Vladick said:

Hey there. I'm having trouble adding this to my 1.0.7 server. I used the original install instructions and the edited mf-tow files but it doesn't seem to be working. Does anyone have files and install instructions that can be used for Epoch 1.0.7?

Thanks!

Vlad

Iv just finished setting this up on my 107 server now mate, what are you having problems with maybe i can help? It is working great on our server tested on Namalsk Epoch 107 i towed a vehicle to a new location then checked on both client and server logs to find them clean.
Maybe try a reinstall. Hope this helps, dont forget you also need toolbox

20210814150858_1.jpg

Link to comment
Share on other sites

  • 7 months later...

Hello guys,

anyone got this to work in 1.0.7 these days ?

I followed the original instruction with the new files, but nothig happens in game. No "Tow"-entry in vehicle action menu ingame.

I checked the installation few times, seems all ok, regarding original instruction.

I have a toolbox in my inventory. No idea, what I'm doing wrong.

Any help would be nice.

 

 

 

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
  • Discord

×
×
  • Create New...