Jump to content
kdk11

AddAction available after AddAction has been used.

Recommended Posts

Hello I currently have a Data Terminal placed in my mission with AddActions to allow scripts to open and close the Terminal. I was wondering how I would be able to add an action inbetween both the "open" and "close" AddActions so that you have to open the Terminal before being able to use my second AddAction and before being able to use the "close" AddAction?.

Below is the script I am using that I found on the forum, thanks to simon1279.

 

 

in the init of the object (Land_DataTerminal_01_F):

[[this,["Open","DataTerminal\OpenTerminal.sqf"]],"addAction",true] call BIS_fnc_MP;

Make a folder named: DataTerminal

 

inside the folder named DataTerminal put these 2 files:

 

OpenTerminal.sqf

_object = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_object removeaction _id;
[_object,3] call BIS_fnc_dataTerminalAnimate;
sleep 2;
with uiNamespace do {
disableserialization; //thank you so much tankbuster
_object setObjectTexture [0,"\A3\Missions_F_EPA\video\A_in_intro.ogv"];
1100 cutRsc ["RscMissionScreen","PLAIN"];
_scr = BIS_RscMissionScreen displayCtrl 1100;
_scr ctrlSetPosition [-10,-10,0,0];
_scr ctrlSetText "\A3\Missions_F_EPA\video\A_in_intro.ogv";
_scr ctrlAddEventHandler ["VideoStopped", {
(uiNamespace getVariable "BIS_RscMissionScreen") closeDisplay 1;
}];
_scr ctrlCommit 0;
};
sleep 10;
_closeaction = [[_object,["Close","DataTerminal\CloseTerminal.sqf"]],"addAction",true] call BIS_fnc_MP;

CloseTerminal.sqf

_object = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_object removeaction _id;
[_object,0] call BIS_fnc_dataTerminalAnimate;
sleep 10;
_openaction = [[_object,["Open","DataTerminal\OpenTerminal.sqf"]],"addAction",true] call BIS_fnc_MP;

OpenTerminal.sqf (alternative version)

_object = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_object removeaction _id;
[_object,3] call BIS_fnc_dataTerminalAnimate;
sleep 2;
with uiNamespace do {
disableserialization; //thank you so much tankbuster
_object setObjectTexture [0,"\A3\Missions_F_EPA\video\A_in_intro.ogv"];
_object setObjectTexture [1,"\A3\Missions_F_EPA\video\A_in_intro.ogv"]; ////added this texture selection to make both monitors showing the video
1100 cutRsc ["RscMissionScreen","PLAIN"];
_scr = BIS_RscMissionScreen displayCtrl 1100;
_scr ctrlSetPosition [-10,-10,0,0];
_scr ctrlSetText "\A3\Missions_F_EPA\video\A_in_intro.ogv";
_scr ctrlAddEventHandler ["VideoStopped", {
(uiNamespace getVariable "BIS_RscMissionScreen") closeDisplay 1;
}];
_scr ctrlCommit 0;
};
sleep 10;
_closeaction = [[_object,["Close","DataTerminal\CloseTerminal.sqf"]],"addAction",true] call BIS_fnc_MP;
 

 

Share this post


Link to post
Share on other sites

I would use the condition parameter of the addAction command to control when to display the actions. As condition, I'd use a simple status or state variable saved to the terminal object.

 

General idea:

 

this addAction ["Open",......,"(_target getVariable ['KDK_TerminalStatus',0]) == 0"];

this addAction ["Do something while its open",......,"(_target getVariable ['KDK_TerminalStatus',0]) == 1"];

this addAction ["Close",......,"(_target getVariable ['KDK_TerminalStatus',0]) == 2"];
 

openScript:

_object setVariable ["KDK_TerminalStatus",1,true];

 

inBetweenScript:

_object setVariable ["KDK_TerminalStatus",2,true];

 

closeScript:

_object setVariable ["KDK_TerminalStatus",0,true];

 
 

This way you wont even need to bother with the add/removeAction via fnc_MP. Condition-method is perfect for few actions, but I wouldn't use it if you are planning on having a huge number of actions. But it also easily enables you to have multiple actions available at the same time, in any combination.

Share this post


Link to post
Share on other sites

this addAction ["Open",......,"(_target getVariable ['KDK_TerminalStatus',0]) == 0"];

this addAction ["Do something while its open",......,"(_target getVariable ['KDK_TerminalStatus',0]) == 1"];

