OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Dash5 on 12 Aug 2007, 21:59:27

Title: AddAction to map objects
Post by: Dash5 on 12 Aug 2007, 21:59:27
A search turned up nothin', so maybe I'm wording this wrong... :confused:

Is it possible to use addAction on map objects (fences, houses, buildings, etc.)?

Assuming it is...I'm trying to make a function that allows the player to destroy a fence. What am I doing wrong?

from init.sqs:
Code: [Select]
ActFence = ((getPos player) nearestObject 262162) addAction ["Break Fence", "BreakFence.sqf"];
from BreakFence.sqf:
Code: [Select]
_object = _this select 0;
_id = _this select 2;
//remove the action
_object removeAction _id;
//destroy fence
_object = (getPos player) nearestObject 262162;
if (!isNull _object) then _object setDamage 1;
Title: Re: AddAction to map objects
Post by: johnnyboy on 12 Aug 2007, 22:37:13
That looks clean to me.  Maybe it only works on editor placed objects.  If that is the case, you could place a hidden H object on the fence, and add the action to that instead.  Worth a try anyway...

This "break fence" idea is a good one, by the way.   
Title: Re: AddAction to map objects
Post by: JasonO on 13 Aug 2007, 02:50:43
It's been discussed before that things like vegetation and fences arn't actually objects, they are only island objects. They can't be selected even with nearestobject etc. Therefore you would have no way of defining what you want the action on in a script.
Title: Re: AddAction to map objects
Post by: Mandoble on 13 Aug 2007, 03:15:09
You may try also adding the action to a gamelogic placed near the desired object.
Title: Re: AddAction to map objects
Post by: JasonO on 13 Aug 2007, 03:43:53
But you still won't be able to actually destroy the fence?
Title: Re: AddAction to map objects
Post by: johnnyboy on 13 Aug 2007, 06:43:45
If they have object ids you may be able to destroy them.  I have successfully destroyed hand rail objects that line the streets of Bagango. 
Title: Re: AddAction to map objects
Post by: Dash5 on 13 Aug 2007, 06:54:47
Yes, fences are destroyable...just gotta figure out how to link it to addAction.

Does anyone know how this was done in Evolution? For example, certain buildings have actions like 'Recruit Soldier'.
Title: Re: AddAction to map objects
Post by: Nixer6 on 13 Aug 2007, 15:08:09
It's gotta be a trigger for Evo, as it's touchy as to where you are at the entrance to the recruitment building. Can't find my decoded mission.sqm for it ATM, so I am not sure though.
Title: Re: AddAction to map objects
Post by: johnnyboy on 13 Aug 2007, 16:33:42
Here's another option:  Collect the fence object ids you need into an array.  Then set up a script that loops through the array and tests the distance of the player to the object.   When player is close enough, add the action to the player, and register the near object id in a global variable (so the destroy action knows which object to destroy).  When player moves away (or fence section destroyed), remove action from player, and remove object id from global variable.  Be sure to sleep in the loop so it doesn't use up too much cpu.

If you want many different possible fence breakpoints, this approach may be cleaner, as your Destroy script is simple:  It destroys the object whose object ID is in the global variable.

If you have to place hidden objects or game logics for each fence break point, your destroy script becomes more complex, as it must be able to know which object id corresponds to which placed object/logic.
Title: Re: AddAction to map objects
Post by: LeeHunt on 13 Aug 2007, 17:14:22
Along the lines of Johnnyboy's comment, see this post with Mr. Peanut's advice as well:

http://www.ofpec.com/forum/index.php?topic=29632.0
Title: Re: AddAction to map objects
Post by: Dash5 on 14 Aug 2007, 04:05:49
hm...any way to extract the numerical object ID from the string returned from nearestObject?