Jump to content
zealot111

Realistic repair script

Recommended Posts

I want to share field repair script which we using in our TvT games and which I believe adds additional realism to the game. It add every unit additional ability to field repair heavy damaged vehicle to "Yellow" state. Repair takes 30-300 seconds (depends on number of heavy damaged parts) and requires dispensable ToolKit in backpack or in vehicle cargo, this kit dissapears after the repair. But you can repair vehicle first time without ToolKit, this simulates spare parts set which always exists on every military vehicle.

Repair trucks could repair 5 times and each repair lasts 120 sec.

27/01/2014 Bugfixes, reduced repair times to 30 secs. for each damaged part and 120 secs. fr repair truck

25/12/2013 Player respawn support.

24/12/2013 Another one hotfix.

22/12/2013 Hotfix for "Repair interrupted" problem.

15/12/2013 Script updated. Repair time depends now from vehicle damage level, repair lasts from (40 sec - 1 broken wheel) to 400 sec. Minor bugfixes.

12/12/2013 Script updated. Support for dynamically created vehicles but repair trucks. See "Installation and usage" for info regarding dynamically created repair trucks.

09/12/2013 Script updated. Several bugfixes regarding working on dedicated MP server.

05/12/2013 Updated with latest script version. Added support for repair tracks. Repair truck also fixes vehicles for 3 min., but completely restores them. Repair truck can be used 5 times. To use repair track you should sat into drivers place of the damaged vehicle then look on repair truck and select 'Full repair' in the menu.

Any suggestions welcome.

Installation and Usage:

Just copy zlt_fieldrepair.sqf file into your mission folder in Documents\Arma 3 - Other Profiles\{YOUR ARMA PROFILE NMAE}\MPMissions directory.

Put in yoyr init.sqf string:

[] execVM "zlt_fieldrepair.sqf";

or if you use dynamically created repair trucks in your mission:

[true] execVM "zlt_fieldrepair.sqf";

Sample mission: http://stels-arma.ucoz.ru/sample.Stratis.zip

Script: http://stels-arma.ucoz.ru/zlt_fieldrepair.sqf

Current limitations:

You should not use Engineer or Repair Specialist classes when using this script, because it doesnt remove vanilla repair actions from their menus and they still will be able to repair vehicles for 1 second.

zlt_fieldrepair.sqf:

// Field repair by [sTELS]Zealot
// Just add 
// [] execVM "zlt_fieldrepair.sqf";
// http://forums.bistudio.com/showthread.php?168714-Realistic-repair-script

#define DEFAULT_FREPAIR_VER "1P"

#define DEFAULT_FIELDREPAIR_EACH_PART_TIME 30
#define DEFAULT_FIELDREPAIR_EACH_HARDPART_TIME 60
#define DEFAULT_FULLREPAIR_LENGTH 120
#define DEFAULT_REPAIR_TRUCK_USES 5
#define DEFAULT_FREE_REPAIRS 1

#define STR_FIELD_REPAIR "Field repair"
#define STR_CANCEL_ACTION "Cancel action"
#define STR_SERIOUS_REPAIR "Full repair"
#define STR_REPAIR_CONDITIONS "Bad conditions for repair"
#define STR_ANOTHER_ACTION "Another action in progress"
#define STR_NEED_TOOLKIT "Need ToolKit in inventory yours or vehicle."
#define STR_REPAIR_INTERRUPTED "Repair interrupted"
#define STR_REPAIR_FINISHED "Repair finished"
#define STR_REPAIR_MSG_STRING "%2 will be repaired in %1 sec"
#define STR_REPAIR_TRUCK_DEPLETED "Spare parts depleted in repair truck"
#define STR_HELP "Realistic field repair (Author: Zealot) <br/>Script gives each player ability to repair vehicles. <br/>- Repair lasts for 40-400 sec. (Longer for heavy damaged vehicles), it can be interrupted and the continued, time saves.<br/>- Each vehicle could be repaired 1 time for spare parts stored in the vehicle itself.For the next repairs you should have Toolkit in your backpack or in vehicle cargo.<br/>- Field repair fixes only some parts of the vehicle and only to 'Yellow state'.<br/>- Repair from repair trucks lasts 3 min. but completely repairs vehicles. Repair truck can be used 5 times, then spare parts in it will be depleted.<br/>- To use repair truck you should sat on the drivers place of the repair truck then look on damaged vehicle and select 'Full repair' in menu.<br/>"
#define STR_SCRIPTS_NAME "Scripts"
#define STR_SCRIPT_NAME "Field repair"
#define STR_PUSH_APC "Push vehicle"

zlt_repair_loop = [_this, 0, false] call BIS_fnc_param;

if (isServer) then {
[] spawn {
	_first = true;
	while {_first or zlt_repair_loop} do {
		{ 
			if (getRepairCargo _x > 0) then {
				_x setRepairCargo 0;
				_x setVariable ["zlt_repair_cargo", 1, true]; 
			};
		} foreach vehicles;
		_first = false;
		sleep 26.1;
	};
};
};

zlt_fnc_partrepair = {
private "_veh";
_veh = [_this, 0] call BIS_fnc_param;
if (isNil {_veh} ) exitWith {}; 
{
	_dmg = (_veh getHitPointDamage _x);
	if (not isNil {_dmg}) then {
		if ( _dmg > 0.64 ) then {
			if (_x in zlt_hardRepairParts) then {
				_veh setHitPointDamage [_x,0.64];
			} else {
				_veh setHitPointDamage [_x,0];
			};
		};
	};
} foreach zlt_repair_hps; 
};

zlt_fnc_fullrepair = {
private "_veh";
_veh = [_this, 0] call BIS_fnc_param;
_veh setDamage 0;
};

