Jump to content
Sign in to follow this  
outlaw

Need help about Engineer repair script

Recommended Posts

Hi,

After i saw this thread , i have similar requirement about the script for my MP mission but with some more condition like;

-player is an engineer class;

-player is looking at and is close to a vehicle;

-vehicle has at least 10% damage;

- engineer could repair 80% of vehicle's damage (20% damage left) ;

- engineer could use repair ability only once and then he needs to replenish his repair ability at base or some specific area (trigger area?) ;

- engineer need to carry "Wire-cutter" to repair vehicle.

I've actually tried to isolate engineer repair system from Domination map but because my lack of programming skill , so i got no luck at all :(

Any help or advice would be really appreciated :)

Edited by outlaw

Share this post


Link to post
Share on other sites

thi is what i use you just need to tweak it to how you need it.

this lets any engineer on west team repair and refuel a damaged vehicle.

init.sqf

[player] execVM "vehiclerepair.sqf";

vehiclerepair.sqf

if ! isdedicated then                                   
{

if (count _this > 1) then {
(_this select 1) playMove "ActsPercSnonWnonDnon_carFixing2";
sleep 7;
(_this select 0) setDammage 0;
(_this select 0) setFuel 1;	 
};

if (!isNil ("vehicleRepairInitiated")) exitWith {};
vehicleRepairInitiated = true;
waitUntil {sleep 1; alive player};

while {true} do {
{

	if (!(_x getVariable ["RepairsInitiated", false])) then {
		_id = _x addAction ["Repair Vehicle", "vehiclerepair.sqf", [], 1, false, true, "", "(getDammage _target) < 1 AND (getDammage _target) > 0 AND (typeOf _this) == 'aawInfantryEngineer' AND (vehicle _this) == _this"];
		_x setVariable ["RepairsInitiated", true, false];
	};
} foreach vehicles;
sleep 5;

};

};

good luck mate i dont have time atm to help to tweak it

---------- Post added at 11:47 ---------- Previous post was at 11:45 ----------

sorry forgot this but

this line here

(typeOf _this) == 'aawInfantryEngineer'

i used

aawInfantryEngineer

you need to change this to the engineer classname you are using

Share this post


Link to post
Share on other sites

Thank you for your help , i have some more question about the script ;

If i used USMC engineer , BAF engineer and US engineer for engineer class in my MP mission , how could i do with that ?

(typeOf _this) == 'engineer'

or

(typeOf _this) == 'USMC_SoldierS_Engineer, US_Soldier_Engineer_EP1,BAF_Soldier_EN_W'

Share this post


Link to post
Share on other sites

maybe try placing in an array

_units = ['USMC_SoldierS_Engineer', 'US_Soldier_Engineer_EP1','BAF_Soldier_EN_W'];

(typeOf _this) == _units

i know kylana or twirly will know a more positive answer but the array is where i would start

---------- Post added at 17:59 ---------- Previous post was at 17:56 ----------

to only repair 80% of vehicles damge use

(_this select 0) setDammage 0.3;

(_this select 0) setFuel 0.3;

as far as only work if unit is holding a wrench you need to place that in an if command

if ( code to check for uit has wrench in here ) then {

code in here

};

Share this post


Link to post
Share on other sites

Thank you for your help again hogman .

I have tried to tweak and tested your code with my MP mission (test with Editor and MP host on my PC) but I cannot seem to make it work ,

here is my tweak code ;

init.sqf

 [player] execVM "repair1.sqf";

repair1.sqf

if ! isdedicated then                                   
{

if (count _this > 1) then {
(_this select 1) playMove "ActsPercSnonWnonDnon_carFixing2";
sleep 7;
(_this select 0) setDammage 0.3;
(_this select 0) setFuel 1;	 
};


if (!isNil ("vehicleRepairInitiated")) exitWith {};
vehicleRepairInitiated = true;
_units = ['USMC_SoldierS_Engineer', 'US_Soldier_Engineer_EP1','BAF_Soldier_EN_W','BAF_Soldier_EN_DDPM','BAF_Soldier_EN_MTP','Soldier_Engineer_PMC','CDF_Soldier_Engineer'];
waitUntil {sleep 1; alive player};

while {true} do {
{


	if (!(_x getVariable ["RepairsInitiated", false])) then {                     
		_id = _x addAction ["Repair Vehicle", "repair1.sqf", [], 1, false, true, "", "(getDammage _target) < 1 AND (getDammage _target) > 0 AND (typeOf _this) == _unit AND (vehicle _this) == _this"];
		_x setVariable ["RepairsInitiated", true, false];
	};
} foreach vehicles;
sleep 5;

};

if !([player, "ACE_Wirecutter"] call ACE_fnc_HasWeapon) 
            exitwith {hintc "Wire cutters are required to service vehicles.";};

};

