Jump to content
  • 0

addaction without external script


raymix

Question

quite an annoying one, spent too much time on this...

 

KK demonstrating it on A3 and even Arma wiki stating that:

  • scriptString or Code - Either path to the script file, relative to the mission folder, or (since Take On Helicopters) the actual script code.

 

Yet it does not work, even with example provided down below in wiki:

player addAction ["Hint Hello!", { hint format ["Hello %1!", _this select 3] }, name player];

I did notice it states code since TKOH, does that mean only Arma 2.5 and 3 supports this?

 

To give you an example, this does not work:

_test = player addAction ["Test", {hint"TEST"}]; //nop

_test = player addAction ["Test", {hint"TEST"},""]; //nop

_test = player addAction ["Test",""]; //works

All I want to do is simply change a bool trough addaction without creating a new file just for a single damn line of code, lol

 

Kinda like this:

_test = player addAction ["Test",{_check = true}];

Any clues?

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

it wont work for arma 2, the instructions are mixed with TKOH info that dosnt make much sense and dosnt work for arma 2 either

 

use a scipt to simulate what you intended to do from the addaction then parse the function you want to call/spawn to the script 

Link to comment
Share on other sites

  • 0

someone already did this, but i cant find the file now (i think it was called genaction.sqf or something simmular)

 

anyways, the concept was quite simple really, it was basicly a switch using code and arguments parsed through the addaction to the script.

 

im sure you can find it if you search around for it on armaholics.

Link to comment
Share on other sites

  • 0

Cheers, what I simply want to achieve is toggle-able addaction that changes it's name depending on string in variable and is always a top action, kinda like this:

 

myself.sqf

_string = (_this select 3);
_ok = "on"

if (_ok != _string) then {
_test = player addaction [format[("<t color=""#ffffff"">" + ("Test: %1") +"</t>"),_string],"myself.sqf","_string = 'on';",6,true,true];
} else {
_test = player addaction [format[("<t color=""#ffffff"">" + ("Test: %1") +"</t>"),_string],"myself.sqf","_string = 'off';",6,true,true];
};

I'll report later if this actually works out

 

It works. Script itself can be called, arguments passed works fine with switch, too.

Edited by raymix
Link to comment
Share on other sites

  • 0

If not found yet, here is the gen_action.sqf file that u can use for such calls:

/*	---Generic Action Script---
	Author: [EVO] Curry
	Function: Enables you to run any code directly from the addAction command
	Installation: Copy into your missions folder and call this file through addAction
	Example usage:  
		In init of something
		this addAction ["Say Hello World!","gen_action.sqf","player sideChat 'Hello World!';"];
		
	Notes: Recommended only for simple code or for testing scripts/functions designed for inits and triggers
*/

//Parameter one: String or Code - Whatever commands you want to issue, remember to check the syntax ;)

private ["_target","_caller","_ID","_arguments"];
_target 	= _this select 0;
_caller 	= _this select 1;
_ID			= _this select 2;
_arguments 	= _this select 3;

switch (typeName _arguments) do {
	case "STRING": 	
	{
		nul = [_target,_caller,_ID] spawn (compile _arguments);
	};
	case "CODE":	
	{
		nul = [_target,_caller,_ID] spawn _arguments;
	};
	default			
	{
		diag_log text "Error in gen_action.sqf: Invalid type passed to function.";
	};
};

and here a link to the BIS forum entry for it:

http://forums.bistudio.com/showthread.php?98108-addAction-simplified

 

 

Moo,

Otter

Link to comment
Share on other sites

  • 0

Oh, I've seen this one before, thanks.

 

Ended up using something very similar with switch and using addaction to call its own file, where a single argument is being changed that flips the switch removing old action and creating a new one with a little different name and different switch condition - basically toggling multiple addactions within 1 script.

 

I am currently stuck trying to understand forEach tho which basically adds or deletes amount of actions counted in an array. Kinda like how repair vehicle does, but this will be for nearobjects and their snap points array pulled from config file later.

 

Heading to bed now. my brain simply refuses to fix this, been coding on and off all day, lol.

edit: just spotted what I did wrong... guess it's another "just 5 more minutes" on this

 

edit2: all working now!

Edited by raymix
Link to comment
Share on other sites

  • 0

Here's a solution I've been working on just this past week, after only having just discovered the AddAction command is broken!
The toggle is based upon your assistance and code above. So thanks to "raymix" above for your persistence. I'm only 5 years late and god knows how many hours I've persisted this week. Easily close to 8+ hrs studying and learning code. 

Below I've now updated my post which demonstrates three versions of using "addAction" command to toggle your captive state.
This includes _StringSelect != _toggle_NotEqualOn ; _StringSelect == _toggle_EqualOn ;  Case with switch (_StringSelect) do {} , examples: 


Initialization code included for player, enjoy!

 

/* 
//////////////////////////////////////////////////////////////////
// Function/Procedure Script file for ArmA2
// Title: toggle_NotEqual.sqf
// by JohnDougls, based on raymix script,
// https://epochmod.com/forum/topic/12901-addaction-without-external-script
//////////////////////////////////////////////////////////////////
// SQF Script: toggle_NotEqual.sqf
// 
// Edit Unit init:
// displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_NotEqual.sqf","Off",6,true,true];
/////////////////////////////////////////////////////////////////// 	
*/
 
