Jump to content

Recommended Posts

Hello there,

 I'm making a control tower that can control multiple border gates for an upcoming server.

 

Relatively new to scripting, and only know the abseoulte basics. All have to start somewhere.

 

So the set up is, I have an addiction to open the script file on the Init of a object. 

 

Firstly how would I remove that add action after it has executed the script file

 

 

Next part, the script so far (pls dont comment on my newbness :)

 

_target = _this select 0;  
_caller = _this select 1;  
_actionId = _this select 2;  
 
//North Gate 1
 
_caller addAction ["Open North Gate 1", {NG_1 animate ["Door_1_rot", 1]}];
_caller removeAction _actionId;
 
 
 _caller addAction ["Close North Gate 1", {NG_1 animate ["Door_1_rot", 0]}];
_caller removeAction _actionId;
 
So what this displays is only the second addaction, Close northgate 1, which is not what I would want to do.
 
Ideally I would like to the person to only see the Close North Gate Addaction after executing the open northgate Addaction and for the Open Northgate addaction to be removed?. Im unsure how to write this using the SQF syntax, and have been scratching my head for the last 2 hours.
 
Also after executing Close Northgate I would like them to see the Open northgate again.
 
How would I go about doing this?
 
Thanks for any help you give me!
 
Regardless of the type of help, all help will be greatly appreciated
 
Best Regards
 
Rhys Priestland

Share this post


Link to post
Share on other sites

In your script you can't remove the action from the _caller using the _actionID, since the action is attached to the _target. Or are caller and target the same?

 

Usually you can add such behavior with setVariable / getVariable and using the condition on the addAction command, in this example however you can simply use this:

player addAction ["Open North Gate 1", {NG_1 animate ["Door_1_rot", 1]},nil,0,true,true,"","_target isequalto _this AND NG_1 animationPhase 'Door_1_rot' isEqualTo 0"];
player addAction ["Close North Gate 1", {NG_1 animate ["Door_1_rot", 0]},nil,0,true,true,"","_target isequalto _this AND NG_1 animationPhase 'Door_1_rot' isEqualTo 1"];

Here we are using animationPhase so you won't see any action during the bar is in transition, as soon as it's open/closed you'll see the respective action.

No need for constant action adding/removing.

 

Cheers

Share this post


Link to post
Share on other sites

You can make it easier by adding a condition to your action-code, so you dont have to remove/re-add the action at all.

 

Take a closer look at the available parameters for addaction:

https://community.bistudio.com/wiki/addAction

example:

someobject addAction ["Open North Gate 1", {
// code
    NG_1 animate ["Door_1_rot", 1];
},1,true,true,"",'
// condition
    NG_1 animationPhase "Door_1_rot" isEqualTo 0
'];

someobject addAction ["Close North Gate 1", {
// code
    NG_1 animate ["Door_1_rot", 0];
},1,true,true,"",'
// condition
    NG_1 animationPhase "Door_1_rot" isEqualTo 1
'];

 
Alternately, you could also use a single action to toggle the gate and just change its text accordingly.

someobject setVariable["actid", 
    someobject addAction ["Open North Gate 1", {
        // code
            if (NG_1 animationPhase "Door_1_rot" isEqualTo 0) then {
                NG_1 animate ["Door_1_rot", 1];
            } else {
                if (NG_1 animationPhase "Door_1_rot" isEqualTo 1) then {
                    NG_1 animate ["Door_1_rot", 0];
                };
            }; 
        },1,true,true,"",'
        // condition
            if (NG_1 animationPhase "Door_1_rot" isEqualTo 0) then {
                _target setUserActionText [_target getVariable "actid", "Open North Gate"];
            } else {
                if (NG_1 animationPhase "Door_1_rot" isEqualTo 1) then {
                    _target setUserActionText [_target getVariable "actid", "Close North Gate"];
                };
            };
        '
    ];
];

The latter is probably a bit better for performance.

 

 

 

 

ps.: Grumpy was faster :P

 

 

pps.: Why this ?

_target isequalto _this

That would only work if the action is attached to the player.

Edited by Tajin

Share this post


Link to post
Share on other sites
pps.: Why this ?

_target isequalto _this

That would only work if the action is attached to the player.

 

Oh well I assumed the "control tower" is a player, might have misread it,

addAction condition accepting code now? Thought it's string only, heh.

 

Cheers

Share this post


Link to post
Share on other sites

Thanks so much for the responces!

 

Tajin that was great, exactly what I needed!

 

Also Grumpy that was great too.

 

By any chance do you know how to get rid of the addaction to open the script. So when I go to the laptop it gives me an addaction which activates the script. Once activated I want that addaction to go away so that you cant open the script 100 times?

 

Thanks again for your responces!

 

Best Regards

 

Rhys Priestland

Share this post


Link to post
Share on other sites

addAction condition accepting code now?

 

Hmm, now that you mention it... I'm not even sure... maybe I mixed that up.  :wacko:

Share this post


Link to post
Share on other sites

Hi there again,

 When you said some object. when using _caller, player, or the object name, Arma throws an error?

 

Any reason why?

 

Sorry to be troubling you!

 

Thanks again

 

Priestland

Share this post


Link to post
Share on other sites

"an error" could be anything. Always show us exactly what the error says :P

I've corrected the scripts in my first post slightly. So maybe copy them again before you give it another try.

 

 

In general, I would recommend to create small test-szenarios and simply try out the different commands. See what different parameters do and get a feel for them. Using the debug window in the editor can also help alot when trying things out.

 

Also, this list is your best friend: https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3

Share this post


Link to post
Share on other sites
/*
	File: Border.sqf
	Author: Rhys Priestland

	Description:
	Used for controlling gates at Nato Border BRITISH RP USE ONLY.
*/



_target = _this select 0;  // Object that had the Action (also _target in the addAction command)
_caller = _this select 1;  // Unit that used the Action (also _this in the addAction command)
_actionId = _this select 2;  // ID of the Action

//North Gate 1

_caller addAction ["Open North Gate 1", {
// code
    NG_1 animate ["Door_1_rot", 1];
},1,true,true,"",'
// condition
    NG_1 animationPhase "Door_1_rot" isEqualTo 0
'];

_caller addAction ["Close North Gate 1", {
// code
    NG_1 animate ["Door_1_rot", 0];
},1,true,true,"",'
// condition
    NG_1 animationPhase "Door_1_rot" isEqualTo 1
'];



//Northgate 2

//Southgate 1

//Southgate 2

//Lockdown

Hiya again!

 

 

Sorry about that. So this is the code above i'm using so far. The _caller in this case, is just the player, So I've probably messed up the syntax somewhere!

 

Here is the error

 

https://gyazo.com/92cc92cfd32f04293156d38afcd48d39

 

Thanks again!!!!

 

 

Best Regards

 

Rhys Priestland

Share this post


Link to post
Share on other sites
/*
	File: Border.sqf
	Author: Rhys Priestland

	Description:
	Used for controlling gates at Nato Border BRITISH RP USE ONLY.
*/



_target = _this select 0;  // Object that had the Action (also _target in the addAction command)
_caller = _this select 1;  // Unit that used the Action (also _this in the addAction command)
_actionId = _this select 2;  // ID of the Action

//North Gate 1

_caller addAction ["Open North Gate 1", {
// code
    NG_1 animate ["Door_1_rot", 1];
},1,true,true,"",'
    NG_1 animationPhase "Door_1_rot" isEqualTo 0
'];

_caller addAction ["Close North Gate 1", {
// code
    NG_1 animate ["Door_1_rot", 0];
},1,true,true,"",'
    NG_1 animationPhase "Door_1_rot" isEqualTo 1
'];



//Northgate 2

//Southgate 1

//Southgate 2

//Lockdown

My bad, I shouldn't put comments into a string.

Share this post


Link to post
Share on other sites
/*
	File: Border.sqf
	Author: Rhys Priestland

	Description:
	Used for controlling gates at Nato Border BRITISH RP USE ONLY.
*/

_target = _this select 0;  // Object that had the Action (also _target in the addAction command)
_caller = _this select 1;  // Unit that used the Action (also _this in the addAction command)
_actionId = _this select 2;  // ID of the Action

//North Gate 1

_caller addAction ["Open North Gate 1", {
// code
    NG_1 animate ["Door_1_rot", 1];
},1,true,true,"",'
    NG_1 animationPhase "Door_1_rot" isEqualTo 0
'];

_caller addAction ["Close North Gate 1", {
// code
    NG_1 animate ["Door_1_rot", 0];
},1,true,true,"",'
    NG_1 animationPhase "Door_1_rot" isEqualTo 1
'];


//Northgate 2
//Southgate 1
//Southgate 2
//Lockdown

My bad, I shouldn't put comments into a string.

 

Expanding on this and the setUserActionText example which Tajin posted earlier:

/*
	File: Border.sqf
	Author: Rhys Priestland

	Description:
	Used for controlling gates at Nato Border BRITISH RP USE ONLY.
*/
params ["_target", "_caller", "_actionId"];

// _target - Object that had the Action (also _target in the addAction command)
// _caller - Unit that used the Action (also _this in the addAction command)
// _actionId - ID of the Action

_caller addAction [
	"Open North Gate 1",
	{
		params ["_target", "", "_id"];

		NG_1 animate [
			"Door_1_rot", 
			[1, 0] select (NG_1 animationPhase "Door_1_rot" isEqualTo 1)
		];
		
		_target setUserActionText [
			_id, 
			["Open North Gate 1", "Close North Gate 1"] select (NG_1 animationPhase "Door_1_rot" isEqualTo 0)
		];
	},
	[], 1, true, true, "",
	'isNull objectParent _this', -1
];

//Northgate 2
//Southgate 1
//Southgate 2
//Lockdown

You can remove the condition in the string before the -1. I added it because I didn't like how the player could open the gate while in a vehicle.

So you can copy and paste the addaction for each gate, replacing the NG_1 in the action or simply do it using forEach

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

×