you could see that i have added some Domination's script at the end of code , not sure if it work or not.

Edited by outlaw

Share this post


Link to post
Share on other sites

yeah man i can see a few issues at first glance give me an hour or so and ill have a good look at it when i get home ;)

Share this post


Link to post
Share on other sites

what i changed is in red



if ! isdedicated then                                   
{

if (count _this > 1) then {
(_this select 1) playMove "ActsPercSnonWnonDnon_carFixing2";
sleep 7;
(_this select 0) setDammage 0.3;
(_this select 0) setFuel 1;	 
};


if (!isNil ("vehicleRepairInitiated")) exitWith {};
vehicleRepairInitiated = true;
_units = ['USMC_SoldierS_Engineer','US_Soldier_Engineer_EP1','BAF_Soldier_EN_W','BAF_Soldier_EN_DDPM','BAF_Soldier_EN_MTP','Soldier_Engineer_PMC','CDF_Soldier_Engineer'];
waitUntil {sleep 1; alive player};

while {true} do 
{

[color="#FF0000"]        if (![player, "ACE_Wirecutter"] call ACE_fnc_HasWeapon) then
       {[/color]	
         {		

[color="#FF0000"]		    if (!(_x getVariable ["RepairsInitiated", false])) then 
		{  [/color]                   
		    _id = _x addAction ["Repair Vehicle", "repair1.sqf", [], 1, false, true, "", "(getDammage _target) < 1 AND (getDammage _target) > 0 AND (typeOf _this) == _unit AND (vehicle _this) == _this"];
		    _x setVariable ["RepairsInitiated", true, false];
	    };

       } foreach vehicles;

[color="#FF0000"]		} else
       {
	  [player,nil,rsideChat,"Wire cutters are required to service vehicles!"] call RE; //multiplayer ready
       };[/color]		

};
sleep 5;

};

now i dont use ace so i dont know if this is corect


if ( [color="#FF0000"]![player, "ACE_Wirecutter"] call ACE_fnc_HasWeapon[/color] ) then

but i have placed it in the right spot in the if command.

this should all work now the array of engineer classnames is still a maybe in my mind but like i said its where i would start.

when testing this run arma with show script errors.

so the only 2 things that maybe wrong is

1) the array of classnames

2) the ace function.

hope all this helps mate.

I can vouch for the code as i gave it to you originally it works perfectly on a dedi and on singleplayer

---------- Post added at 22:07 ---------- Previous post was at 22:05 ----------

Ooops just proof checked it lol the sleep 5; needs to be moved up 1 };

Share this post


Link to post
Share on other sites

@Hogmason , Thanks again for your help but i still got a problem as picture below

252343_10151280338839696_283177201_n.jpg

I might have to remove this "engineer need to carry "Wire-cutter" to repair vehicle" feature , find another way to tweak this script with ACE , or just change from Wire-Cutter to anything else .

and here is the script

repair1.sqf

if ! isdedicated then                                   
{

if (count _this > 1) then {
(_this select 1) playMove "ActsPercSnonWnonDnon_carFixing2";
sleep 7;
(_this select 0) setDammage 0.3;
(_this select 0) setFuel 1;	 
};


if (!isNil ("vehicleRepairInitiated")) exitWith {};
vehicleRepairInitiated = true;
_units = ['USMC_SoldierS_Engineer','US_Soldier_Engineer_EP1','BAF_Soldier_EN_W','BAF_Soldier_EN_DDPM','BAF_Soldier_EN_MTP','Soldier_Engineer_PMC','CDF_Soldier_Engineer'];
waitUntil {sleep 1; alive player};

while {true} do 
{

       if (![player, "ACE_Wirecutter"] call ACE_fnc_HasWeapon) then
       {	
         {		

	    if (!(_x getVariable ["RepairsInitiated", false])) then 
		{                     
		    _id = _x addAction ["Repair Vehicle", "repair1.sqf", [], 1, false, true, "", "(getDammage _target) < 1 AND (getDammage _target) > 0 AND (typeOf _this) == _unit AND (vehicle _this) == _this"];
		    _x setVariable ["RepairsInitiated", true, false];
	    };

       } foreach vehicles;

	} else
       {
	  [player,nil,rsideChat,"Wire cutters are required to service vehicles!"] call RE; //multiplayer ready
       };		

};
sleep 5;

};

