Jump to content
Sign in to follow this  
VonNexus

Some questions about addAction and removeAction

Recommended Posts

Hi,

I'm pretty new to scripting and editing but in the last months I learned a lot about triggers, waypoint, synch and so on. What I'm not able to figure out is the addAction script. In my mission, I want to add an action in the action menù when my player is near a soldier. When the action is activated, it disappears from the menu and a dialog is displayed. But I don't know how to do that. I know that I should make a .sqf file with something in that, but what? I searched in the forum and found something, but I don't understand ( there are things like IDs, callers and so on) so I'd like a little explanation.

Thanks.

Share this post


Link to post
Share on other sites

Soldier's init:

talking = this addAction ["Talk to soldier","talk2soldier.sqf"];

talk2soldier.sqf:

_soldier = _this select 0;  // Object who had the addAction
_caller = _this select 1;  // Object who used the addAction
_actionID = _this select 2;  // ID of the addAction

// Remove the action
_soldier removeAction _actionID;

_soldier sideChat "You clicked on my action!";
sleep 2;
_caller sideChat "Indeed I did my friend, indeed I did!";

Share this post


Link to post
Share on other sites
Soldier's init:

talking = this addAction ["Talk to soldier","talk2soldier.sqf"];

talk2soldier.sqf:

_soldier = _this select 0;  // Object who had the addAction
_caller = _this select 1;  // Object who used the addAction
_actionID = _this select 2;  // ID of the addAction

// Remove the action
_soldier removeAction _actionID;

_soldier sideChat "You clicked on my action!";
sleep 2;
_caller sideChat "Indeed I did my friend, indeed I did!";

OK. But what do you actually mean with Object who had the addAction and Object who used the addAction? Is that an explanation for soldier and caller or I must write there the soldier who has the action and the one who he's talking with?

Share this post


Link to post
Share on other sites

The object who "has" the addAction is the object to which the action is attached, i.e., the object to which you applied the "addAction" scripting command. The object who used the addAction is the unit that went up to the object and actually selected the action from the action menu. Note that these two can be the same, e.g., if you add an action to the player and he activates it.

Share this post


Link to post
Share on other sites

An object is a "thing", a soldier, a tank, a wall something that exists. I list it as an object in the comments (everything after a // is just a comment. It explains what that line is doing) as an object so you know the "data type" it is. Sometimes you'll have something be a string or a number (like the _actionID is) and it helps to keep track of the type of data something is.

When you use an action it sends some information to the script it calls. The first thing it sends is the object that had the action - in this case the soldier you clicked on. The script knows this as _this select 0. So we'll assign it to the local variable of _soldier so we can use it in the script. We could have called it _guyWhoHadTheAction if we wanted to, but _soldier is easier to read. :)

The second thing it sends us is the object of whoever triggered the action. The script knows this as _this select 1. In the script I assign that value to _caller to sound all official and stuff. We could have called it _dudeWhoClicked if we wanted to.

The third thing, the ID number of the action, is known as _this select 2. We call it _actionID in the script.

So we have little "nicknames" for the soldier that had the action and the soldier that called the action but we never need to refer to the specific unit. This lets us use the same script for multiple soldiers if we wanted to or to be able to keep the script the same if we change who had it.

So the script sends us three pieces of information. The object that had the action, the object that used the action and the number of the action. We took that information, assigned them to friendly local variable names so we could use them within the script.

Make sense or is anything still confusing?

Share this post


Link to post
Share on other sites
An object is a "thing", a soldier, a tank, a wall something that exists. I list it as an object in the comments (everything after a // is just a comment. It explains what that line is doing) as an object so you know the "data type" it is. Sometimes you'll have something be a string or a number (like the _actionID is) and it helps to keep track of the type of data something is.

When you use an action it sends some information to the script it calls. The first thing it sends is the object that had the action - in this case the soldier you clicked on. The script knows this as _this select 0. So we'll assign it to the local variable of _soldier so we can use it in the script. We could have called it _guyWhoHadTheAction if we wanted to, but _soldier is easier to read. :)

The second thing it sends us is the object of whoever triggered the action. The script knows this as _this select 1. In the script I assign that value to _caller to sound all official and stuff. We could have called it _dudeWhoClicked if we wanted to.

The third thing, the ID number of the action, is known as _this select 2. We call it _actionID in the script.

So we have little "nicknames" for the soldier that had the action and the soldier that called the action but we never need to refer to the specific unit. This lets us use the same script for multiple soldiers if we wanted to or to be able to keep the script the same if we change who had it.

So the script sends us three pieces of information. The object that had the action, the object that used the action and the number of the action. We took that information, assigned them to friendly local variable names so we could use them within the script.

Make sense or is anything still confusing?

I'm understanding something but still get confused on ID. What do I write in there? A number?

Share this post


Link to post
Share on other sites

You don't write anything specific there, the script already knows it. The code I posted is exactly what you'd type.

If you wanted to make a script that did nothing but remove an action when you clicked on it you'd put this:

_soldier = _this select 0;  // Object who had the addAction
_actionID = _this select 2;  // ID of the addAction

// Remove the action
_soldier removeAction _actionID;

You don't need to know exactly what the number was, the script keeps track of that.

You could even write it this way:

_this select 0 removeAction _this select 2;

But that's a lot more confusing than assigning labels to those values. You won't have to actually type the number though.

Share this post


Link to post
Share on other sites
You don't write anything specific there, the script already knows it. The code I posted is exactly what you'd type.

If you wanted to make a script that did nothing but remove an action when you clicked on it you'd put this:

_soldier = _this select 0;  // Object who had the addAction
_actionID = _this select 2;  // ID of the addAction

// Remove the action
_soldier removeAction _actionID;

You don't need to know exactly what the number was, the script keeps track of that.

You could even write it this way:

_this select 0 removeAction _this select 2;

But that's a lot more confusing than assigning labels to those values. You won't have to actually type the number though.

Uh OK pal! Thanks for your help and your patience! You really helped me!

---------- Post added at 03:47 PM ---------- Previous post was at 03:25 PM ----------

Only one thing: I want to make the chat like when I'm talking directly with some one, not on the radio ( with all the letters in white). Can you help me on this one?

Share this post


Link to post
Share on other sites
This demo mission shows all sorts of ways of "talking" to the player.

Uhm, from what I can see, that explains how to put sound with the dialog. Also the subs are in another file. I think that I can put something in the talk2soldier.sqf, like you did. globalRadio maybe?

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  

×