Jump to content
Sign in to follow this  
drunkenjawa

Trying to get simple repair script going

Recommended Posts

So basically all I'm trying to do is write my own repair script which fires as soon as the vehicle is damaged. Pretty simple to most of you I guess hehe, I know there are a lot of scripts out there but I prefer to try and write them myself to get a better understanding of what is happening. I can use a trigger to get this going, but would prefer to use a script instead so I can then apply it to any vehicle that happens to be spawned as well, which doesn't have a specific name attached to it.

so far I have the script being executed by a vehicle like this:

null = [this] execVM "damagecheck.sqf";

in the vehicles init line in the editor. Then I've made damagecheck.sqf:

_broken = _this select 0; 

if (damage _broken > 0) then
{
	hint "unit broken";
	_broken addAction ["<t color='#0BD05A'>Repair Vehicle - must be out of car!</t>", "repairvehicle.sqf"];
} else {
		"";
	};

But it never fires. I'm guessing because, this is due to the whole script just checking once, right at the beginning, then that's it, doesn't check again?

If that's the case, how would I get this to run all the time and constantly check to see if the vehicle is damaged, and would that cause some strain in the background with it constantly checking all the time? It's for a Single Player mission.

While I'm here I will also ask about applying this to a vehicle spawn, since I can't get the action to appear in the first place I can't actually check if it's applying or not lol, but think it seems fine:

_cost=500;
if  (cash >= _cost) then
	{
		cash=cash-_cost;
		hint format ["-$ %1",_cost];
		_vehicle = createVehicle ["B_Heli_Light_01_F", (getMarkerPos "vehiclespawn1"), [], 0, "CAN_COLLIDE"];
		_vehicle setObjectTexture [0,"white.jpg"];
		_vehicle setVehicleInit "null = [this] execVM 'damagecheck.sqf'";
		processInitCommands;
		player say "ching";
		[str ("AH-9 Hummingbird")] spawn BIS_fnc_infoText;
	} else	{
			hint "Not enough cash."
		};

Basically I know that the whole script works, the new part though is:

_vehicle setVehicleInit "this execVM 'damagecheck.sqf'";
	processInitCommands;

Would that end up applying it to the spawn ok?

Share this post


Link to post
Share on other sites

You might just want to add an action to the vehicle with a simple condition that only shows the action when the vehicle is damaged. Like so...

null = this addAction ["Repair Vehicle","repairVehicle.sqf",[],1,true,true,"","damage this > 0"];

Share this post


Link to post
Share on other sites

Thanks for that Horner - still not working for me at the moment though, would that condition at the end need to be in brackets or something?

I've tried "(damage this) >0" and "((damage this) >0)" as well as your suggestion however it still doesn't seem to be firing.

EDIT: The annoying thing is that if I create a trigger that says in the condition: damage car1 > 0 and name the vehicle car1, it works all the time. But since I'll be spawning vehicles, I want to add it to each individual vehicle that spawns too, and make it easy to move over from mission to mission.

Edited by drunkenjawa

Share this post


Link to post
Share on other sites

How are you adding that line? Through the init line of the vehicle or through a script?

Share this post


Link to post
Share on other sites

in the init line, through the editor - will be adding via that other script later on once I can get this going.

EDIT: So to clarify I'm using:

null = this addAction ["Repair Vehicle","repairVehicle.sqf",[],1,true,true,"","damage this > 0"];  

In the init line of the truck that I've put down in the editor.

Edited by drunkenjawa

Share this post


Link to post
Share on other sites

Okay so basically it was the 'this' in that condition, should have been '_this' - all working now, thanks for your help Horner!

null = this addAction ["Repair Vehicle","repairVehicle.sqf",[],1,true,true,"","((damage _this) > 0)"];

And that's working :D Not sure if the brackets or needed or not.

---------- Post added at 07:24 ---------- Previous post was at 06:46 ----------

Now with the spawned in vehicle, I have this code:

_cost=500;
if  (cash >= _cost) then
	{
		cash=cash-_cost;
		hint format ["-$ %1",_cost];
		_vehicle = createVehicle ["C_Offroad_01_F", (getMarkerPos "vehiclespawn1"), [], 0, "CAN_COLLIDE"];
		_vehicle setObjectTexture [0,"black.jpg"];
                      //hint "now to set vehicle init";
		//sleep 1;
		_vehicle setVehicleInit "this addAction "Repair Vehicle","repairVehicle.sqf","",1,true,true,"","((damage _this) > 0)"];"; 
		processInitCommands;
		sleep 1;
		hint "vehicle init set";
		player say "ching";
		[str ("Offroad Purchased")] spawn BIS_fnc_infoText;
	} else	{
				hint "Not enough cash."
			};

However it gives me a script error saying that there is an issue with line 10 (where I use the setVehicleInit) saying I'm missing an ; and doesn't finish running the script.

Commenting out the setVehicleInit and processInitCommands lines makes the script run ok again. One thing that I noticed is that my SQF syntax highlighting thing for notepad++, does not light up 'setVehicleInit' in blue like it does with say, 'setOjectTexture'. But setVehicleInit seems to be the right command to use. Any ideas? I've tried adding ;'s, removing ;'s, doesn't seem to make much difference so I think that the issue is with how I'm running the addaction command in the first place.

Edited by drunkenjawa

Share this post


Link to post
Share on other sites
Okay so basically it was the 'this' in that condition, should have been '_this' - all working now, thanks for your help Horner!

null = this addAction ["Repair Vehicle","repairVehicle.sqf",[],1,true,true,"","((damage _this) > 0)"];

And that's working :D Not sure if the brackets or needed or not.

---------- Post added at 07:24 ---------- Previous post was at 06:46 ----------

Now with the spawned in vehicle, I have this code:

_cost=500;
if  (cash >= _cost) then
	{
		cash=cash-_cost;
		hint format ["-$ %1",_cost];
		_vehicle = createVehicle ["C_Offroad_01_F", (getMarkerPos "vehiclespawn1"), [], 0, "CAN_COLLIDE"];
		_vehicle setObjectTexture [0,"black.jpg"];
                      //hint "now to set vehicle init";
		//sleep 1;
		_vehicle setVehicleInit "this addAction "Repair Vehicle","repairVehicle.sqf","",1,true,true,"","((damage _this) > 0)"];"; 
		processInitCommands;
		sleep 1;
		hint "vehicle init set";
		player say "ching";
		[str ("Offroad Purchased")] spawn BIS_fnc_infoText;
	} else	{
				hint "Not enough cash."
			};

However it gives me a script error saying that there is an issue with line 10 (where I use the setVehicleInit) saying I'm missing an ; and doesn't finish running the script.

Commenting out the setVehicleInit and processInitCommands lines makes the script run ok again. One thing that I noticed is that my SQF syntax highlighting thing for notepad++, does not light up 'setVehicleInit' in blue like it does with say, 'setOjectTexture'. But setVehicleInit seems to be the right command to use. Any ideas? I've tried adding ;'s, removing ;'s, doesn't seem to make much difference so I think that the issue is with how I'm running the addaction command in the first place.

Well you have on line 10 ]; the square bracket isn't closing anything.

Share this post


Link to post
Share on other sites

Thanks, I actually noticed that and removed it, still got the same error, then I read something about when the command is inside a string, it should read more like

_vehicle setVehicleInit "this addAction 'Repair Vehicle','repairVehicle.sqf','',1,true,true,'','((damage _this) > 0)';";

I've tried without the second to last ; and it still gives the error. Tried adding one on the end, same error. The error being, that there is a missing ;

Share this post


Link to post
Share on other sites

setVehicleInit I thought was removed.

--

anyway I made this script a long time ago and it can be changed, it basically acts like the standard repair in arma but you can set the value.

and yea you need a toolkit in your inventory and also as a bug it will double up if your an engineer/repair specialist

repair.sqf

Edited by Lala14

Share this post


Link to post
Share on other sites

Yeah I found last night just before I went to bed, that BIS have removed the setVehicleInit from Arma 3 and from what I gather, trying to use some BIS_fnc_MP call or something instead, to add scripts to spawning vehicles. Thanks alot for that script lala, works perfectly and I will just use that I think. It does everything that I need it to do and is 100 times better than what I could have written at the moment anyway hehe.

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  

×