zlt_repair_hps = ["HitLFWheel","HitLBWheel","HitLMWheel","HitLF2Wheel","HitRFWheel","HitRBWheel","HitRMWheel","HitRF2Wheel" ,"HitEngine", "HitLTrack","HitRTrack"] + ["HitFuel","HitAvionics","HitVRotor","HitHRotor"];
zlt_hardRepairParts = ["HitEngine", "HitLTrack","HitRTrack"] + ["HitFuel","HitAvionics","HitHRotor"];

if (isDedicated) exitWith {};
waitUntil {player == player};
zlt_mutexAction = false;

zlt_fnc_vehicledamaged = {
private ["_veh","_vehtype","_flag"];
_veh =  [_this, 0] call BIS_fnc_param;
if (isNil {_veh}) exitWith {false};
_vehtype = typeOf _veh;
_flag = false;
if (true) then {
	{
		_cdmg = _veh getHitPointDamage (_x);
		if (not isNil {_cdmg} ) then {
			if (_cdmg > 0.64) exitWith {_flag = true};
		};
	}  forEach zlt_repair_hps;
};
_flag;
};



zlt_frpr_getPartsRepairTime = {
private ["_veh","_vehtype","_flag"];
_veh =  [_this, 0] call BIS_fnc_param;
if (isNil {_veh}) exitWith {1};
_rprTime = 0;
{
	_cdmg = _veh getHitPointDamage (_x);
	if (not isNil {_cdmg} ) then {
		diag_log str ["REPAIR ", _x, _cdmg];
		if (_cdmg > 0.64) exitWith {_rprTime = _rprTime + ( if (_x in zlt_hardRepairParts) then {DEFAULT_FIELDREPAIR_EACH_HARDPART_TIME} else {DEFAULT_FIELDREPAIR_EACH_PART_TIME}); };
	};
}  forEach zlt_repair_hps;
_rprTime;
};

zlt_fnc_notify = {
 [ format["<t size='0.75' color='#ffff00'>%1</t>",_this], 0,1,5,0,0,301] spawn bis_fnc_dynamicText;
};

zlt_fnc_hastk = {
private ["_ret"];
_ret = 0;
if ("ToolKit" in (items player)) then {_ret = 1;};
if ("ToolKit" in (itemCargo _veh)) then {_ret = 2;};
if ( (_veh getVariable ["zlt_longrepair_times",0] ) < DEFAULT_FREE_REPAIRS) then {_ret = 3;};
_ret;
};


zlt_fnc_removeitemfromcargo = {
private ["_veh"];
_item = [_this,0,""] call BIS_fnc_param;
_veh = [_this,1] call BIS_fnc_param;
_allitems = itemcargo _veh;
clearItemCargoGlobal _veh;
_allitems = _allitems call BIS_fnc_consolidateArray;
_n = [_allitems, _item] call BIS_fnc_findInPairs;
_allitems set [_n, [(_allitems select _n) select 0, ((_allitems select _n) select 1) - 1]];
   { _veh addItemCargoGlobal [_x select 0, _x select 1 ];} foreach _allitems;
};

zlt_prc_repairvehicle = {
private ["_veh"];
_veh = (nearestObjects [player,["LandVehicle","Air","Ship"], 7]) select 0;
if (isNil {_veh}) exitWith {};
if (zlt_mutexAction) exitWith {
	STR_ANOTHER_ACTION call zlt_fnc_notify;
};
if (not alive player or (player distance _veh) > 7 or (vehicle player != player) or speed _veh > 3) exitWith {STR_REPAIR_CONDITIONS call zlt_fnc_notify;};
_hastk = [] call zlt_fnc_hastk;
if ( _hastk == 0 ) exitWith {STR_NEED_TOOLKIT call zlt_fnc_notify;};
_repairFinished = false;
zlt_mutexAction = true;  
_lastPlayerState = animationState player;
player playActionNow "medicStartRightSide";
sleep 0.5;
_maxlength = _veh getVariable["zlt_longrepair",[_veh] call zlt_frpr_getPartsRepairTime];
_vehname = getText ( configFile >> "CfgVehicles" >> typeOf(_veh) >> "displayName");
_length = _maxlength;
_cycle = 0;
while {alive player and (player distance _veh) < 7 and (vehicle player == player) and speed _veh < 3 and not _repairFinished and zlt_mutexAction and (_cycle < 3 or (["medic",animationState player] call BIS_fnc_inString))} do {		
//	diag_log ("ANIM STATE = "+str(animationState player));	
	(format[sTR_REPAIR_MSG_STRING, _length, _vehname] ) call zlt_fnc_notify;
	if (_length <= 0) then {_repairFinished = true;};
	_length = _length - 1;
	sleep 1;
	_hastk = [] call zlt_fnc_hastk;
	if (_hastk <= 0) exitWith {STR_NEED_TOOLKIT call zlt_fnc_notify; sleep 1.;};	
	_cycle = _cycle + 1;
};
if (_repairFinished) then {
	_hastk = [] call zlt_fnc_hastk;
	if (_hastk == 0) exitWith {STR_NEED_TOOLKIT call zlt_fnc_notify; sleep 1.;};	
	STR_REPAIR_FINISHED call zlt_fnc_notify;
	[_veh,"zlt_fnc_partrepair", _veh] call bis_fnc_MP;
	if (_hastk == 1) then {player removeItem "ToolKit";};
	if (_hastk == 2) then { ["ToolKit",_veh] call zlt_fnc_removeitemfromcargo;};
	_veh setVariable["zlt_longrepair",nil, true];
	_veh setVariable["zlt_longrepair_times", (_veh getVariable ["zlt_longrepair_times",0]) + 1 , true ];
} else {
	STR_REPAIR_INTERRUPTED call zlt_fnc_notify;
	_veh setVariable["zlt_longrepair",_length, true];
};
zlt_mutexAction = false;  
player playActionNow "medicstop";
};


zlt_fnc_repair_cond = {
private ["_veh","_ret"];
_ret = false;
_veh = (nearestObjects [player,["LandVehicle","Air","Ship"], 7]) select 0;
if (isNil {_veh}) exitWith {_ret};
_dmged = _veh call zlt_fnc_vehicledamaged;
_ret = (alive player and {(player distance _veh) <= 7} and {(vehicle player == player)} and {speed _veh < 3} and {not zlt_mutexAction} and {_dmged} and {alive _veh});
_ret;
};



