Jump to content
Sign in to follow this  
MrBob

Removing an action after activation

Recommended Posts

I'm trying to make a mission where one of the side objectives is to rescue some pilots. Here's what I have in the pilot's init field:

_rescue = this addAction ["Rescue","rescue.sqf",(this)];

and here's rescue.sqf:

_p = [_this select 0];
_id = [_this select 2];
_p join player;
_p removeaction _rescue;
hint "debug: rescued pilot";

The pilot will join my group but the action is never removed and the debug test never displays. What is the problem here?

Share this post


Link to post
Share on other sites

You can't use _rescue (a local variable) in the init field and have that accessible by the rescue.sqf script. Rename it to just "rescue" and use that in the removeAction line and I think it should work. :)

Share this post


Link to post
Share on other sites

I did that, and I still have the same problem.

Share this post


Link to post
Share on other sites

One trick you can do to remove all actions from a unit is the following. At the point where you want to remove actions, just add one and have it remove everything from that point back, like this:

// Remove all actions from the suspect
_action = unitObject addAction["foo", "foo.sqf"];
while {_action >= 0} do	{
unitObject removeAction _action;
_action = _action - 1;
};

That way you don't have to keep track of the action ID across space and time.

Share this post


Link to post
Share on other sites

Do I put the top line in the init field or is it part of the script?

Share this post


Link to post
Share on other sites

Maybe the problem is here:

_p = [_this select 0];

_id = [_this select 2];

_p join player;

_p removeaction _rescue;

hint "debug: rescued pilot";

Try this:

_p = _this select 0;
_id = _this select 2;
_p join player;
_p removeaction _rescue;
hint "debug: rescued pilot";

Share this post


Link to post
Share on other sites

Lads, why so complicated? addAction already delivers the ID to the script which is executed, MrBob already read it out:

_id = _this select 2;

btw, remove those square brackets, they're just wrong.

After that, this will work:

_p = _this select 0;
_id = _this select 2;
_p join player;
_p removeaction _id;

You really have to explain me why you set those square brackets. I'm really curious about.

Share this post


Link to post
Share on other sites

When I remove the brackets, none of it works. He doesn't join my squad, the action isn't removed, and the debug text doesn't work. I'm really confused here.

Share this post


Link to post
Share on other sites

Join(Silent) needs an array, that's why the brackets were there. A far more elegant solution would be:

_object = _this select 0;
_activator = _this select 1;
_id = _this select 2;

_object removeAction _id;

[_object] joinSilent _activator;

Share this post


Link to post
Share on other sites

Thanks, it works perfectly now.

Share this post


Link to post
Share on other sites

isn't the join command [_p] join player I suspect your not using -showScriptErrors placed in the target line of the games short cut.

Share this post


Link to post
Share on other sites
isn't the join command [_p] join player I suspect your not using -showScriptErrors placed in the target line of the games short cut.

Yup, that's it! Both why the join and removeAction weren't working!

_p = _this select 0;
_id = _this select 2;
[_p] joinSilent player;
_p removeaction _id;

That should work fine.

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  

×