by the way , do you know how to make a script that made engineer could use repair ability only once and then he needs to replenish his repair ability at base or some specific area (trigger area?) ?

Share this post


Link to post
Share on other sites

ok so

a)

error type array expected bool

that is this line

if (![player, "ACE_Wirecutter"] call ACE_fnc_HasWeapon) then

the [ ] brackets are an array

so we will need to change this

also

the ! is not needed i do believe.

ok so ill have ago and research some for you tomorrow mate.

b)

by the way , do you know how to make a script that made engineer could use repair ability only once and then he needs to replenish his repair ability at base or some specific area (trigger area?) ?

yeah guess you can use public variables change the state of the varialbe once the engineer uses repair option then change the state back to original stat when player is near an object.

so you need to place in your init.sqf


if (isnil "repair_allowed") then {repair_allowed = 0;};

execVM "mechanic_replenish.sqf";

mechanic_replenish.sqf

// change repair_allowed variable to 1
///////////////////////////////////////
if (isServer) then 
{

_x = player

while {true} do 
{

	if ({(_x distance mechanic_shed) <10}) then 
	{

         	repair_allowed = 1; publicvariable "repair_allowed";
			_x switchMove "AinvPknlMstpSnonWrflDnon_medic3"; // change this to whatever animation you whant i think it gives the script some life so the player can c something is happaning
			sleep 10;
			[player,nil,rsideChat,"you have replenished your mechanical repair skill!"] call RE;

	};

};	

};	


then the repair script


[color="#FF0000"]if ( repair_allowed == 1 ) then
{[/color]

if ! isdedicated then                                   
{

if (count _this > 1) then {
(_this select 1) playMove "ActsPercSnonWnonDnon_carFixing2";
sleep 7;
(_this select 0) setDammage 0;
(_this select 0) setFuel 1;	 
};

if (!isNil ("vehicleRepairInitiated")) exitWith {};
vehicleRepairInitiated = true;
waitUntil {sleep 1; alive player};

while {true} do {
{

	if (!(_x getVariable ["RepairsInitiated", false])) then {
		_id = _x addAction ["Repair Vehicle", "HOG_scripts\HOG_mechanic\vehiclerepair.sqf", [], 1, false, true, "", "(getDammage _target) < 1 AND (getDammage _target) > 0 AND (typeOf _this) == 'aawInfantryEngineer' AND (vehicle _this) == _this"];
		_x setVariable ["RepairsInitiated", true, false];
	};
} foreach vehicles;
sleep 5;

};

};

};

un tested but should work

---------- Post added at 23:52 ---------- Previous post was at 23:50 ----------

also need to create an object on the map named mechanic_shed

once the engineer is near that shed he will get the repair skill added

Share this post


Link to post
Share on other sites

Ok I have encountered a problem while testing..

If i tested with dedi server , i'll never get any error on show script errors panel (but script didn't work)

and then i made my PC to be a LAN or Internet host , i'll get an error like this ;

311238_10151280604789696_782292959_n.jpg

here was the script ;

1st test

init.sqf

if (isnil "repair_allowed") then {repair_allowed = 0;};

execVM "mechanic_replenish.sqf";

[player] execVM "repair1.sqf";

mechanic_replenish.sqf

// change repair_allowed variable to 1
///////////////////////////////////////
if (isServer) then 
{

_x = player[color="#FF0000"];[/color] // add " ; " 

while {true} do 
{

	if ({(_x distance mechanic_shed) <10}) then 
	{

         	repair_allowed = 1; publicvariable "repair_allowed";
			_x switchMove "AinvPknlMstpSnonWrflDnon_medic3"; // change this to whatever animation you whant i think it gives the script some life so the player can c something is happaning
			sleep 10;
			[player,nil,rsideChat,"you have replenished your mechanical repair skill!"] call RE;

	};

};	

};