this addAction ["Close",......,"(_target getVariable ['KDK_TerminalStatus',0]) == 2"];
 

 

Thanks for the reply :) Would I use the code above in the init of the Terminal?.

Share this post


Link to post
Share on other sites

Thanks for the reply :) Would I use the code above in the init of the Terminal?.

 

Yes, it would replace the:

 

[[this,["Open","DataTerminal\OpenTerminal.sqf"]],"addAction",true] call BIS_fnc_MP;

Share this post


Link to post
Share on other sites

openScript:

_object setVariable ["KDK_TerminalStatus",1,true];

 

inBetweenScript:

_object setVariable ["KDK_TerminalStatus",2,true];

 

closeScript:

_object setVariable ["KDK_TerminalStatus",0,true];

 

 

And would these lines go into each script? or my init.sqf maybe? Sorry I am not very good with coding.

Share this post


Link to post
Share on other sites

And would these lines go into each script? or my init.sqf maybe? Sorry I am not very good with coding.

i would guess in 

Open Terminal.sqf

 

above:

_closeaction = [[_object,["<t color='#ff0000'>Close-Box<t>","DataTerminal\CloseTerminal.sqf"]],"addAction",true] call BIS_fnc_MP;

Share this post


Link to post
Share on other sites

Init field of the terminal:

this addAction ["Open Terminal","terminal.sqf",0,2,true,true,"","(_target getVariable ['KDK_TerminalStatus',0]) == 0"];
this addAction ["Use Terminal","terminal.sqf",1,2,true,true,"","(_target getVariable ['KDK_TerminalStatus',0]) == 1"];
this addAction ["Close Terminal","terminal.sqf",2,2,true,true,"","(_target getVariable ['KDK_TerminalStatus',0]) == 2"];

terminal.sqf in the mission folder:

params ["_object","_state"];
_state = _this select 3;
switch _state do {
  case 0: { // Open terminal
    _object setVariable ["KDK_TerminalStatus",1,true];
    [_object,3] call BIS_fnc_dataTerminalAnimate;
    sleep 2;
    with uiNamespace do {
      disableSerialization;
      _object setObjectTexture [0,"\A3\Missions_F_EPA\video\A_in_intro.ogv"]; 
      1100 cutRsc ["RscMissionScreen","PLAIN"];
      _scr = BIS_RscMissionScreen displayCtrl 1100;
      _scr ctrlSetPosition [-10,-10,0,0];
      _scr ctrlSetText "\A3\Missions_F_EPA\video\A_in_intro.ogv";
      _scr ctrlAddEventHandler ["VideoStopped", {
        (uiNamespace getVariable "BIS_RscMissionScreen") closeDisplay 1;
      }];
      _scr ctrlCommit 0;
    };
  };
  case 1: { // Use terminal
    _object setVariable ["KDK_TerminalStatus",2,true];
  };
  case 2: { // Close terminal
    _object setVariable ["KDK_TerminalStatus",0,true];
    [_object,0] call BIS_fnc_dataTerminalAnimate;
  };
};

exampleMission

 

 

Someone smarter can help you how to stop the video(sound) when closing the terminal before the video has ended. I'm not familiar with the resources and controls.

Share this post


Link to post
Share on other sites

Init field of the terminal:

this addAction ["Open Terminal","terminal.sqf",0,2,true,true,"","(_target getVariable ['KDK_TerminalStatus',0]) == 0"];
this addAction ["Use Terminal","terminal.sqf",1,2,true,true,"","(_target getVariable ['KDK_TerminalStatus',0]) == 1"];
this addAction ["Close Terminal","terminal.sqf",2,2,true,true,"","(_target getVariable ['KDK_TerminalStatus',0]) == 2"];

terminal.sqf in the mission folder:

params ["_object","_state"];
_state = _this select 3;
switch _state do {
  case 0: { // Open terminal
    _object setVariable ["KDK_TerminalStatus",1,true];
    [_object,3] call BIS_fnc_dataTerminalAnimate;
    sleep 2;
    with uiNamespace do {
      disableSerialization;
      _object setObjectTexture [0,"\A3\Missions_F_EPA\video\A_in_intro.ogv"]; 
      1100 cutRsc ["RscMissionScreen","PLAIN"];
      _scr = BIS_RscMissionScreen displayCtrl 1100;
      _scr ctrlSetPosition [-10,-10,0,0];
      _scr ctrlSetText "\A3\Missions_F_EPA\video\A_in_intro.ogv";
      _scr ctrlAddEventHandler ["VideoStopped", {
        (uiNamespace getVariable "BIS_RscMissionScreen") closeDisplay 1;
      }];
      _scr ctrlCommit 0;
    };
  };
  case 1: { // Use terminal
    _object setVariable ["KDK_TerminalStatus",2,true];
  };
  case 2: { // Close terminal
    _object setVariable ["KDK_TerminalStatus",0,true];
    [_object,0] call BIS_fnc_dataTerminalAnimate;
  };
};

