CuddleTank001 3 Posted May 26, 2019 Im trying to add actions that are exclusive to characters carrying ak-12 30 rnd magazines, or maybe to characters that are wearing the NATO pilot coveralls, and i cant figure a way to do so, can i please get some help? 1 Share this post Link to post Share on other sites
sarogahtyp 1109 Posted May 26, 2019 Here are the tools: currentWeapon uniform typeOf If you need further help then show what you have done so far, pls. 1 Share this post Link to post Share on other sites
GEORGE FLOROS GR 4207 Posted May 26, 2019 Hello there CuddleTank001 ! It's good and worth to make a search first , because there might be a topic already made for this : GOOGLE : addaction if item https://www.google.com/search?client=firefox-b-d&ei=LPjqXI7iIcSzkwXj6ayYAQ&q=addaction+if+item&oq=addaction+if+item&gs_l=psy-ab.3...21302.23508..23871...0.0..0.175.288.0j2......0....1..gws-wiz.hnrzihk6wcI Check here : 1 Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 27, 2019 ok so i tried Player addAction ["<t color='#FFFF00'>repair</t>",{cursorTarget setDamage 0;},[],-1,false,true,"","_weaponclass = [hgun_P07_snds_F]"]; but it just hid the action and no matter what gun i hold it wouldn't show back up, so what did i do wrong? Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 27, 2019 i also tried Player addAction ["<t color='#FFFF00'>repair</t>",{cursorTarget setDamage 0;},[],-1,false,true,"","([hgun_P07_snds_F] = currentWeapon player)"]; but it didn't work neither, and gave me a missing ; error. Share this post Link to post Share on other sites
sarogahtyp 1109 Posted May 27, 2019 3 minutes ago, CuddleTank001 said: "([hgun_P07_snds_F] = currentWeapon player)" 22 minutes ago, CuddleTank001 said: "_weaponclass = [hgun_P07_snds_F]"]; both nonsense. what is intended with this? Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 27, 2019 im trying to only show this action to players with PO7s in their hands Share this post Link to post Share on other sites
sarogahtyp 1109 Posted May 27, 2019 'toLower (typeOf currentWeapon player) isEqualTo "hgun_p07_snds_f"' didn't test but should work if the classname is correct (except lower case) EDIT: or better just: 'typeOf currentWeapon player isEqualTo "hgun_P07_snds_F"' 1 Share this post Link to post Share on other sites
jshock 513 Posted May 27, 2019 Going back to OP about mags and uniform: fnc_hasTheStuff = { params [ ["_unit",objNull,[objNull]], ["_magClasses",[],[[]]], ["_uniClasses",[],[[]]] ]; private _uniClass = toLower uniform _unit; private _magArr = magazines _unit; _magArr pushBackUnique currentMagazine _unit; { _x = _x apply {toLower _x}; } forEach [_magClasses,_uniClasses,_magArr]; private _hasMag = count (_magArr arrayIntersect _magClasses) > 0; private _hasUni = _uniClasses find _uniClass > -1; _hasMag || _hasUni; }; player addAction [ "My Action", {/*do stuff*/}, [], -1, false, true, "", "[_originalTarget,['myMagClass1','myMagClass2'],['myUniformClass1']] call fnc_hasTheStuff" ]; Of course replace info where necessary (in the addAction portion), fnc_hasTheStuff is called with the parameters of a unit (namely the player), an array of magazine classnames and an array of uniform classnames, if the player has either the right magazine or the right uniform then the action is shown. 1 Share this post Link to post Share on other sites
Dedmen 2717 Posted May 28, 2019 19 hours ago, sarogahtyp said: typeOf currentWeapon player Taking typeOf of a string? typeOf takes object. 19 hours ago, sarogahtyp said: except lower case Why not just use "==" instead of "isEqualTo" then? 18 hours ago, jshock said: _x = _x apply {toLower _x}; Your "_x =" doesn't update _x, it creates a copy of the array (plus the copy that apply created, plus the copy that toLower created of every string in the array) 18 hours ago, jshock said: _magArr arrayIntersect _magClasses Another copy of the array. Also what's that supposed to do? arrayIntersect removes duplicates, unless both arrays are empty, it will always return more than 0 elements, so your _hasMag will always be true. Instead of copying everything multiple times and toLower'ing it, you can just use findIf to make a case-insensitive search. fnc_hasTheStuff = { params [ ["_unit",objNull,[objNull]], ["_magClasses",[],[[]]], ["_uniClasses",[],[[]]] ]; private _hasUniform = (_uniClasses isEqualTo []) || { private _unitUniform = uniform _unit; _uniClasses findIf {_x == _unitUniform} > -1 }; if (_hasUniform) exitWith {_hasUniform}; //Exit early as uniform is cheaper to check than mags private _magClasses = _magClasses apply {toLower _x}; //It is very likely that player isn't carrying multiple types of magazines //And that also means its very likely that he already has one of the magazines that he carries loaded into his weapon //Simply assuming this and checking this first, saves the need to look up all other magazines (toLower currentMagazine _unit) in _magClasses) || { //Putting the toLower for magazines into the findIf means we might not need to toLower every magazine (which might be a big number) (magazines _unit) findIf {toLower _x in _magClasses} > -1 } }; Share this post Link to post Share on other sites
jshock 513 Posted May 28, 2019 From the wiki arrayIntersects: Quote Intersects array1 with array2 returning array of unique common elements. So if they don’t share an element the returned value should be []. I did test this before posting. I avoided making a number of the assumptions you’ve made in your code simply because OP never really specified the intent of the action, only that it’s available when the player has a certain magazine (which can be a type that isn’t for the weapon the player carries, think wasteland or survival modes where you pick up what you can) or uniform. I concede on otherwise inefficient code though, forgot findIf even existed . Share this post Link to post Share on other sites
Dedmen 2717 Posted May 28, 2019 1 hour ago, jshock said: From the wiki arrayIntersects: Oops. I wanted to delete that before I post the message. Ignore that part. Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 28, 2019 im kinda new to this whole scripting thingy and the mag script looks intimidating tbh so i'll just stick to the weapon script, so i ended up with Player addAction ["<t color='#FFFF00'>repair</t>",{cursorTarget setDamage 0;},[],-1,false,true,"","toLower (typeOf currentWeapon player) isEqualTo "hgun_p07_f""]; but the message gave me a missing ] error, so what did i do wrong? Share this post Link to post Share on other sites
jshock 513 Posted May 28, 2019 Lol, understandable. When there are other strings present within the condition string they must be enclosed in either single quotes ('mystuff') or double quotes (""my stuff""). See below for your fixed condition: "toLower (typeOf currentWeapon player) isEqualTo 'hgun_p07_f'" //OR "toLower (typeOf currentWeapon player) isEqualTo ""hgun_p07_f""" Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 28, 2019 that still gives me the error Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 28, 2019 and arent "toLower (typeOf currentWeapon player) isEqualTo "hgun_p07_f"" and "toLower (typeOf currentWeapon player) isEqualTo 'hgun_p07_f'" the same? the only difference that i can spot is that one of them is more tidier than the other Share this post Link to post Share on other sites
sarogahtyp 1109 Posted May 28, 2019 4 minutes ago, CuddleTank001 said: im kinda new to this whole scripting thingy and the mag script looks intimidating tbh so i'll just stick to the weapon script, so i ended up with Player addAction ["<t color='#FFFF00'>repair</t>",{cursorTarget setDamage 0;},[],-1,false,true,"","toLower (typeOf currentWeapon player) isEqualTo "hgun_p07_f""]; but the message gave me a missing ] error, so what did i do wrong? as @Dedmen stated I did a mistake. no need for typeOf as currentWeapon already returns the classname of the weapon. use this: Player addAction ["<t color='#FFFF00'>repair</t>",{cursorTarget setDamage 0;},[],-1,false,true,"",'currentWeapon player == "hgun_p07_f"']; 2 Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 28, 2019 2 minutes ago, sarogahtyp said: as @Dedmen stated I did a mistake. no need for typeOf as currentWeapon already returns the classname of the weapon. use this: Player addAction ["<t color='#FFFF00'>repair</t>",{cursorTarget setDamage 0;},[],-1,false,true,"",'currentWeapon player == "hgun_p07_f"']; yup that worked, thx for the help! Share this post Link to post Share on other sites
sarogahtyp 1109 Posted May 28, 2019 5 minutes ago, CuddleTank001 said: that still gives me the error ALWAYS show the errors pls 3 minutes ago, CuddleTank001 said: and arent "toLower (typeOf currentWeapon player) isEqualTo "hgun_p07_f"" and "toLower (typeOf currentWeapon player) isEqualTo 'hgun_p07_f'" the same? the only difference that i can spot is that one of them is more tidier than the other no. arma cant parse " here comes a string in a string: " I am the inner string"" but it can ' here comes a string in a string: " I am the inner string"' and it can " here comes a string in a string: 'I am the inner string'" and it can " here comes a string in a string: ""I am the inner string""" Share this post Link to post Share on other sites
jshock 513 Posted May 28, 2019 7 minutes ago, CuddleTank001 said: and arent "toLower (typeOf currentWeapon player) isEqualTo "hgun_p07_f"" and "toLower (typeOf currentWeapon player) isEqualTo 'hgun_p07_f'" the same? the only difference that i can spot is that one of them is more tidier than the other Sorry missed that you were still doing "typeOf currentWeapon player", see @sarogahtyp post above this. And to answer this simply, no they are not the same, because the condition is evaluated as a string anything within two ". So in your original condition, it is evaluting only: "toLower (typeOf currentWeapon player) isEqualTo " So it will throw an error no only because the condition itself is incomplete code (and it expects the closing addAction bracket) but also because there is incomplete code outside of that condition string, e.g. the rest of the condition itself. 1 Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 28, 2019 thank you both for your condition parsing explanations, you probably saved me alot of future scripting time, and forum topics 😛 . but seriously thanks for the help, you've been the best arma scripting support dudes i've ever seen 🙂 . 2 Share this post Link to post Share on other sites
jshock 513 Posted May 28, 2019 41 minutes ago, CuddleTank001 said: condition parsing explanations Just to clarify, these parsing concepts apply in every usage of strings, not just conditions. I was just keeping my explanation focused specifically on this example. hint "My hint that still shows a ""string"""; //displays as: My hint that still shows a "string" 47 minutes ago, CuddleTank001 said: but seriously thanks for the help That's what the forums are for. I for one just like to tackle issues with people even if I'm not entirely sure how to approach it, especially in the cases where better/more experienced coders (cough, Dedmen ) come in and poke holes in my stuff, helps me learn too. Even though half the time I screw up is either because I'm sleep deprived or post without testing Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 28, 2019 actually hold on, i tried this script in multiplayer and it didn't work 😛 Share this post Link to post Share on other sites
jshock 513 Posted May 28, 2019 Where are you putting the addAction code? I recommend putting in the initPlayerLocal.sqf in your mission folder (if you don't have one already, make one). Share this post Link to post Share on other sites
CuddleTank001 3 Posted May 28, 2019 oh it may not be compatible with my whole script, so this is my script, it may look noobish but just bare with me. removeallactions player; start = { removeallactions player; player addAction ["<t color='#0000FF'>Begin</t>", foption]; }; foption = { removeallactions player; Player addAction ["<t color='#0000FF'>Spawn Vehicles</t>", soption ,[],-1,false,true,"",'currentWeapon player == "hgun_P07_snds_F"']; Player addAction ["<t color='#FF00FF'>Repair</t>",{vehicle player setDamage 0; vehicle player setFuel 1; vehicle player setVehicleAmmo 1;},nil,0,false,true,"","_this == _Target turretunit [0]",15, false]; Player addAction ["<t color='#FF00FF'>Repair Target</t>",{cursorTarget setDamage 0;cursorTarget setFuel 0;cursorTarget setVehicleAmmo 0;},[],-1,false,true,"",'currentWeapon player == "hgun_P07_snds_F"']; Player addAction ["<t color='#FFFF00'>ENG</t>",{vehicle player setHitPointDamage ["hitengine", 1]},nil,0,false,true,"","_this == _Target turretunit [0]",15, false]; Player addAction ["<t color='#FFFF00'>Rear Rotor</t>",{vehicle player setHitPointDamage ["hitvrotor", 1]},nil,0,false,true,"","_this == _Target turretunit [0]",15, false]; player addAction ["<t color='#FF0000'>DESTROY</t>", {cursorTarget setDamage 1;},[],-1,false,true,"",'currentWeapon player == "hgun_P07_snds_F"']; player addAction ["<t color='#FF0000'>DELETE</t>", {deleteVehicle cursorTarget;},[],-1,false,true,"",'currentWeapon player == "hgun_P07_snds_F"']; player addAction ["<t color='#00FF00'>Remove Earplugs</t>" , {1 fadeSound 1},0,1,false,false,"","(soundVolume < 1)"]; player addAction ["<t color='#00FF00'>Put Earplugs On</t>" , {1 fadeSound 0.15},0,1,false,false,"","(soundVolume == 1)"]; }; soption = { removeallactions player; player addAction ["<t color='#FF0000'>Pawnee</t>", {"B_Heli_Light_01_dynamicLoadout_F" createVehicle position player;}]; player addAction ["Humming Bird", {"B_Heli_Light_01_stripped_F" createVehicle position player;}]; player addAction ["Hellcat", {"I_Heli_light_03_unarmed_F" createVehicle position player;}]; player addAction ["Orca", {"O_Heli_Light_02_unarmed_F" createVehicle position player;}]; player addAction ["Taru", {"O_Heli_Transport_04_covered_F" createVehicle position player;}]; player addAction ["Armed Hellcat", {"I_Heli_light_03_dynamicLoadout_F" createVehicle position player;}]; player addAction ["Huron", {"B_Heli_Transport_03_unarmed_F" createVehicle position player;}]; player addAction ["Blackfish", {"B_T_VTOL_01_infantry_F" createVehicle position player;}]; player addAction ["Darter", {"B_UAV_01_F" createVehicle position player;}]; player addAction ["<t color='#0000FF'>Back</t>", foption]; }; call start; Share this post Link to post Share on other sites