repair1.sqf

if ( repair_allowed == 1 ) then
{

if ! isdedicated then                                   
{

if (count _this > 1) then {
(_this select 1) playMove "ActsPercSnonWnonDnon_carFixing2";
sleep 7;
(_this select 0) setDammage 0;
(_this select 0) setFuel 1;	 
};

if (!isNil ("vehicleRepairInitiated")) exitWith {};
_units = ['USMC_SoldierS_Engineer', 'US_Soldier_Engineer_EP1','BAF_Soldier_EN_W','BAF_Soldier_EN_DDPM','BAF_Soldier_EN_MTP','Soldier_Engineer_PMC','CDF_Soldier_Engineer'];
vehicleRepairInitiated = true;
waitUntil {sleep 1; alive player};

while {true} do {
{

	if (!(_x getVariable ["RepairsInitiated", false])) then {
		_id = _x addAction ["Repair Vehicle", "repair1.sqf", [], 1, false, true, "", "(getDammage _target) < 1 AND (getDammage _target) > 0 AND (typeOf _this) == _unit AND (vehicle _this) == _this"];
		_x setVariable ["RepairsInitiated", true, false];
	};
} foreach vehicles;
sleep 5;

};

};

}

2nd Test

init.sqf

if (isnil "repair_allowed") then {repair_allowed = 0;};

execVM "mechanic_replenish.sqf"; 

mechanic_replenish.sqf

// change repair_allowed variable to 1
///////////////////////////////////////
if (isServer) then 
{

_x = player;

while {true} do 
{

	if ({(_x distance mechanic_shed) <10}) then 
	{

         	repair_allowed = 1; publicvariable "repair_allowed";
			_x switchMove "AinvPknlMstpSnonWrflDnon_medic3"; // change this to whatever animation you whant i think it gives the script some life so the player can c something is happaning
			sleep 10;
			[player,nil,rsideChat,"you have replenished your mechanical repair skill!"] call RE;

	};

};	

};


if ( repair_allowed == 1 ) then
{

if ! isdedicated then                                   
{

if (count _this > 1) then {
(_this select 1) playMove "ActsPercSnonWnonDnon_carFixing2";
sleep 7;
(_this select 0) setDammage 0;
(_this select 0) setFuel 1;	 
};

if (!isNil ("vehicleRepairInitiated")) exitWith {};
_units = ['USMC_SoldierS_Engineer', 'US_Soldier_Engineer_EP1','BAF_Soldier_EN_W','BAF_Soldier_EN_DDPM','BAF_Soldier_EN_MTP','Soldier_Engineer_PMC','CDF_Soldier_Engineer'];
vehicleRepairInitiated = true;
waitUntil {sleep 1; alive player};

while {true} do {
{

	if (!(_x getVariable ["RepairsInitiated", false])) then {
		_id = _x addAction ["Repair Vehicle", "mechanic_replenish.sqf", [], 1, false, true, "", "(getDammage _target) < 1 AND (getDammage _target) > 0 AND (typeOf _this) == _unit AND (vehicle _this) == _this"];
		_x setVariable ["RepairsInitiated", true, false];
	};
} foreach vehicles;
sleep 5;

};

};

}

Edited by outlaw

Share this post


Link to post
Share on other sites

Thats an easy fix mate i got time to put it togeather correctly today and test it ill upload the working version today

---------- Post added at 07:14 ---------- Previous post was at 07:12 ----------

Got time today to fix it and test it ill upload today

Share this post


Link to post
Share on other sites

righto so good news i hve it working only get 1 repair then you must replenish the skill and you must be holding the wrench to use the skill ;)

ill upload it in an hour when i get home

Share this post


Link to post
Share on other sites
righto so good news i hve it working only get 1 repair then you must replenish the skill and you must be holding the wrench to use the skill ;)

ill upload it in an hour when i get home

Ah.. Thank you ,

well right now , i'm trying to tweak your old code but still got the same error , so i'm gonna wait for your new code then :)

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
Sign in to follow this  

×