zlt_fnc_heavyRepair = {
_caller = player;
_truck = vehicle _caller;
_veh = cursorTarget;
if (isNil "_veh" or {isNull _truck} or {isNull _veh}) exitWith {false};


if (zlt_mutexAction) exitWith {
	STR_ANOTHER_ACTION call zlt_fnc_notify;
};
if (_truck getVariable ["zlt_repair_cargo", 0] <= 0) then {
	STR_REPAIR_TRUCK_DEPLETED call zlt_fnc_notify;
};

if (not alive player or vehicle player == player or speed _veh > 3 or _veh distance _truck > 15 ) exitWith {STR_REPAIR_CONDITIONS call zlt_fnc_notify;};

_repairFinished = false;
zlt_mutexAction = true;	
_maxlength = _veh getVariable["zlt_longrepairTruck",DEFAULT_FULLREPAIR_LENGTH];
_vehname = getText ( configFile >> "CfgVehicles" >> typeOf(_veh) >> "displayName");
_length = _maxlength;
while { alive player and alive _truck and alive _veh and vehicle _caller != _caller and speed _veh <= 3 and not _repairFinished and zlt_mutexAction and _veh distance _truck <= 15 } do {			
	(format[sTR_REPAIR_MSG_STRING, _length, _vehname] ) call zlt_fnc_notify;
	if (_length <= 0) then {_repairFinished = true;};
	_length = _length - 1;
	sleep 1;
};

if (_repairFinished) then {
	STR_REPAIR_FINISHED call zlt_fnc_notify;
	[_veh,"zlt_fnc_fullrepair", _veh] call bis_fnc_MP;
	_truck setVariable ["zlt_repair_cargo", ( (_truck getVariable ["zlt_repair_cargo", 0] )- (1 / DEFAULT_REPAIR_TRUCK_USES) ), true] ;

	_veh setVariable["zlt_longrepairTruck", nil, true];
	_veh setVariable["zlt_fullrepair_times", (_veh getVariable ["zlt_fullrepair_times",0]) + 1 , true ];
} else {
	STR_REPAIR_INTERRUPTED call zlt_fnc_notify;
	_veh setVariable["zlt_longrepairTruck",_length, true];
};
zlt_mutexAction = false;  	
};

zlt_pushapc = {
private ["_veh","_unit"];
_veh = vehicle player;

if (zlt_mutexAction) exitWith {};
zlt_mutexAction = true;
sleep 1.;
_spd = 3;
_dir = direction _veh;
_veh setVelocity [(sin _dir)*_spd, (cos _dir)*_spd, 0];  
zlt_mutexAction = false;
};


// obsolete
zlt_fnc_heavyRepairCOnd = {
_truck = vehicle player;
_veh = cursorTarget;
if (isNull _truck or isNull _veh) exitWith {false};
_isRepair = _truck getVariable ["zlt_repair_cargo", -1];
if (_isRepair == -1) exitWith {false};

_res = _veh distance _truck <= 15 and {player == (driver _truck)} and {(_veh isKindOf "LandVehicle" or _veh isKindOf "Ship" or _veh isKindOf "Air")} and {alive _truck} and {alive player} and {alive _veh} and {not zlt_mutexAction} and {speed _veh <= 3} and {(damage _veh != 0)};
_res;

};


if (isNil "zlt_cancelActionId") then {
zlt_cancelActionId = player addAction["<t color='#0000ff'>"+STR_CANCEL_ACTION+"</t>", {zlt_mutexAction = false}, [], 10, false, true, '',' zlt_mutexAction  '];

player addAction["<t color='#ff0000'>"+STR_FIELD_REPAIR+"</t>", zlt_prc_repairvehicle, [], -1, false, true, '','[] call zlt_fnc_repair_cond'];
player addAction["<t color='#ff0000'>"+STR_SERIOUS_REPAIR+ "</t>", zlt_fnc_heavyRepair, [], -1, false, true, '','_truck=(vehicle player);_truck getVariable ["zlt_repair_cargo", -1] != -1 and {alive cursorTarget} and {_truck distance cursorTarget <= 15} and {(cursorTarget isKindOf "LandVehicle" or cursorTarget isKindOf "Ship" or cursorTarget isKindOf "Air")} and {not zlt_mutexAction} and {speed cursorTarget <= 3} and {(damage cursorTarget != 0)}'];
player addAction["<t color='#FF9900'>"+STR_PUSH_APC+"</t>",zlt_pushapc,[],5,false,true,"","canMove (vehicle player) and ((vehicle player) isKindOf 'Wheeled_APC_F') and player == driver (vehicle player) and surfaceIsWater getpos (vehicle player)  and abs(speed (vehicle player) ) < 3 and not zlt_mutexAction"];   

player createDiarySubject [sTR_SCRIPTS_NAME,STR_SCRIPTS_NAME];
player createDiaryRecord [sTR_SCRIPTS_NAME,[sTR_SCRIPT_NAME, STR_HELP]];


};

player addEventHandler ["Respawn", {
zlt_cancelActionId = player addAction["<t color='#0000ff'>"+STR_CANCEL_ACTION+"</t>", {zlt_mutexAction = false}, [], 10, false, true, '',' zlt_mutexAction  '];

player addAction["<t color='#ff0000'>"+STR_FIELD_REPAIR+"</t>", zlt_prc_repairvehicle, [], -1, false, true, '','[] call zlt_fnc_repair_cond'];
player addAction["<t color='#ff0000'>"+STR_SERIOUS_REPAIR+ "</t>", zlt_fnc_heavyRepair, [], -1, false, true, '','_truck=(vehicle player);_truck getVariable ["zlt_repair_cargo", -1] != -1 and {alive cursorTarget} and {_truck distance cursorTarget <= 15} and {(cursorTarget isKindOf "LandVehicle" or cursorTarget isKindOf "Ship" or cursorTarget isKindOf "Air")} and {not zlt_mutexAction} and {speed cursorTarget <= 3} and {(damage cursorTarget != 0)}'];
player addAction["<t color='#FF9900'>"+STR_PUSH_APC+"</t>",zlt_pushapc,[],5,false,true,"","canMove (vehicle player) and ((vehicle player) isKindOf 'Wheeled_APC_F') and player == driver (vehicle player) and surfaceIsWater getpos (vehicle player)  and abs(speed (vehicle player) ) < 3 and not zlt_mutexAction"];   
}];

