Jump to content
Sign in to follow this  
Fuzzy Bandit

Making Actions Private

Recommended Posts

Is there any way to make actions private?

For example, I've got an action assigned to my unit using their init line. The code:

this addAction [("<t color=""#8A8A8A"">" + ("Check Score") + "</t>"),"flagcheck.sqf"];

Now that's all fine and dandy, but if I were to die, respawn and look at my corpse... Voila! I have two 'Check Score' actions. This same thing happens if teammates have an action - looking at them gives you the ability to use the action as well.

So like I said, is there any way to make an action completely private, so that nobody looking at you receives that action?

Cheers!

Share this post


Link to post
Share on other sites
Is there any way to make actions private?

execute 'addaction' only those clients that shall see/use the action:

[noparse]
if(local this) then {
   this addAction [("<t color=""#8A8A8A"">" + ("Check Score") + "</t>"),"flagcheck.sqf"];
};
[/noparse]

..., but if I were to die, respawn and look at my corpse... Voila! I have two 'Check Score' actions.

Remove the added action once your player unit dies. The code below assumes that the id of the automaticly added action (on every respawn) is and stays the same, as the manually added one at the beginning. If that's not the case you could do something like this in the killed-eh code instead:

for [{_x=1},{_x<=10},{_x=_x+1}] do { (_this select 0) removeAction _x; };

[noparse]
if(local this) then {
   checkScoreActionId = this addAction [("<t color=""#8A8A8A"">" + ("Check Score") + "</t>"),"flagcheck.sqf"];
   this addEventHandler["killed", "(_this select 0) removeAction checkScoreActionId;"];
};
[/noparse]

Share this post


Link to post
Share on other sites

Looks good to me! Will test ASAP.

I currently have a 'respawn script' running on the event of my player being killed. Something along the lines of:

Unit's Init Line

_xhandle = _this addEventHandler ["killed", "_this execVM 'checkspawn.sqf'"];
this addAction [("<t color=""#8A8A8A"">" + ("Check Score") + "</t>"),"flagcheck.sqf"];

checkspawn.sqf

(Something like this - don't have access to ARMA atm. Could it be changed to something along these lines to incorporate removing the action on death?)

_unit = this select 0;
for [{_x=1},{_x<=10},{_x=_x+1}] do { _unit removeAction _x; };

{waitUntil alive player}

if(local this) then {
   this addAction [("<t color=""#8A8A8A"">" + ("Check Score") + "</t>"),"flagcheck.sqf"];
};

Share this post


Link to post
Share on other sites

An alternative would be to use the optional condition part of the addAction command, for example this would go in a units init field:

_actionId = this addAction [("<t color=""#8A8A8A"">" + ("Check Score") + "</t>"), "flagcheck.sqf", [], 0, 
 false, true, "", "local this"];

At least I think that would work when your alive, also that checkspawn.sqf doesnt look right I think this should work:

_unit = _this select 0;
for [{_i=0},{_i<=10},{_i=_i+1}] do { _unit removeAction _i; };

waitUntil{alive _unit};

if(local _unit) then {
   _unit addAction [("<t color=""#8A8A8A"">" + ("Check Score") + "</t>"),"flagcheck.sqf"];
};

Edited by Andy455

Share this post


Link to post
Share on other sites

Ah cool.

I've got a working version of checkspawn.sqf on my ARMA computer that currently just adds the action. I'll try changing the addAction to the "local this" version, as well as adding the removeAction part to the beginning.

Thanks for all the help!

Ooh, and I'm not too hot on what 'for' does. I'm pretty sure it's some sort of loop, but not totally sure of the syntax and how that piece of code is working. Could anyone fill me in on what's actually happening in that part of the code? I hate adding things to my missions when I have no idea what they do! :D

Share this post


Link to post
Share on other sites

Ok fabulous and thank you! Don't know why I didn't check out the wiki in the first place!

As an interrogative, that will remove all actions from 0 to 9, correct? Does that mean that if I die 10+ times, the action will be assigned an ID of 10 and therefore not get removed? If so... that's a bugger. I'd add more to the '<=' number, but I assume that would just increase server load at times of mass death! :D

Share this post


Link to post
Share on other sites

Ok apologies but bumping.

Now tested both methods (IF statement and addAction condition), and neither even gave my character an action. Can't think why this would be, as the 'local' command would seem the place to go...

Share this post


Link to post
Share on other sites

Try switching the condition from

local this

to

local _target

in

_actionId = this addAction [("<t color=""#8A8A8A"">" + ("Check Score") + "</t>"), "flagcheck.sqf",[],0,false,true,"", "local _target"];

Or, you might try

_target == player

Share this post


Link to post
Share on other sites

Okey dokey! I'll give that a go when I can get on ARMA, and bump this thread with the results

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  

×