Jump to content
Sign in to follow this  
Unkn0wn

Scripting Problem

Recommended Posts

Sup Guys,

I am new to scripting i wanted to make a repair script where a player repairs a vehicle but i ran into a problem. This is what i got so far i tried it in game it diden't work. i want it to where when the vehicle is damaged show "Repair MTVR" when selected executes another script which repairs the vehicle. Help would be greatly appreciated thanks.

if ((damage mtvr)>0.1) then 
{
mtvr addaction ["Repair MTVR", "Unkn0wnsRepair.sqf"]; 

I figured it out

if ((damage mtvr)>0.1) then 
{
mtvr addAction [("<t color=""#CCD3FF"">" + "Repair MTVR" + "</t>"), "Unkn0wnsRepair.sqf", "", 10, FALSE, FALSE, "", ""];
};

Edited by Unkn0wn

Share this post


Link to post
Share on other sites

Put this in vehicle int field.

if((damage this)>0.1) then {
this addAction [
	"Repair MTVR",
	"Unkn0wnsRepair.sqf",
	[],
	1,
	false,
	true,
	"",
	""
];
};

Put this in your mission folder.

name it Unkn0wnsRepair.sqf

_vehicle =_this select 0;
_actionID =_this select 2;
_spoter removeAction _actionID;

if(damage _vehicle > 0.95)then{
Hint "We can not repair this vehicle";
}else{
sleep 2;
_vehicle setdammage 0;
};
exit;

Share this post


Link to post
Share on other sites

If you want the repair option to appear only after the vehicle is damaged, you need an Event Handler. One way to go about this is to put this in the "init.sqf" file in the mission folder:

vehicleRepair = -1;
_ehDamagedIdx = v1 addEventHandler ["dammaged", {[_this] execVM "damaged.sqf"}];

vehicleRepair is a global variable. There are other ways, this is the simplest I think.

v1 is the name of your MTVR, change the name to suit your preferences. And yes dammaged has 2 m's.

Add a 'damaged.sqf' file with code like this:

if ((damage v1 > 0.1) && (vehicleRepair < 0)) then 
{ 
vehicleRepair = player addAction["Repair Vehicle","repair.sqf",nil,-1000,false,true];
};

Again, replace 'v1' to suit your preferences. Repair.sqf can be called whatever you want too of course. I used the vehicleRepair global var simply to prevent multiple addActions from appearing everytime the vehicle gets damaged :)

The repair script in the previous post will work fine. The only reason I put in this event handler is because if you put the addAction in the vehicle init line, then it will only work if the vehicle is damaged the moment it is created. Hope that helps!

- oh one other thing, the 'dammaged' event handler passes in 3 arguments. I left them out for simplicity, but you can see it here: http://community.bistudio.com/wiki/ArmA_2:_Event_Handlers#Dammaged

Edited by AZCoder
forgot one item

Share this post


Link to post
Share on other sites

Isn't it better to always add the action and use the condition expression field to determine when it is being showed?

I use something like this for something different:

player addAction ["Join Squad", "scripts\ActionJoin.sqf", [], -10, false, false, "", "(player distance (leader gShark) < 5) && (player in units gRevolver)"];

If we're talking about many actions, then I guess this method has a potential for slowing down (not tested), but I find action adding and removing quite messy to work with and have a high failure frequency (for me anyway).

Domination uses a third approach, by letting looping scripts or fsms determine when actions are added and removed.

I guess there are many ways :)

Share this post


Link to post
Share on other sites

I normally use the CBA version now:

 _actionIndex = [["Teleport", "teleport.sqf"]] call CBA_fnc_addPlayerAction;

That's from http://dev-heaven.net/docs/cba/files/common/fnc_addPlayerAction-sqf.html#CBA_fnc_addPlayerAction

I try to avoid actions altogether, except when test building a mission I run some scripts from the action menu, such as one to display my position and copy it to the clipboard. I would like to spend some time and learn the FSM, just never get around to it :D

Share this post


Link to post
Share on other sites
Isn't it better to always add the action and use the condition expression field to determine when it is being showed?

Personally I believe it is. Unfortunately, a lot of people aren't used to using conditions in addAction and instead use more complex OFP methods for adding/removing actions.

Maybe you could write up a small guide to using actions and try to get people in the habbit of using conditions instead of adding & removing.

Share this post


Link to post
Share on other sites

Hah. I didn't realize you could write it that way, still learning the nuances. I will play around with addAction when I have a bit of time. Thanks for the input.

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  

×