Edited by zealot111

Share this post


Link to post
Share on other sites
Guest

Thanks for sending us the release :cool:

Release frontpaged on the Armaholic homepage.

==============================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites

Latest version:

All files integrated into one script. Installation and use greatly simplificated.

Now it repairs only wheels, Engine and Tracks.

Use:

[] execVM "zlt_fieldrepair.sqf";

from init.sqf

(Created by script vehicles will not have this ability, only vehicles placed in editor are)

zlt_fieldrepair.sqf:

// v1c by [sTELS]Zealot
// Just add 
// [] execVM "zlt_fieldrepair.sqf";

#define DEFAULT_REPAIR_LENGTH 180
private ["_veh"];
_veh = [_this, 0, objNull] call BIS_fnc_param;

if (isDedicated) exitWith {};

zlt_repair_hps = ["HitLFWheel","HitLBWheel","HitLMWheel","HitLF2Wheel","HitRFWheel","HitRBWheel","HitRMWheel","HitRF2Wheel" ,"HitEngine", "HitLTrack","HitRTrack"];
zlt_hardRepairParts = ["HitEngine", "HitLTrack","HitRTrack"];

zlt_fnc_vehicledamaged = {
private ["_veh","_vehtype","_flag"];
_veh =  [_this, 0] call BIS_fnc_param;
if (isNil {_veh}) exitWith {false};
_vehtype = typeOf _veh;
_flag = false;
{
	_cdmg = _veh getHitPointDamage (_x);
	if (not isNil {_cdmg} ) then {
		if (_cdmg > 0.64) exitWith {_flag = true};
	};
}  forEach zlt_repair_hps;
_flag;
};

zlt_fnc_partrepair = {
private "_veh";
_veh = [_this, 0] call BIS_fnc_param;
if (isNil {_veh} ) exitWith {}; 
{
	_dmg = (_veh getHitPointDamage _x);
	if (not isNil {_dmg}) then {
		if ( _dmg > 0.64 ) then {
			if (_x in zlt_hardRepairParts) then {
				_veh setHitPointDamage [_x,0.64];
			} else {
				_veh setHitPointDamage [_x,0];
			};
		};
	};
} foreach zlt_repair_hps; 
};



zlt_fnc_notify = {
 [ format["<t size='0.75' color='#ffff00'>%1</t>",_this], 0,1,5,0,0,301] spawn bis_fnc_dynamicText;
};

zlt_fnc_hastk = {
private ["_ret"];
_ret = 0;
if ("ToolKit" in (items player)) then {_ret = 1;};
if ("ToolKit" in (itemCargo _veh)) then {_ret = 2;};
if ( (_veh getVariable ["zlt_longrepair_times",0] ) == 0) then {_ret = 3;};
_ret;
};


zlt_fnc_removeitemfromcargo = {
private ["_veh"];
_item = [_this,0,""] call BIS_fnc_param;
_veh = [_this,1] call BIS_fnc_param;
_allitems = itemcargo _veh;
clearItemCargoGlobal _veh;
_allitems = _allitems call BIS_fnc_consolidateArray;
_n = [_allitems, _item] call BIS_fnc_findInPairs;
_allitems set [_n, [(_allitems select _n) select 0, ((_allitems select _n) select 1) - 1]];
   { _veh addItemCargoGlobal [_x select 0, _x select 1 ];} foreach _allitems;
};





zlt_prc_repairvehicle = {
private ["_veh"];
_veh = (nearestObjects[player, ["LandVehicle","Air","Ship"], 5] select 0);
if (isNil {_veh}) exitWith {};
if (zlt_mutexAction) exitWith {
	"Another action in process." call zlt_fnc_notify;
};
if (not alive player or (player distance _veh) > 5 or (vehicle player != player) or speed _veh > 3) exitWith {"Bad conditions for repair." call zlt_fnc_notify;};
_hastk = [] call zlt_fnc_hastk;
if ( _hastk == 0 ) exitWith {"Need ToolKit in inventory yours or vehicle." call zlt_fnc_notify;};
_repairFinished = false;
zlt_mutexAction = true;  
_lastPlayerState = animationState player;
player playActionNow "medicstartup";
sleep 0.5;
_maxlength = _veh getVariable["zlt_longrepair",DEFAULT_REPAIR_LENGTH];
_vehname = getText ( configFile >> "CfgVehicles" >> typeOf(_veh) >> "displayName");
_length = _maxlength;
while {alive player and (player distance _veh) < 5 and (vehicle player == player) and speed _veh < 3 and not _repairFinished and zlt_mutexAction and (["medic",animationState player] call BIS_fnc_inString)} do {		
//	diag_log ("ANIM STATE = "+str(animationState player));	
	(format["%2 will be repaired in %1 Ñек. ", _length, _vehname] ) call zlt_fnc_notify;
	if (_length <= 0) then {_repairFinished = true;};
	_length = _length - 1;
	sleep 1;
	_hastk = [] call zlt_fnc_hastk;
	if (_hastk <= 0) exitWith {"Need ToolKit in inventory yours or vehicle." call zlt_fnc_notify; sleep 1.;};	
};
if (_repairFinished) then {
	_hastk = [] call zlt_fnc_hastk;
	if (_hastk == 0) exitWith {"Need ToolKit in inventory yours or vehicle." call zlt_fnc_notify; sleep 1.;};	
	"Repair completed." call zlt_fnc_notify;
	[_veh,"zlt_fnc_partrepair", _veh] call bis_fnc_MP;
	if (_hastk == 1) then {player removeItem "ToolKit";} else { ["ToolKit",_veh] call zlt_fnc_removeitemfromcargo;};
	_veh setVariable["zlt_longrepair",DEFAULT_REPAIR_LENGTH, true];
	_veh setVariable["zlt_longrepair_times", (_veh getVariable ["zlt_longrepair_times",0]) + 1 , true ];
} else {
	"Repair interrupted." call zlt_fnc_notify;
	_veh setVariable["zlt_longrepair",_length, true];
};
zlt_mutexAction = false;  
player playActionNow "medicstop";
};


