Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
Toasted Duckie

Addaction for one player

Recommended Posts

Hey guys, I'm always finding myself struggling with actions, but usually I can manage..

This time however, I can't seem to find a solution.

Very simple actually, but can't figure it out.

Question: how to add an action for just one player? player is variable.:confused:

:rolleyes:

Much love

Share this post


Link to post
Share on other sites

Name the player in the editor i.e. "P1",

then in your script

P1 addaction .....................

Share this post


Link to post
Share on other sites

if you want an object to hold an action that only one player can activate, you can also use the "condition" parameter (check commands wiki) and use it to check if the player is who you need it to be, if not, the action doesn´t show

cheerz

Share this post


Link to post
Share on other sites

and that's what I don't want to do. When the player is in an area I want him to have an action.

Also, would P1 addaction.... not just give the object (in this case unit) P1 the action, so everyone close enough to P1 has the action?

---------- Post added at 03:00 AM ---------- Previous post was at 02:56 AM ----------

I see Moach_Mayhem, would that look like this?

_increasetargets = _player addAction [format ["Increase targets. %1",_tar],"targetsettings.sqf",  "",1, false, false, "", (_target == player)];

Above code is wrong, must be filling in some parameters faulty ... :( Can someone help this poor man out? :D

Edited by Toasted Duckie

Share this post


Link to post
Share on other sites

Well, you have an area trigger right? If it doesn't have a name yet, name it.

So, change that (_target == player) to:

"player in list myTriggerName"

Share this post


Link to post
Share on other sites

Thanks, but

_increasetargets = _player addAction [format ["Increase targets. %1",_tar],"targetsettings.sqf",  "",1, false, false, "", (_player in list _trigger)];

doesn't work.

Other players still have the action when looking at the person in the trigger area.

Same goes for this:

_increasetargets = _player addAction [format ["Increase targets. %1",_tar],"targetsettings.sqf",  "",1, false, false, "", (player distance _player <1)];

Share this post


Link to post
Share on other sites

Well, if you bother reading the wiki, it clearly tells you the condition is a string. That's why I said:

"player in list myTriggerName"

and not

player in list myTriggerName

Share this post


Link to post
Share on other sites

You want the action assigned locally on the player, not globally. Then the editor, or more specifically, a trigger, is a very bad idea to do so.

Name the player, let's say, P1.

Then write into a script, e.g. the Init.sqf file:

if(player == P1) then{
      _increasetargets = player addAction ["Increase targets.","targetsettings.sqf",  "",1, false, false, "", ""];
};

EDIT:

That's it for your intial concern / what your initial post was about. For restricting the action to be in a certain area, the very last post of shk should finally give you all information you need: Name the trigger that describes the area, and edit the addAction statement to the following:

if(player == P1) then{
      _increasetargets = player addAction ["Increase targets.","targetsettings.sqf",  "",1, false, false, "", "player in list <triggername>"];
};

Edited by Bon

Share this post


Link to post
Share on other sites

So this way the action is completely hidden from other players?

I thought actions always show up if another player is close enough to the unit that has it......

Share this post


Link to post
Share on other sites

I thought actions always show up if another player is close enough to the unit that has it......

No. It is just a thing of locality. An action assigned from within a script that runs locally on certain machines can't be shown on other machines, as it doesn't exist for 'em.

Edited by Bon

Share this post


Link to post
Share on other sites

Thanks for the help Bon, the thing is, it's variable which player gets the action. When player x is in trigger area, ONLY player x gets the actions. When player y steps in that trigger area, only player y gets the commands

Share this post


Link to post
Share on other sites

Name the trigger, and write this into your init.sqf:

_increasetargets = player addAction ["Increase targets.","targetsettings.sqf",  "",1, false, false, "", "player in list <triggername>"];

This way every player will have the action enabled once s/he enters the trigger area and looses it when leaving the area. The action assigned to the player won't be shown on other machines.

You want the action assigned only once a time? So if it is already assigned to player x it can't be assigned to player y even if player y enters the area?

Share this post


Link to post
Share on other sites

That is exactly what I want bon! Right now I have a trigger, and if bluefor enters the are it fires a script. In that script _player is assigned to the first element of the array that contains the players in the trigger area.

_player = _this select 0

in the script that is fired by the trigger. So yes, I only want one person per time to have the action.

But wait, I'm getting crazier:p

I have

_var = player addAction [format ["Some text %1", _avariable],"script.sqs",etc]

And want to change that _avariable quite often, actually every time the player executes the action. So I figured I would want to add the actions in a script, and when triggered remove and re-add those actions, thus seeing a change in the _avariable. That can't be accomplished from the init file, can it?

:rolleyes:

Share this post


Link to post
Share on other sites

Also, while on the subject off addactions, is it possible to call a function from the addaction code, instead of just executing a script? So have values return to the script that adds the action?

Share this post


Link to post
Share on other sites

No... I tried it too... apparently the addaction function can only call scripts... it won't call functions or run a single commandline

I think that's how the addAction function is wired... which is too bad because it would be very handy in situations when all you need is a single line to be executed

Cheers

Share this post


Link to post
Share on other sites
Sign in to follow this  

×