Home   Help Search Login Register  

Author Topic: Using addaction for a generic unit type.  (Read 1358 times)

0 Members and 2 Guests are viewing this topic.

Baphomet

  • Guest
Using addaction for a generic unit type.
« on: 17 Oct 2002, 20:36:08 »
I am moderately farmiliar with the usage of "addaction" to allow one to call scripts from the action menu. However how does one create a general action script that will enable that action to be performed on a general type of unit or structure as opposed to one which is defined by a specific name.
(Ie: man addAction ["Hello", "hello.sqs"] )

Whereas "man" would be some infantry or civilian. He would provide an action that would call a script that said "Hello" in titletext.

However what If I wanted to make this action apply to not one unit, however any unit of that type that exists or has yet to exist (ie: spawned).

I was looking through the comref and I didn't really extrapolate anything that would be of use to my limited understanding as of yet.

This might have some fairly useful applications in multiplayer games if put to use in the right way. I was just wondering how its accomplished.
« Last Edit: 17 Oct 2002, 20:37:45 by Baphomet »

A5hley

  • Guest
Re:Using addaction for a generic unit type.
« Reply #1 on: 17 Oct 2002, 21:17:43 »
Well i come across this while messing with one of my missions and that is if u group the trigger that activates the add action menu, with the group leader and and instead of vehicle present use any group member, then in the activation instead of using "man" i used "player", then the add action is available for any player unit that goes in the trigger area.

One problem though is that i havnt tested it over lan yet so i dont know if it ONLY adds the action to that unit or EVERY unit when one person enters the trigger.

I dont know if thats what u want but i hope it helps.

Baphomet

  • Guest
Re:Using addaction for a generic unit type.
« Reply #2 on: 17 Oct 2002, 21:58:21 »
Perhaps I did a lousy job of explaining this.

Lets say you place an open tent or something, anything really, say you want it to have actions which call various scripts.

At this point you have to create a script which associates the object with the action, in this script you'd have something like this.

object addaction["Execute","your script.sqs"]

"object" being a specific name for the object that you want to have the action associated with.

Then you've got to declare in some way that you want this script to be up and running when the game starts. I believe you can just exec it from the init.sqs.

... now. What if you don't want just some building named "object" to be associated with this addaction script. Perhaps you want all buildings like it to run this script as well. Of course that would preclude changing something in the addaction declaration for example. It would no longer be

object addaction["Execute","your script.sqs"]

The name "object" obviously wouldn't apply anymore because you don't just want something named "object" to run it. This allows flexibility insofar as if you wanted to make a map where you create buildings of various types each with unique associated actions. Furthermore you don't want to just predefine these structures during the creation of the map, however create a script that automatically runs whenever one is near that type of building.

I'm pretty sure that area-of-effect triggers wouldn't be necessary in this case.


Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Using addaction for a generic unit type.
« Reply #3 on: 18 Oct 2002, 02:07:37 »
Dunno about automatically incorporating it into a specific unit, but to add it to all existing objects/units, use a line like this in your init.sqs:

"_x addaction [""Hello"",""Hello.sqs""]" foreach [ object1,object2,object3...etc]

Adding all the names of objects into the array there.
Then just add the action to any extra objects you create

Baphomet

  • Guest
Re:Using addaction for a generic unit type.
« Reply #4 on: 19 Oct 2002, 03:28:49 »
Hm. Well that would be handy too. Still, its still finite in the sense that you must define each structure that you want associated with these actions.

I was thinking more on the lines of some general non-specific script that simply applies what is written within it to anything of a general type, be it an infantryman, vehicle, structure, etc. That way there is no limitation in terms of having to create it first in the editor. It can then even be a unit type or structure that is created mid game.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Using addaction for a generic unit type.
« Reply #5 on: 19 Oct 2002, 07:24:00 »
Hm. Well that would be handy too. Still, its still finite in the sense that you must define each structure that you want associated with these actions.

Whether using the mission editor or createunit/vehicle you still have to define your unit if you want it to exist ;)

I gather you are after an 'automatic' way of attaching the action to a unit... I'm afraid I don't have the answer to that one :)

But it wouldn't be too hard to simply add an action to a unit when it was created (mid game units) or to paste the addaction line into it's init (or use the foreach line as in my first post).

The alternative is a trigger which cycles through all units in it and applies the action to a specific unit type... but unless you had upwards of 50 units to add teh action to that would be more trouble than it's worth

Life is never easy ;D

Offline KTottE

  • Former Staff
  • ****
Re:Using addaction for a generic unit type.
« Reply #6 on: 19 Oct 2002, 09:34:21 »
Hmm, couldn't there be a way of solving this with a work-around?

Isn't there some spell that will return unit type?
If so, that could be used to pass all Soldiers with MG:s for example, into an array, then turn that into a group, then use "_x addaction [""Hello"",""Hello.sqs""]" foreach Group/Array-name

Or am being daft again?
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"