waitUntil {player == player};

zlt_mutexAction = false;

zlt_fnc_repair_cond = {
private ["_veh","_ret"];
_ret = false;
_veh = (nearestObjects[player, ["LandVehicle","Air","Ship"], 5] select 0);
if (isNil {_veh}) exitWith {_ret};
_dmged = _veh call zlt_fnc_vehicledamaged;
_ret = (alive player and (player distance _veh) < 5 and (vehicle player == player) and speed _veh < 3 and not zlt_mutexAction and _dmged);
_ret;
};


zlt_fnc_addRepairActions = {
private ["_veh"];
_veh = _this select 0;
if (_veh isKindOf "LandVehicle" or _veh isKindOf "Ship" or _veh isKindOf "Air") then {
	_veh addAction["<t color='#ff0000'>Field repair</t>", zlt_prc_repairvehicle, [], -1, false, false, '','alive _target and (_target call zlt_fnc_vehicledamaged) and (_this distance _target) < 7 and (vehicle _this == _this) and alive _this and not zlt_mutexAction'];
	_veh addAction["<t color='#0000ff'>Cancel</t>", {zlt_mutexAction = false}, [], 10, false, false, '',' zlt_mutexAction  '];
};
};



if (isNull _veh) then {
{ [_x] call zlt_fnc_addRepairActions} foreach vehicles;
} else {
[_veh] call zlt_fnc_addRepairActions;
};



Share this post


Link to post
Share on other sites
Guest

New version frontpaged on the Armaholic homepage.

==============================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites

Tried this yesterday and like it.. thanks for the update

Share this post


Link to post
Share on other sites

New version. Fixed minor bugs and added support for repair tracks. Repair truck also fixes vehicles for 3 min., but completely restores them. Repair truck can be used 5 times. To use repair track you should sat into drivers place of the damaged vehicle then look on repair truck and select 'Full repair' in the menu.

Any suggestions welcome.

// v1e by [sTELS]Zealot
// Just add 
// [] execVM "zlt_fieldrepair.sqf";

#define DEFAULT_REPAIR_LENGTH 180
#define DEFAULT_REPAIR_TRUCK_USES 5

#define STR_FIELD_REPAIR "Field repair"
#define STR_CANCEL_ACTION "Cancel action"
#define STR_SERIOUS_REPAIR "Full repair"
#define STR_REPAIR_CONDITIONS "Bad conditions for repair"
#define STR_ANOTHER_ACTION "Another action in progress"
#define STR_NEED_TOOLKIT "Need ToolKit in inventory yours or vehicle."
#define STR_REPAIR_INTERRUPTED "Repair interrupted"
#define STR_REPAIR_FINISHED "Repair finished"
#define STR_REPAIR_MSG_STRING "%2 will be repaired in %1 sec"
#define STR_REPAIR_TRUCK_DEPLETED "Spare parts depleted in repair truck"
#define STR_HELP "Realistic field repair (Ðвтор: Zealot) <br/>Script gives each player ability to repair vehicles. <br/>- Repair lasts for 3 min., it can be interrupted and the continued, time saves.<br/>- Each vehicle could be repaired 1 time for spare parts stored in the vehicle itself.For the next repairs you should have Toolkit in your backpack or in vehicle cargo.<br/>- Field repair fixes only tyres, engine and tracks and only to 'Yellow state'.<br/>- Repair from repair trucks also lasts 3 min. but completely repairs vehicles. Repair truck can be used 5 times, then spare parts in it will be depleted.<br/>- To use repair truck you should sat on the drivers place of the damaged vehicle then look on repair truck and select 'Full repair' in menu.<br/>"
#define STR_SCRIPTS_NAME "Scripts"
#define STR_SCRIPT_NAME "Field repair"
#define STR_PUSH_APC "Push vehicle"

private ["_veh"];
_veh = [_this, 0, objNull] call BIS_fnc_param;

if (isDedicated) exitWith {};
waitUntil {player == player};

zlt_repair_hps = ["HitLFWheel","HitLBWheel","HitLMWheel","HitLF2Wheel","HitRFWheel","HitRBWheel","HitRMWheel","HitRF2Wheel" ,"HitEngine", "HitLTrack","HitRTrack"];
zlt_hardRepairParts = ["HitEngine", "HitLTrack","HitRTrack"];

zlt_fnc_vehicledamaged = {
private ["_veh","_vehtype","_flag"];
_veh =  [_this, 0] call BIS_fnc_param;
if (isNil {_veh}) exitWith {false};
_vehtype = typeOf _veh;
_flag = false;
{
	_cdmg = _veh getHitPointDamage (_x);
	if (not isNil {_cdmg} ) then {
		if (_cdmg > 0.64) exitWith {_flag = true};
	};
}  forEach zlt_repair_hps;
_flag;
};

zlt_fnc_partrepair = {
private "_veh";
_veh = [_this, 0] call BIS_fnc_param;
if (isNil {_veh} ) exitWith {}; 
{
	_dmg = (_veh getHitPointDamage _x);
	if (not isNil {_dmg}) then {
		if ( _dmg > 0.64 ) then {
			if (_x in zlt_hardRepairParts) then {
				_veh setHitPointDamage [_x,0.64];
			} else {
				_veh setHitPointDamage [_x,0];
			};
		};
	};
} foreach zlt_repair_hps; 
};



