Jump to content
Sign in to follow this  
luckyhendrix

addaction condition question

Recommended Posts

Hi, i'm trying to make a simple script to move mortar with a truck.

I want to add an action to the mortar when the truck is near it so it pu this in my script :

_id = _mortar addaction ["Mount Mortar","Tow.sqf",[_truck],10,true,true,"(_truck distance _mortar)<7"];

But it doesn't work the action always shows up.

Share this post


Link to post
Share on other sites

_truck and _mortar are local variables, while the addaction will be on a global scale when it's run. Either hard code it with names of the truck and mortar or use format to replace those variables with their values.

Share this post


Link to post
Share on other sites

It'll be a very little more tricky than that.

Like Dr Eyeball said, what you can access inside the condition script of the action is the unit to which the action is attached (in your case, the mortar) and the unit which could activate the action (in your case, useless, that's not an information you need).

So, from within the "" of the action condition check, you can only access the mortar object by using for example

_mortar = _target

In the same vein, in the argument field of your addAction arguments, you can't use "_truck" as it is a local variable which is undefined here. You will be able to access the truck through

_truck = _this select 0

from within your Tow.sqf script.

To be able to access the truck in the condition script, as kylania pointed out, would require a global variable (ie a variable that exists outside of the condition script defined between "") which does not begin with _ caracter and could be for example defined in the init line of your truck unit

myTruck = this

Which would make the code looks like this :

_id = _mortar addaction ["Mount Mortar","Tow.sqf",[],10,true,true,"(myTruck distance (_target))<7"];

If you have 1 truck, statically defined, that will do it easy.

Things can go more complicated if you have multiple trucks, or if they are for example generated on the fly (for example coming from a Warfare Vehicle Factory), there's no global variable assigned to it.

In which case, I'd suggest detecting the nearest vehicle of type "truck" that you need to test.

You'd need to retrieve the class name of the truck (you have a class names list here : http://forums.bistudio.com/showthread.php?t=73241 ), and use nearestObject to detect the nearest truck of this type.

For example, let's say the truck type you want is the normal US transport truck, its class name is "MTVR".

The code would be :

_id = _mortar addaction ["Mount Mortar","Tow.sqf",[],10,true,true,"((nearestObject [_target, 'MTVR']) distance (_target))<7"];

The condition check here basically means "true if the nearest object of the action's target (the mortar), of type "MTVR", is closer than 7m from the action's target"

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  

×