exampleMission

 

 

Someone smarter can help you how to stop the video(sound) when closing the terminal before the video has ended. I'm not familiar with the resources and controls.

 

Thanks for the reply and the example mission, I appreciate that and I can kinda see how it works. But my second option will be "power off grid" and then I want that action to execute the script "lights.sqf" that I have in my mission folder. So I tried this...

 

this addAction ["Open Terminal","terminal.sqf",0,2,true,true,"","(_target getVariable ['KDK_TerminalStatus',0]) == 0"];
this addAction ["Power off grid","lights.sqf",1,2,true,true,"","(_target getVariable ['KDK_TerminalStatus',0]) == 1"];
this addAction ["Close Terminal","terminal.sqf",2,2,true,true,"","(_target getVariable ['KDK_TerminalStatus',0]) == 2"];

And it did not work, and I know why it did not work. But to get it to work I assume that I somehow have to put my "lights.sqf" in the code below?. I will try and research how to do this but I just know once I start playing around with your code I will break something lol.

 

params ["_object","_state"];
_state = _this select 3;
switch _state do {
  case 0: { // Open terminal
    _object setVariable ["KDK_TerminalStatus",1,true];
    [_object,3] call BIS_fnc_dataTerminalAnimate;
    sleep 2;
    with uiNamespace do {
      disableSerialization;
      _object setObjectTexture [0,"\A3\Missions_F_EPA\video\A_in_intro.ogv"]; 
      1100 cutRsc ["RscMissionScreen","PLAIN"];
      _scr = BIS_RscMissionScreen displayCtrl 1100;
      _scr ctrlSetPosition [-10,-10,0,0];
      _scr ctrlSetText "\A3\Missions_F_EPA\video\A_in_intro.ogv";
      _scr ctrlAddEventHandler ["VideoStopped", {
        (uiNamespace getVariable "BIS_RscMissionScreen") closeDisplay 1;
      }];
      _scr ctrlCommit 0;
    };
  };
  case 1: { // Use terminal
    _object setVariable ["KDK_TerminalStatus",2,true];
  };
  case 2: { // Close terminal
    _object setVariable ["KDK_TerminalStatus",0,true];
    [_object,0] call BIS_fnc_dataTerminalAnimate;
  };
};

Thanks again for your time dude :)

Share this post


Link to post
Share on other sites

Add it to the case 1:

case 1: { // Use terminal
  _object setVariable ["KDK_TerminalStatus",2,true];
  [] execvm "lights.sqf";
};

Share this post


Link to post
Share on other sites

Thanks that worked :D I have removed the close action as I dont need it, it can just stay open. I have one last question, I know about the sleep command am just wondering where in the terminal.sqf I would put it so that there is a pause from opening the terminal to then being able to chose the next action?.

Share this post


Link to post
Share on other sites
  case 0: { // Open terminal
    [_object,3] call BIS_fnc_dataTerminalAnimate;
    sleep 2;
    with uiNamespace do {
      disableSerialization;
      _object setObjectTexture [0,"\A3\Missions_F_EPA\video\A_in_intro.ogv"]; 
      1100 cutRsc ["RscMissionScreen","PLAIN"];
      _scr = BIS_RscMissionScreen displayCtrl 1100;
      _scr ctrlSetPosition [-10,-10,0,0];
      _scr ctrlSetText "\A3\Missions_F_EPA\video\A_in_intro.ogv";
      _scr ctrlAddEventHandler ["VideoStopped", {
        (uiNamespace getVariable "BIS_RscMissionScreen") closeDisplay 1;
      }];
      _scr ctrlCommit 0;
    };
    sleep 5;
    _object setVariable ["KDK_TerminalStatus",1,true];
  };

I moved the setVariable to the end of the case. Before that I added five second sleep. Change the time to whatever you want.

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

×