Jump to content
Sign in to follow this  
Fuzzy Bandit

player removeAction not working...

Recommended Posts

Hello!

Well here's the low-down. I've got a variety of scripts all bouncing off of each other, and one particular script manages whether or not to add an action to the player.

Disregarding other parameters, if the unit gets within 5m of a certain object, add an action. If he then moves furthur than 5m from that object, the object disappears. Problem is, the action isn't removed!

Here's the code:

//Setting local variable to player
_unit = player;

//West capture Flag1 Action
if ((playerSide == WEST) AND (_unit distance flag1 < 5) AND ((tflag1 == "Neutral") OR (tflag1 == "PLA"))) then {
_captureit = _unit addAction ["Capture CP1","flags\flag1\us.sqf"];
} else {
_unit removeAction _captureit;
};

Any ideas as to why it wouldn't be removing the action?

Share this post


Link to post
Share on other sites

Is that inside a while loop or something similar?

If that's all the code in the script and the script is run multiple times. The action ID is not saved/transfered as it's assigned to a local variable.

Share this post


Link to post
Share on other sites

I actually prefer adding the action to the object in question and use the condition string in the addAction array to add the condition whether or not to show the action. That way you don't have to worry about removing it and if the condition ever reverses itself the action will appear again. Example:


// Add the action to flag1, no arguments to pass, priority of 10, showWindow true, hideOnUse true, no shortcut, and the condition string as shown.

_captureit = flag1 addAction ["Capture CP1","flags\flag1\us.sqf", "", 10, true, true, "", "(playerSide == WEST) AND (_unit distance flag1 < 5) AND ((tflag1 == ""Neutral"") OR (tflag1 == ""PLA""))"];

Share this post


Link to post
Share on other sites

The only issue is that us.sqf also does things that need the player to be doing the activating, for example showing their name in chat when they capture the flag.

Could that also be achieved by adding something along the lines of:

_caller = _this select 1;
[west,"HQ"] sideChat format ["%1 captured CP1 for US Forces!", name _caller];

as opposed to the old:

[west,"HQ"] sideChat format ["%1 captured CP1 for US Forces!", name player];

The issue with adding the action to the flag is that the script posted in my first post is called decide.sqf which is activated when player gets within 5m of one of three flagpoles. decide.sqf then contains a total of 6 IF statements which ask the current predicament of the flag and the player, and assigns an action accordingly. Would assigning the action to flag still work?

I would do all this testing stuff myself, but won't have access to ARMA for most of the day, so I can't really test anything myself! :D

Share this post


Link to post
Share on other sites

Maybe something like this could work

_unit = player;

//West capture Flag1 Action
_captureit = -1;

while {(playerSide == WEST) AND (_unit distance flag1 < 5) AND ((tflag1 == "Neutral") OR (tflag1 == "PLA"))} do 
{
if  (_captureit == -1)  then {
_captureit = _unit addAction ["Capture CP1","flags\flag1\us.sqf"];
};
sleep 0.1;
};
_unit removeAction _captureit;

How are you calling the script?

I'm using a repeated trigger when player is within 5 meters but why not just put it all in a trigger to start with.

cond

((playerSide == WEST) AND (player unit distance flag1 < 5) AND ((tflag1 == "Neutral") OR (tflag1 == "PLA")))

on act

captureit = player addAction ["Capture CP1","flags\flag1\us.sqf"];

on dea

player removeAction captureit;

Share this post


Link to post
Share on other sites

Well there are 3 flags and 2 possible sides capturing each, so creating triggers would be annoying and silly.

Is there literally no way to do this apart from creating triggers or defining new global variables?

Share this post


Link to post
Share on other sites

Ok Loyalguard! Finally got a chance to test out some of these scripts and yours works a charm!

Just slapped all the actions in the init.sqf and had it done with! Cheers!

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  

×