zlt_fnc_notify = {
 [ format["<t size='0.75' color='#ffff00'>%1</t>",_this], 0,1,5,0,0,301] spawn bis_fnc_dynamicText;
};

zlt_fnc_hastk = {
private ["_ret"];
_ret = 0;
if ("ToolKit" in (items player)) then {_ret = 1;};
if ("ToolKit" in (itemCargo _veh)) then {_ret = 2;};
if ( (_veh getVariable ["zlt_longrepair_times",0] ) == 0) then {_ret = 3;};
_ret;
};


zlt_fnc_removeitemfromcargo = {
private ["_veh"];
_item = [_this,0,""] call BIS_fnc_param;
_veh = [_this,1] call BIS_fnc_param;
_allitems = itemcargo _veh;
clearItemCargoGlobal _veh;
_allitems = _allitems call BIS_fnc_consolidateArray;
_n = [_allitems, _item] call BIS_fnc_findInPairs;
_allitems set [_n, [(_allitems select _n) select 0, ((_allitems select _n) select 1) - 1]];
   { _veh addItemCargoGlobal [_x select 0, _x select 1 ];} foreach _allitems;
};





zlt_prc_repairvehicle = {
private ["_veh"];
_veh = (nearestObjects[player, ["LandVehicle","Air","Ship"], 7] select 0);
if (isNil {_veh}) exitWith {};
if (zlt_mutexAction) exitWith {
	STR_ANOTHER_ACTION call zlt_fnc_notify;
};
if (not alive player or (player distance _veh) > 7 or (vehicle player != player) or speed _veh > 3) exitWith {STR_REPAIR_CONDITIONS call zlt_fnc_notify;};
_hastk = [] call zlt_fnc_hastk;
if ( _hastk == 0 ) exitWith {STR_NEED_TOOLKIT call zlt_fnc_notify;};
_repairFinished = false;
zlt_mutexAction = true;  
_lastPlayerState = animationState player;
player playActionNow "medicstartup";
sleep 0.5;
_maxlength = _veh getVariable["zlt_longrepair",DEFAULT_REPAIR_LENGTH];
_vehname = getText ( configFile >> "CfgVehicles" >> typeOf(_veh) >> "displayName");
_length = _maxlength;
while {alive player and (player distance _veh) < 7 and (vehicle player == player) and speed _veh < 3 and not _repairFinished and zlt_mutexAction and (["medic",animationState player] call BIS_fnc_inString)} do {		
//	diag_log ("ANIM STATE = "+str(animationState player));	
	(format[sTR_REPAIR_MSG_STRING, _length, _vehname] ) call zlt_fnc_notify;
	if (_length <= 0) then {_repairFinished = true;};
	_length = _length - 1;
	sleep 1;
	_hastk = [] call zlt_fnc_hastk;
	if (_hastk <= 0) exitWith {STR_NEED_TOOLKIT call zlt_fnc_notify; sleep 1.;};	
};
if (_repairFinished) then {
	_hastk = [] call zlt_fnc_hastk;
	if (_hastk == 0) exitWith {STR_NEED_TOOLKIT call zlt_fnc_notify; sleep 1.;};	
	STR_REPAIR_FINISHED call zlt_fnc_notify;
	[_veh,"zlt_fnc_partrepair", _veh] call bis_fnc_MP;
	if (_hastk == 1) then {player removeItem "ToolKit";} else { ["ToolKit",_veh] call zlt_fnc_removeitemfromcargo;};
	_veh setVariable["zlt_longrepair",DEFAULT_REPAIR_LENGTH, true];
	_veh setVariable["zlt_longrepair_times", (_veh getVariable ["zlt_longrepair_times",0]) + 1 , true ];
} else {
	STR_REPAIR_INTERRUPTED call zlt_fnc_notify;
	_veh setVariable["zlt_longrepair",_length, true];
};
zlt_mutexAction = false;  
player playActionNow "medicstop";
};


waitUntil {player == player};

zlt_mutexAction = false;

zlt_fnc_repair_cond = {
private ["_veh","_ret"];
_ret = false;
_veh = (nearestObjects[player, ["LandVehicle","Air","Ship"], 7] select 0);
if (isNil {_veh}) exitWith {_ret};
_dmged = _veh call zlt_fnc_vehicledamaged;
_ret = (alive player and (player distance _veh) < 5 and (vehicle player == player) and speed _veh < 3 and not zlt_mutexAction and _dmged);
_ret;
};

zlt_fnc_fullrepair = {
private "_veh";
_veh = [_this, 0] call BIS_fnc_param;
_veh setDamage 0;
};


zlt_fnc_heavyRepair = {
_truck =_this select 0; //): Object - the object which the action is assigned to 
_caller =_this select 1; //): Object - the unit that activated the action 
_veh = vehicle _caller;
if (zlt_mutexAction) exitWith {
	STR_ANOTHER_ACTION call zlt_fnc_notify;
};
if (_truck getVariable ["zlt_repair_cargo", 0] <= 0) then {
	STR_REPAIR_TRUCK_DEPLETED call zlt_fnc_notify;
};

if (not alive player or vehicle _caller == _caller or speed _veh > 3 or driver _veh != _caller or _veh distance _truck > 10 ) exitWith {STR_REPAIR_CONDITIONS call zlt_fnc_notify;};

_repairFinished = false;
zlt_mutexAction = true;	
_maxlength = _veh getVariable["zlt_longrepairTruck",DEFAULT_REPAIR_LENGTH];
_vehname = getText ( configFile >> "CfgVehicles" >> typeOf(_veh) >> "displayName");
_length = _maxlength;
while { alive player and alive _truck and alive _veh and driver _veh == _caller and speed _veh <= 3 and not _repairFinished and zlt_mutexAction and _veh distance _truck < 10 } do {			
	(format[sTR_REPAIR_MSG_STRING, _length, _vehname] ) call zlt_fnc_notify;
	if (_length <= 0) then {_repairFinished = true;};
	_length = _length - 1;
	sleep 1;
};

if (_repairFinished) then {
	STR_REPAIR_FINISHED call zlt_fnc_notify;
	[_veh,"zlt_fnc_fullrepair", _veh] call bis_fnc_MP;
	_truck setVariable ["zlt_repair_cargo", ( (_truck getVariable ["zlt_repair_cargo", 0] )- (1 / DEFAULT_REPAIR_TRUCK_USES) )] ;

	_veh setVariable["zlt_longrepairTruck", nil, true];
	_veh setVariable["zlt_longrepair_times", (_veh getVariable ["zlt_longrepair_times",0]) + 1 , true ];
} else {
	STR_REPAIR_INTERRUPTED call zlt_fnc_notify;
	_veh setVariable["zlt_longrepairTruck",_length, true];
};
zlt_mutexAction = false;  	
};

