dreadedentity 278 Posted September 24, 2014 Hello all, As some of you may know, I'm terrible with addActions. So I need some help. I need a toggle-able action that, when used, will remove any other toggle-able actions in the player's action menu. I'm using this to pick up objects, so that's why it needs to be toggle-able and why other options need to be removed when used. Thanks Share this post Link to post Share on other sites
epicgoldenwarrior 11 Posted September 24, 2014 I think I'll be using this too, so Im gonna tell you what I know but I'm not a pro. You should label your action by doing (without []) [_actiona = player addAction ["Hint", hint.sqf"] then, hint.sqf should have a part that says [removeAction "_actiona";] I think it should work that way but I'm not there yet. Hope this helps Share this post Link to post Share on other sites
das attorney 858 Posted September 24, 2014 You'll need to save the other action indexes to an array (save globally or in missionNameSpace or similar). When your special action is used, remove all the actions and save all of their data to a player variable (make sure you know where it is local to. If in doubt use the persistent var on setVariable). Then when it is switched back, add the actions back in with the data saved in the variable. That's the way I would do it, (and am doing it for similar things). Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 24, 2014 What exactly do you mean by "toggle-able"? Do you mean, they should be added/removed, depending on the item placed / picked up? Share this post Link to post Share on other sites
dreadedentity 278 Posted September 24, 2014 What exactly do you mean by "toggle-able"? Do you mean, they should be added/removed, depending on the item placed / picked up? Yes. I'm trying to play around with it, but I'm really bad with actions Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 24, 2014 (edited) OK, this is what came to my mind firstly: allAddedActions = []; allAddedActions pushBack (player addAction ["Action 1", {[] call tag_fnc_yourFunction; {player removeAction _x;} count allAddedActions}]); allAddedActions pushBack (player addAction ["Action 2", {/*some code*/}]); allAddedActions pushBack (player addAction ["Action 3", {/*more code*/}]); allAddedActions pushBack (player addAction ["Action 4", {/*some more code*/}]); allAddedActions pushBack (player addAction ["Action 5", {/*even more code*/}]); /* missionNamespace setVariable ["allAddedActions", allAddedActions]; Alternatively, save allAddedActions to missionNamespace and change the function of Action 1 accordingly. */ EDIT: OK, reading the following post by Iceman77, it seems I didn't understand it thoroughly... Edited September 24, 2014 by waltenberg Share this post Link to post Share on other sites
iceman77 18 Posted September 24, 2014 (edited) Toggleable action. toggleOn = 0; _xIDx = player addAction ["Toggle Action", { if (toggleOn == 0) then { player sideChat "Action On"; toggleOn = 1; } else { player sideChat "Action Off"; toggleOn = 0; }; }, [], 6, false, true, "", ""]; More streamlined version by larrow. Utilizes setUserActiontext command. actionStatus = false; player addAction ["Turn On", { if (!actionStatus) then { hint "You have turned it On"; (_this select 0) setUserActionText [(_this select 2), "Turn Off"]; }else{ hint "You have turned it Off"; (_this select 0) setUserActionText [(_this select 2), "Turn On"]; }; actionStatus = !actionStatus; },[],1,true,true,"",""]; You can also use the condition parameter to dictate when the action is shown. actionAvail = true; _xIDx = player addAction ["Toggle Action", { hint "you've used the action"; actionAvail = false; }, [], 6, false, true, "", "actionAvail"]; variable changed in some other script example if (someCondition) then {actionAvail=true;} else {actionAvail=false;}; Anyhow, hope with all of this, you can find your way to glory =) Edited September 24, 2014 by Iceman77 Share this post Link to post Share on other sites
dreadedentity 278 Posted September 24, 2014 (edited) More streamlined version by larrow. Utilizes setUserActiontext command. actionStatus = false; player addAction ["Turn On", { if (!actionStatus) then { hint "You have turned it On"; (_this select 0) setUserActionText [(_this select 2), "Turn Off"]; }else{ hint "You have turned it Off"; (_this select 0) setUserActionText [(_this select 2), "Turn On"]; }; actionStatus = !actionStatus; },[],1,true,true,"",""]; Thanks, Iceman. I remember Larrow giving this code to me in a previous topic. I was trying to find a way to add it to the objects themselves without breaking the toggle-ability of them. I just wrote up this small init.sqf, it should be a good starting point for something like this. boxes = []; _playerPos = position player; for "_i" from 0 to 2 do { _position = [((_playerPos select 0) - 5) + (_i * 5), (_playerPos select 1) + 10, 0]; _obj = createVehicle ["Box_NATO_Wps_F", _position, [], 0, "None"]; boxes pushBack [_obj, str _obj]; }; hintSilent format["%1", boxes]; It simply spawns 3 boxes, 10 meters in front of the player, 5 meters apart from each other. Use any map you want, save, then create an init.sqf and drop that code in it. It saves an array of arrays, the first value is the object itself, and the second value is a string of the object's handle (my thinking is that since all of these strings are unique, and addAction handles must be unique this would be a good naming scheme). Going to start messing with the actions now. ---------- Post added at 17:56 ---------- Previous post was at 17:34 ---------- Well, I got it finished, and it was actually a lot easier than I thought. Just put this in your init.sqf. init.sqf boxes = []; actionStatus = false; _playerPos = position player; for "_i" from 0 to 2 do { _position = [((_playerPos select 0) - 5) + (_i * 5), (_playerPos select 1) + 10, 0]; _obj = createVehicle ["Box_NATO_Wps_F", _position, [], 0, "None"]; boxes pushBack [_obj, str _obj]; //Unnecessary _obj addAction ["Pick Up", { if (!actionStatus) then { (_this select 0) attachTo [(_this select 1)]; (_this select 0) setUserActionText [(_this select 2), "Drop"]; }else { detach (_this select 0); (_this select 0) setUserActionText [(_this select 2), "Pick Up"]; }; actionStatus = !actionStatus; },[],1,true,true,"",""]; }; hintSilent format["%1", boxes]; Problem with this is that if you happen to move your mouse over another object, you'll get the option to pick it up, and if you use that action twice you actually will pick it up. But since this is going to be used privately and not in a script I will release, this is where I stop :p EDIT: 2 things I forgot to say. 1. I believe the easiest way by far to do this is to add your action when you create the object so you still have access to the local variable you should be using to refer to the object in your spawning function. An alternative way to do this is to add your created object to a global array with pushBack, then spawn a seperate thread with a while loop that simply waits for the size of the array to change, then adds the action to the last object in the array. 2. Any unit that you want to be able to use the actions needs to have actionStatus declared (not necessarily in init, but before they encounter any situation where the action is available to them). If you use the exact code from above, actionStatus needs to be declared as a boolean. Edited September 24, 2014 by DreadedEntity Share this post Link to post Share on other sites
Larrow 2822 Posted September 25, 2014 for "_i" from 0 to 2 do { _position = [((_playerPos select 0) - 5) + (_i * 5), (_playerPos select 1) + 10, 0]; _obj = createVehicle ["Box_NATO_Wps_F", _position, [], 0, "None"]; _obj addAction ["Pick Up", { _box = _this select 0; _caller = _this select 1; _actionID = _this select 2; if (isNil {_box getVariable ["carried", nil]}) then { _box attachTo [_caller]; _box setUserActionText [_actionID, "Drop"]; _caller setVariable ["carrying", _box]; _box setVariable ["carried", _caller]; }else { detach _box; _box setUserActionText [_actionID, "Pick Up"]; _caller setVariable ["carrying", nil]; _box setVariable ["carried", nil]; }; },[],1,true,true,"","(isNil {_this getVariable ['carrying',nil]} || {_this getVariable 'carrying' == _target}) && (isNil {_target getVariable ['carried', nil]} || {_target getVariable 'carried' == _this}) "]; }; Removed any reliance on global variables, everything needed for operation is contained in the action itself. Added a condition so other boxes cannot be picked up whilst you have one and other players also cannot make you drop the box you are carrying. Think thats about right only quickly tested to make sure there were no silly mistakes. Share this post Link to post Share on other sites
jshock 513 Posted September 25, 2014 #Larrow has spoken:worship: Share this post Link to post Share on other sites
Larrow 2822 Posted September 25, 2014 Enough already, now your just trolling. Me and DE have spoken recently i know he has enough knowledge to understand the above so its just short and to the point. Im by no means a code genius, i like to script and i like to help. Alright i dont post any scripts ive made but instead i like to help others to help themselves. Do i posted long pieces of script that nealry do what you want alot of the time, yes, but atleast you have to read the things and implement them yourself unlike just dumping a premade script in your mission folder and adding aline. No offence to the guys who make these scripts, there are all kinds of people here, those.. who just want a premade script package, who just want to C&P who would like to learn by example who would like to discuss option and learn themselves If anyone ever wants me to not post examples in there threads just say and ill be happy to oblige. Share this post Link to post Share on other sites
dreadedentity 278 Posted September 25, 2014 (edited) Enough already, now your just trolling.Me and DE have spoken recently i know he has enough knowledge to understand the above so its just short and to the point. Im by no means a code genius, i like to script and i like to help. Alright i dont post any scripts ive made but instead i like to help others to help themselves. Do i posted long pieces of script that nealry do what you want alot of the time, yes, but atleast you have to read the things and implement them yourself unlike just dumping a premade script in your mission folder and adding aline. No offence to the guys who make these scripts, there are all kinds of people here, those.. who just want a premade script package, who just want to C&P who would like to learn by example who would like to discuss option and learn themselves If anyone ever wants me to not post examples in there threads just say and ill be happy to oblige. I try not to focus on anything I consider trolling, it's always a pleasure to look over your always-informative code and try to learn something from it/you. I consider myself to be the bottom 2 kinds of people. Keep coming in my threads!!! Edited September 25, 2014 by DreadedEntity Share this post Link to post Share on other sites
iceman77 18 Posted September 25, 2014 If anyone ever wants me to not post examples in there threads just say and ill be happy to oblige. But don't deprive the rest of the community. :cool: Share this post Link to post Share on other sites