Jump to content
vastiny

Trying to get simple action adding and remover via Trigger

Recommended Posts

I'm trying to create a simple trigger that executes an action adding script on activation by player1, and an action removing script upon deactivating.
It needs to be MP compatible and let me add as many players as I need, so I Google-fu'd around until I found the proper structure for a multiplayer compatible addAction using the BIS_fnc_MP thing.
 
 
So, I have a trigger (Anybody Present, is Repeatable), on Activation it runs the following code:
If (isPlayer player1) then { 
     player1 execVM "scripts\inTrigger.sqf"
};
 

inTrigger.sqf

If (isPlayer player1) then { 
     hint "Player1 inside Trigger";
     player1 allowdamage false;
     action_arsenal = player1 addAction ["Action Here",{["script.sqf","BIS_fnc_execVM",true,false] spawn BIS_fnc_MP;}];
};
 
 
And on Deactivation, the same but it calls a "scripts\notInTrigger.sqf" instead
 
notInTrigger.sqf
If (isPlayer player1) then { 
     hint "Player1 no longer in Trigger";
     player1 allowdamage true;
     player1 removeaction 0; - Alternatively I also tried "removeallactions player1;" which didn't work either
};
 
 
This method works for entering the trigger, but the action or any other actions I add onto it will NOT remove once I exit the trigger like intended..
And ontop of that, the trigger doesn't seem to ever re-trigger again even though it's set to Repeatable as I only get the first hint message once and never again
 
With my very limited scripting knowledge I tried to look up how to do a condition that was set to "true" when player1 is in the trigger, and "false" when player1 is out of it - but couldn't get anywhere with that.

Share this post


Link to post
Share on other sites

This will give everyone an action to run action.sqf only if they are in the area of a trigger named nameOfTrigger.

[
	player,
	["Action Name","action.sqf", [], 0, false, false, "", "_this inArea nameOfTrigger"]
] remoteExec ["addAction"];

What is script.sqf supposed to do?

Share this post


Link to post
Share on other sites

script.sqf is just an example I put there, normally I'm supposed to have several actions, one of which for example calls the arsenal through it's own sqf which I have set up, and actions that exec other scripts by pressing an action

 

I'm hoping it's possible to set up so I can add all the actions in the inTrigger.sqf, it gets messy and unstructured in the trigger on act lines

Share this post


Link to post
Share on other sites

This will give everyone an action to run action.sqf only if they are in the area of a trigger named nameOfTrigger.

[
	player,
	["Action Name","action.sqf", [], 0, false, false, "", "_this inArea nameOfTrigger"]
] remoteExec ["addAction"];

What is script.sqf supposed to do?

 

this will not work if executed on server because of player is not known on server and 0 is send to the clients.

read 4th note in wiki entry of remoteExec written by r3vo

 

 

EDIT:

correct way could look like this:

[[],
 {player addAction ["Action Name","action.sqf", [], 0, false, false, "", "_this inArea nameOfTrigger"];}
] remoteExec ["call"];
Edited by sarogahtyp
  • Like 1

Share this post


Link to post
Share on other sites

So I should be able to put that into a script file, and then execvm said script file from a trigger's activation? I thought the [ and ] brackets were only for putting in trigger and not external sqf files?

Share this post


Link to post
Share on other sites

u can put that in a script and call it from the on act field or u put it in the on act field directly.

the bad news r that idk how to delete the action with on deact field... but maybe kylania knows

Share this post


Link to post
Share on other sites

Could I perhaps just use this in the trigger act and deact since "BIS_fnc_MP" is documented to be local execution?

[[[],"scripts\addactions.sqf"],"BIS_fnc_execVM",false,true] call BIS_fnc_MP;

And in my "addactions.sqf" I would use

[[player, ["My Action Title","myAction.sqf"]],"addAction",true,true] call BIS_fnc_MP;

and for the trigger deact field, change "addAction" to "removeAllActions" approprietly for the "removeactions.sqf"?

 

 

Edit: Nevermind, this defo didn't work at all :P

Share this post


Link to post
Share on other sites

adduseractions.sqf

if(!isServer) exitWith {true};
[[],
 {player addAction ["Action Name","action.sqf", [], 0, false, false, "", "_this inArea nameOfTrigger"];}
] remoteExec ["call"];

deleteuseractions.sqf

if(!isServer) exitWith {true};
[[],
 {removeAllActions player;}
] remoteExec ["call"];

execute that files from on act and on deact fields.

dont use BIS_fnc_MP because of this:

 

 

60px-Arma_3_logo_black.png This function is now provided for backward compatibility only. Please use the engine based commands remoteExec or remoteExecCall instead.

 

Share this post


Link to post
Share on other sites

Ok, I managed to solve it with the help of another script that accomplishes another part of what I also wanted in the end. I found a No Kill Zone script that I modified to add the commands

Couldn't get my head around how different local and server execution seems to be, and with the whole deal with needing MP compatibility

 

Kinda pissy that not even a simple trigger will accept removeAction or removeAllActions

Share this post


Link to post
Share on other sites

Couldn't get my head around how different local and server execution seems to be, and with the whole deal with needing MP compatibility

Once you get your head around locality, using addActions won't seem so pissy. In fact, lots of capability will make much more sense and become so much easier to implement.

Share this post


Link to post
Share on other sites

If you were to use removeAction, I believe you would do it like this:

 

InTrigger.sqf

if (isPlayer player1) then {
    Player1_InTriggerAction = player1 addAction ["blalalaa"];
};