zlt_pushapc = {
private ["_veh","_unit"];
_veh = vehicle player;

if (zlt_mutexAction) exitWith {};
zlt_mutexAction = true;
sleep 1.;
_spd = 3;
_dir = direction _veh;
_veh setVelocity [(sin _dir)*_spd, (cos _dir)*_spd, 0];  
zlt_mutexAction = false;
};


zlt_fnc_heavyRepairCOnd = {
_truck = _this select 0;
_player = _this select 1;
_player == (driver (vehicle _player)) and (vehicle _player isKindOf "LandVehicle" or vehicle _player isKindOf "Ship" or vehicle _player isKindOf "Air") and alive _truck and alive _player and not zlt_mutexAction and speed vehicle _player <= 3 and (damage (vehicle _player) != 0);

};

zlt_fnc_addRepairActions = {
private ["_veh"];
_veh = _this select 0;
if (_veh isKindOf "LandVehicle" or _veh isKindOf "Ship" or _veh isKindOf "Air") then {
	_veh addAction["<t color='#ff0000'>"+STR_FIELD_REPAIR+"</t>", zlt_prc_repairvehicle, [], -1, false, false, '','alive _target and (_target call zlt_fnc_vehicledamaged) and (_this distance _target) < 7 and (vehicle _this == _this) and alive _this and not zlt_mutexAction'];

};
if (getRepairCargo _veh > 0) then {
	_veh setRepairCargo 0;
	_veh setVariable ["zlt_repair_cargo", 1];
	_veh addAction["<t color='#ff0000'>"+STR_SERIOUS_REPAIR+ "</t>", zlt_fnc_heavyRepair, [], -1, false, false, '','[_target, _this] call zlt_fnc_heavyRepairCOnd'];
};
if (_veh isKindOf "Wheeled_APC_F") then {
	_veh addAction ["<t color='#FF9900'>"+STR_PUSH_APC+"</t>",zlt_pushapc,[],5,false,true,"","canMove _target and _this == driver _target and surfaceIsWater getpos _this and abs(speed _target) < 3 and not zlt_mutexAction"];   
};
};

if (isNil "zlt_cancelActionId") then {
zlt_cancelActionId = player addAction["<t color='#0000ff'>"+STR_CANCEL_ACTION+"</t>", {zlt_mutexAction = false}, [], 10, false, false, '',' zlt_mutexAction  '];
player createDiarySubject [sTR_SCRIPTS_NAME,STR_SCRIPTS_NAME];
player createDiaryRecord [sTR_SCRIPTS_NAME,[sTR_SCRIPT_NAME, STR_HELP]];
};


if (isNull _veh) then {
{ if not (_x getVariable["ZLT_NOREPAIR",false]) then {[_x] call zlt_fnc_addRepairActions};} foreach vehicles;
} else {
[_veh] call zlt_fnc_addRepairActions;
};



Edited by zealot111

Share this post


Link to post
Share on other sites

Thx for this great script, you wrote that this script can't be used for script spawned vehicle, could it be one of your next implementation?

Share this post


Link to post
Share on other sites
Thx for this great script, you wrote that this script can't be used for script spawned vehicle, could it be one of your next implementation?

This scripts adds repair action to the all vehicles using addAction command. For all created by the script vehicles you should manually call

[_vehicle] call zlt_fnc_addRepairActions;

_vehicle is variable with your created by the script vehicle.

Or you may just insert this code in your init.sqf which automatically will do this, but sometimes (on heavy loaded MP server) it is not advised...:

if (isServer) then {
while {true} do {

sleep 15.6;

{ if not (_x getVariable["ZLT_REPAIR1",false]) then {
_x setVariable["ZLT_REPAIR1",true]   ;[_x] call compile preprocessFileLineNumbers "zlt_fieldrepair.sqf";
};} foreach vehicles;

};};

Note, that you should not add

[] execVM "zlt_fieldrepair.sqf";

to your init.sqf when using this way.

Edited by zealot111

Share this post


Link to post
Share on other sites
Guest

New version frontpaged on the Armaholic homepage.

==============================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites

Thank you very much for your fast response! i love this script!

Share this post


Link to post
Share on other sites

Slightly fixed, as it seems that code didnt works in previous variant

if (isServer) then {
while {true} do {

sleep 15.6;

{ if not (_x getVariable["ZLT_REPAIR1",false]) then {
_x setVariable["ZLT_REPAIR1",true]   ;[_x] call compile preprocessFileLineNumbers "zlt_fieldrepair.sqf";
};} foreach vehicles;

};};

Share this post


Link to post
Share on other sites

Updated first thread post with latest version of the script.

Edited by zealot111

Share this post


Link to post
Share on other sites
Guest

Thanks for sending us the latest release :cool:

Release frontpaged on the Armaholic homepage.

==============================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites
Thx for the fast update :)