_StringSelect = (_this select 3);
_toggle_NotEqualOn = "On";

///////////////////////////////////////	
//1.    Off!   =   On   (true)
//2.     On!   =   On   (false)
///////////////////////////////////////


if (_StringSelect != _toggle_NotEqualOn) then {
///////////////////////////////////////
// Off !=  On is true
// Set AddAction "Off", having selected "displayAction_on"
///////////////////////////////////////
displayAction_Off = player addaction [format[("<t color=""#FF7F50"">" + ("Off %1") +"</t>"),""],"toggle_NotEqual.sqf","On",6,true,true];    	
	player setCaptive True;
	player removeAction displayAction_on;

	
} else {
///////////////////////////////////////	
// On !=  On is false
// Set AddAction "On", having selected "displayAction_Off"
/////////////////////////////////////// 
displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_NotEqual.sqf","Off",6,true,true];
	player setCaptive False;
	player removeAction displayAction_Off;
	
};


_Variable1 = _StringSelect;
_Variable2 = _StringSelect;
_Variable3 = captive player; 

Sleep 1;
  hintSilent format ["displayAction: %1\n_StringSelect: %2\n_captive player: %3", _Variable1, _Variable2, _Variable3];
Sleep 5;

 

 

/* 
//////////////////////////////////////////////////////////////////
// Function/Procedure Script file for ArmA2
// Title: toggle_Equal.sqf
// by JohnDougls, based on raymix script,
// https://epochmod.com/forum/topic/12901-addaction-without-external-script
//////////////////////////////////////////////////////////////////
// SQF Script: toggle_Equal.sqf
// 
// Edit Unit init:
// displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_Equal.sqf","Off",6,true,true];
/////////////////////////////////////////////////////////////////// 	
*/
 
_StringSelect = (_this select 3);
_toggle_EqualOn = "On";

///////////////////////////////////////	
//1.     On   =   On   (true)
//2.    Off   =   On   (false)
///////////////////////////////////////


if (_StringSelect == _toggle_EqualOn) then {
///////////////////////////////////////	
// On =  On is true
// Set AddAction "On", having selected "displayAction_Off"
///////////////////////////////////////	
displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_Equal.sqf","Off",6,true,true];
	player setCaptive False;
	player removeAction displayAction_Off;

	
} else {
///////////////////////////////////////
// Off =  On is false
// Set AddAction "Off", having selected "displayAction_on"
///////////////////////////////////////
displayAction_Off = player addaction [format[("<t color=""#FF7F50"">" + ("Off %1") +"</t>"),""],"toggle_Equal.sqf","On",6,true,true];    	
	player setCaptive True;
	player removeAction displayAction_on;
	
};


_Variable1 = _StringSelect;
_Variable2 = _StringSelect;
_Variable3 = captive player; 

Sleep 1;
  hintSilent format ["displayAction: %1\n_StringSelect: %2\n_captive player: %3", _Variable1, _Variable2, _Variable3];
Sleep 5;

 

 

/* 
//////////////////////////////////////////////////////////////////
// Function/Procedure Script file for ArmA2
// Title: toggle_Case.sqf
// by JohnDougls, based on raymix script,
// https://epochmod.com/forum/topic/12901-addaction-without-external-script
//////////////////////////////////////////////////////////////////
// SQF Script: toggle_Case.sqf
// 
// Edit Unit init:
// displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_Case.sqf","Off",6,true,true];
/////////////////////////////////////////////////////////////////// 	
*/
 
_StringSelect = (_this select 3);

///////////////////////////////////////	
//     case "On": 
//     case "Off": 
//     case "default": 
///////////////////////////////////////

switch (_StringSelect) do {
    
    case "On": 
    { 
    		///////////////////////////////////////	
		// case "On": 
		// Set AddAction "On", having selected "displayAction_Off"
		///////////////////////////////////////	
		displayAction_on = player addaction [format[("<t color=""#32CD32"">" + ("On %1") +"</t>"),""],"toggle_Equal.sqf","Off",6,true,true];
			player setCaptive False;
			player removeAction displayAction_Off;
    };
    
    case "Off": 
    { 
    		///////////////////////////////////////
		// case "Off":
		// Set AddAction "Off", having selected "displayAction_on"
		///////////////////////////////////////
		displayAction_Off = player addaction [format[("<t color=""#FF7F50"">" + ("Off %1") +"</t>"),""],"toggle_Equal.sqf","On",6,true,true];    	
			player setCaptive True;
			player removeAction displayAction_on;
	    };
    
    default 
    {
	    
	      ///////////////////////////////////////
		// case "default":
		// - default block will be executed only if no case matches
		/////////////////////////////////////// 
    		hint "error!" 
    };

};


_Variable1 = _StringSelect;
_Variable2 = _StringSelect;
_Variable3 = captive player; 

Sleep 1;
  hintSilent format ["displayAction: %1\n_StringSelect: %2\n_captive player: %3", _Variable1, _Variable2, _Variable3];
Sleep 5;

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...