LeaveTrigger.sqf

if (isPlayer player1) then {
    player1 removeAction Player1_InTriggerAction;
};

Do you want the action to be given to the individual player when they enter the area, or do you want the action to be given to everyone if one person enters the area?

Share this post


Link to post
Share on other sites

If you were to use removeAction, I believe you would do it like this:

 

InTrigger.sqf

if (isPlayer player1) then {
    Player1_InTriggerAction = player1 addAction ["blalalaa"];
};

LeaveTrigger.sqf

if (isPlayer player1) then {
    player1 removeAction Player1_InTriggerAction;
};

Do you want the action to be given to the individual player when they enter the area, or do you want the action to be given to everyone if one person enters the area?

 

The action will be given to each player locally, your examples were one of the first things I tried before my Google journey and before I came on here :P

Already solved it though using another script

 

 

Once you get your head around locality, using addActions won't seem so pissy. In fact, lots of capability will make much more sense and become so much easier to implement.

I'm finding it really hard to learn Arma 3 scripting, I've learned a little over the years by deconstructing other peoples scripts, but I'm definitely going to need more than just already-made-scripts to learn anything new, but my head hurts whenever I look at more advanced scripting guides.

I'm really not proud to say that I'm just another guy who downloads all pre-made scripts from Armaholic and modifies really basic stuff in them :P

  • Like 2

Share this post


Link to post
Share on other sites

The action will be given to each player locally, your examples were one of the first things I tried before my Google journey and before I came on here :P

Already solved it though using another script

 

 

I'm finding it really hard to learn Arma 3 scripting, I've learned a little over the years by deconstructing other peoples scripts, but I'm definitely going to need more than just already-made-scripts to learn anything new, but my head hurts whenever I look at more advanced scripting guides.

I'm really not proud to say that I'm just another guy who downloads all pre-made scripts from Armaholic and modifies really basic stuff in them :P

Ah, I was going of your initial examples

 

InTrigger.sqf

If (isPlayer player1) then { 
hint "Player1 inside Trigger";
player1 allowdamage false;
action_arsenal = player1 addAction ["Action Here",{["script.sqf","BIS_fnc_execVM",true,false] spawn BIS_fnc_MP;}];
};

and

 

LeaveTrigger.sqf

If (isPlayer player1) then { 
hint "Player1 no longer in Trigger";
player1 allowdamage true;
player1 removeaction 0; - Alternatively I also tried "removeallactions player1;" which didn't work either
};

and I noticed that you were trying to remove the first index of actions, and ArmA is weird when it comes to indexes and there's a nice trick of storing the index in a variable and then removing it instead of trying to remove all actions or trying to find the index of the action you were trying to remove, hence why I stored the action in a variable and removed it while its index was stored in a variable :D At least you got it sorted :)

 

Learning to code for ArmA is weird in many different ways, its took me about 3-4 years to learn how to code effectively to a point where I'm planning on building my own framework which will completely revolutionize the limits servers currently encounter, and it takes a long time to learn properly, but once you learn it its 100% worth it. Keep doing what you're doing, try and remake scripts that have been made already before looking at someone elses code, and then compare the effectiveness of it, or even do it the other way around, look at someone elses code and try and make it better by rewriting it.

  • Like 1

Share this post


Link to post
Share on other sites

Kinda pissy that not even a simple trigger will accept removeAction or removeAllActions

 

The point of my example was that you didn't have to use removeAction or a trigger at all for what you were doing.  The condition field on addAction could handle that effect.

Share this post


Link to post
Share on other sites

This guide, though a few years old now, covers the fundamentals really well, and was the guide that got me from knowing enough to scrape together some crap for myself, to understanding enough to be able to self-teach my way through most things. Give it a good look:

https://forums.bistudio.com/topic/145056-arma-3-scripting-tutorial-for-noobs/

Share this post


Link to post
Share on other sites

Sorry to revive this dead post but i cant make a new topic...lame.

Any way is there away to grab the index number of a user added action added with remoteExec? 

I want to remove and add actions based on game play conditions. Having a hard time figuring out how to reference the addAction index/id numbers.

 

Share this post


Link to post
Share on other sites

Sorry to revive this dead post but i cant make a new topic...lame.

Any way is there away to grab the index number of a user added action added with remoteExec? 

I want to remove and add actions based on game play conditions. Having a hard time figuring out how to reference the addAction index/id numbers.

 

Store the action Id in a variable

so:

JmpAction = player addaction ["Jump","jump.sqf"];

will store the action Id in Jmpaction then you would use removeaction action to just remove that one.

removeaction JmpAction;

if you are adding actions to players or objects individually and not at the same time then the variable can be applied to the object using setvariable

e.g

This is on a player using a local variable to then store on the player object

_Jmpaction = ["jump","jump.sqf"];player setvariable ["Jumpaction",_jmpAction];

then to remove action use

removeaction (player getvariable "Jumpaction");// you can then make the action variable nil to 'clear it out' player setvariable ["Jumpaction",nil];

Share this post


Link to post
Share on other sites

sorry to be more clear how do i grab the index number when its formatted like this?

 

FOBA_State = [ConTruck, ["Remove FOB-Alpha", {execVM "FOB\FOBA_Active.sqf"}]] remoteExec ["addAction", 0 , ConTruck, true];

FOBA_State  only grabs the return for the remoteExec function.

Share this post


Link to post
Share on other sites

sorry no idea on that one, maybe someone who has used remoteexec more can assist.

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

×