I have updated the script. You dont need any complicated ways to handle vehicles created by scripts. It works now just "out of the box". Just use '[true] execVM "zlt_fieldrepair.sqf";' from init.sqf if you use repair vehicles created by scripts. If you dont use repair trucks created by scripts just use '[] execVM "zlt_fieldrepair.sqf";'

Share this post


Link to post
Share on other sites

Love the script zealot, any chance we'll see it be able to see repair of vehicles spawned after mission start at some point?

Share this post


Link to post
Share on other sites
Guest

Thanks for the headsup about the new version :cool:

New version frontpaged on the Armaholic homepage.

==============================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites

Is it possible to modify the default repair time?

Disregard: Figured out that if I modify #define DEFAULT_REPAIR_LENGTH with a lower value this will reduce the length of time necessary to complete the action.

Edited by HaveANiceDay

Share this post


Link to post
Share on other sites

I have to say..

Those of you who have somewhat experience in Editor, keep talking in script language. Because you "talk" advanced, the editor community doesnt expand.

No one cares if your a prof* in editor.

Either you explain something, so everyone understands, or you just dont. Cuz iv wasted time reading this "seems to be" wonderful script, that someone has spent time creating.. and i would love to use it.

Im going to ask now; Whats the STEP BY STEP procedure to ad this script to my mission.

What iv done, just by reading this topic;

1. Copy the code and paste it into a NEW sqm file, that i called "zlt_fieldrepair.sqf".

2. I had to copy my init sqm file, and remove its content, to even be able to get a NEW sqm file in the mp folder.

Is everyone able to repair the vehicle 5 times ? Or do u need the Kit? Do u have to chhose a repairman/engineer class? etc etc

---------- Post added at 12:06 ---------- Previous post was at 11:34 ----------

I have to say..

Those of you who have somewhat experience in Editor, keep talking in script language. Because you "talk" advanced, the editor community doesnt expand.

No one cares if your a prof* in editor.

Either you explain something, so everyone understands, or you just dont. Cuz iv wasted time reading this "seems to be" wonderful script, that someone has spent time creating.. and i would love to use it.

Im going to ask now; Whats the STEP BY STEP procedure to ad this script to my mission.

What iv done, just by reading this topic;

1. Copy the code and paste it into a NEW sqm file, that i called "zlt_fieldrepair.sqf".

2. I had to copy my init sqm file, and remove its content, to even be able to get a NEW sqm file in the mp folder.

Is everyone able to repair the vehicle 5 times ? Or do u need the Kit? Do u have to chhose a repairman/engineer class? etc etc

Alright. So i extracted the sqf file this time, from armaholic, into the mpfolder. I added the code ;

//[] execVM "zlt_fieldrepair.sqf";

EXACTLY as you see it, as the LAST code in my INIT file. Is this correct ?

All i want, is for the script to work on the vehicles that i spawned in map editor. They are placed on ground as empty hunters.. id like them to be affected by the script.

Wel i added all this in the MP folder, i LOADED the editor map, and saved usermission and export to MP... but nothing happens when i load the map online.

Share this post


Link to post
Share on other sites
I have to say..

Im going to ask now; Whats the STEP BY STEP procedure to ad this script to my mission.

What iv done, just by reading this topic;

1. Copy the code and paste it into a NEW sqm file, that i called "zlt_fieldrepair.sqf".

2. I had to copy my init sqm file, and remove its content, to even be able to get a NEW sqm file in the mp folder.

Well i added all this in the MP folder, i LOADED the editor map, and saved usermission and export to MP... but nothing happens when i load the map online.

Step by step guide:

1. Enter into MP mission editor throught Play->Multiplayer->Host new session-> <<New - Editor >> from Main menu of the game.

2. Place units which you wants

3. Click "Save" button and remember your mission name

4. Look into system folder

C:\Users\[Your system user name]\Documents\Arma 3 - Other Profiles\[Your Arma3 profile name]\MPMissions\[Your mission name from p. 3].Stratis (or Altis)

(Or Documents\Arma 3 - Other Profiles\[Your Arma3 profile name]\MPMissions\[Your mission name from p. 3].Stratis (or Altis) )

For example for me its:

C:\Users\Zealot\Documents\Arma 3 - Other Profiles\[sTELS]Zealot\MPMissions\sdfd.Stratis

where sdfd - mission name.

This is the folder where all scripts and other mission regarding stuff should be placed.

5. Copy zlt_fieldrepair.sqf into that folder.

6. You should create init.sqf file manually by notepad or other editor, I suggest Notepad++ ( 'init.sqf' - This is "magic" name for script file which will be executed each time on mission start )

7. Put

[] execVM "zlt_fieldrepair.sqf";

string into that file. This code just runs the file with repair script.

8. When you will run your mission in editor or pack mission and run on the server script will be running and working.

I have prepared sample mission: http://stels-arma.ucoz.ru/sample.Stratis.zip

Just unpack file into beforementioned MPMissions folder.

Share this post


Link to post
Share on other sites

Alright, it worked.

Great script. Enhances the milsim.

However, im not sure if this is something you can adjust, but the Revive animation seems a bit off. The head of the soldier slides far out "long neck" for some odd reason.

This aint important.. but if anything, then this should be worked on.

Aswell to the amount o time spent repairing. Is there a way to adjust the time ? Say the vehicle is 99%broken down, id say the 3min is good. What about tired only, or a small dmg to it; put at 1min+ ?

I just know that as soon as small things immobilises the vehicle, and ppl want to get it back up, 3min could be slightly long. I changed 2 weels on my "Iveco" back in Afgh, in under 2min. Hehe.. Just saying.

Not having a fixed time, would be even more milsim.

GREAT SCRIPT!

Share this post


Link to post
Share on other sites

Love the script, but it would be very cool if we were able to fix downed choppers as well.

I was looking to implement it myself, but I noticed that I don't know the names of chopper hitpoint parts. I tried searching for them, but I only found hitpoints for tracked vehicles and cars.

Any ideas?

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

×