ClickGamingNZ 2 Posted September 21, 2018 Hello, To start off I'm new to scripting and just starting dabbling in it. I'm currently making a basic script as I'm learning and it's going around finding boxes and every time you find one it adds it to the total of found boxes. I've got my box script which is this: Quote while {true}do { waitUntil {((player distance box1) <=30);}; hint "Your nearing a box"; waitUntil {((player distance box1) >35);}; hint "Your going away from a box"; }; I've got it repeating for all the boxes that I've got and I'm just not sure how to include a count when you interact with the box and I've had a google and just can't find anything. I'll also got the start to the counting script but it's not really much at this stage: Quote _boxesFound = 0; _boxesFound = _boxesFound + 1; I hope that someone knows how to solve this and I'm currently going through Fockers Arma Scripting PDF and KK's arma scripting blog. Share this post Link to post Share on other sites
Larrow 2799 Posted September 22, 2018 What are the boxes? How do you interact? Standard open-able crate? box1 addEventHandler [ "ContainerOpened", { params[ "_container", "_unit" ]; hint format[ "%1 opened %2", name _unit, getText( configFile >> "CfgVehicles" >> typeOf _container >> "displayName" ) ]; }]; Share this post Link to post Share on other sites
gokitty1199 225 Posted September 22, 2018 if im understanding you right then this may be what you want it adds an addaction to the player that only shows up if the player is looking at a box, if he looks away or gets further away than 4 meters the the option disappear until the player goes back and looks at it. when the player clicks Found Box, it tallys up 1 box found for that player and no other player on the server can get the option to find that box boxesFound = 0; box1 setVariable ["isFound", false, true]; box2 setVariable ["isFound", false, true]; //do more of these for each box player addAction ["Found Box", { cursorTarget setVariable ["isFound", true, true]; boxesFound = boxesFound + 1; }, [], 6, true, true, "", "cursorTarget getVariable ['isFound', nil] isEqualTo false AND player distance cursorTarget < 4"]; result from clicking on 2 boxes(it sucks trying to make a gif with gyazo -_-) https://gyazo.com/3908068544e5239e0467dd41ecafae05 https://gyazo.com/49d73c9644a30874991b74e74407a960 1 Share this post Link to post Share on other sites
ClickGamingNZ 2 Posted September 22, 2018 thanks those work well but I'm going to have to go with gokitty1199. Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted September 22, 2018 2 hours ago, gokitty1199 said: if im understanding you right then this may be what you want it adds an addaction to the player that only shows up if the player is looking at a box, if he looks away or gets further away than 4 meters the the option disappear until the player goes back and looks at it. when the player clicks Found Box, it tallys up 1 box found for that player and no other player on the server can get the option to find that box boxesFound = 0; box1 setVariable ["isFound", false, true]; box2 setVariable ["isFound", false, true]; //do more of these for each box player addAction ["Found Box", { cursorTarget setVariable ["isFound", true, true]; boxesFound = boxesFound + 1; }, [], 6, true, true, "", "cursorTarget getVariable ['isFound', nil] isEqualTo false AND player distance cursorTarget < 4"]; result from clicking on 2 boxes(it sucks trying to make a gif with gyazo -_-) https://gyazo.com/3908068544e5239e0467dd41ecafae05 https://gyazo.com/49d73c9644a30874991b74e74407a960 No need to individually set variables if you simply want to return a default value: cursorTarget getVariable ['isFound', nil] isEqualTo false This will not work since you can't compare nil to bool However when first setting the following: box1 setVariable ["isFound", false, true]; will make the isEqualTo false check unnecessary and most likely confusing when you can simply check for this: cursorTarget getVariable ['isFound', false] isEqualTo false Again, no need to set any variable when you can simply check for a default value. You can also remove the distance check in the addAction condition and handle it from the addAction radius parameter #10. On top of that it always pays off to save variables on objects, in this case the player (boxesFound), so you'll have an easier time porting this to MP if needed. Depending on how you want to detect the interaction you can do this with addAction or, as @Larrow suggested, via ContainerOpened EH. Cheers Share this post Link to post Share on other sites
gokitty1199 225 Posted September 22, 2018 1 hour ago, Grumpy Old Man said: No need to individually set variables if you simply want to return a default value: cursorTarget getVariable ['isFound', nil] isEqualTo false This will not work since you can't compare nil to bool However when first setting the following: box1 setVariable ["isFound", false, true]; will make the isEqualTo false check unnecessary and most likely confusing when you can simply check for this: cursorTarget getVariable ['isFound', false] isEqualTo false Again, no need to set any variable when you can simply check for a default value. You can also remove the distance check in the addAction condition and handle it from the addAction radius parameter #10. On top of that it always pays off to save variables on objects, in this case the player (boxesFound), so you'll have an easier time porting this to MP if needed. Depending on how you want to detect the interaction you can do this with addAction or, as @Larrow suggested, via ContainerOpened EH. Cheers that i didnt think about, nice response 1 Share this post Link to post Share on other sites
ClickGamingNZ 2 Posted September 22, 2018 Ok I'm just trying to put my head around what @Grumpy Old Man said in regards to @gokitty1199 wrote and I'm trying to put those recommended changes into code as I've not delved into the depths of addAction commands with putting a radius on them and haven't even looked at the MP side of scripting yet. 1 Share this post Link to post Share on other sites
gokitty1199 225 Posted September 22, 2018 13 hours ago, ClickGamingNZ said: Ok I'm just trying to put my head around what @Grumpy Old Man said in regards to @gokitty1199 wrote and I'm trying to put those recommended changes into code as I've not delved into the depths of addAction commands with putting a radius on them and haven't even looked at the MP side of scripting yet. i think he means something along the lines of box1 setVariable ["isFound", false, true]; box2 setVariable ["isFound", false, true]; //do more of these for each box player addAction ["Found Box", { cursorTarget setVariable ["isFound", true, true]; boxesFound = boxesFound + 1; }, [], 6, true, true, "", "cursorTarget getVariable ['isFound', nil] isEqualTo false AND player distance cursorTarget < 4"]; //cursorTarget getVariable ['isFound', nil] isEqualTo false this line should not get the default value of nil. i didnt think to much of it but with getVariable you have a default value(in this case its set to nil), and its going by the cursor target(whats in your cursor). so its reading whats in your cursor, getting the variable isFound, if the object does not have the variable isFound then it returns the default value(in this case nil) for comparison. hopefully @Grumpy Old Man will correct and explain the comment in the script above better so it makes more sense to you Share this post Link to post Share on other sites
Larrow 2799 Posted September 23, 2018 //initPlayerLocal.sqf { _x addAction ["Found Box", { params[ "_target", "_caller", "_ID", "_args" ]; //Set this examined box as found, so the action on it is no longer active //Also PV to all clients so their action for this box is no longer active _target setVariable ["isFound", true, true]; //Get the number of boxes found, default 0 _currentFoundBoxes = _caller getVariable[ "boxesFound", 0 ]; //Increase count by 1 _currentFoundBoxes = _currentFoundBoxes + 1; //Update callers variable _caller setVariable [ "boxesFound", _currentFoundBoxes ]; //Maybe do something when # boxes have been found if ( _currentFoundBoxes isEqualTo 4 ) then { //Do something }; }, [], 6, true, true, "", //_target (unit to which action is attached to) and _this (caller/executing unit) "!( _target getVariable [ 'isFound', false ] )", //NOT found ( default false ) !false == true 4 //distance for action ]; }forEach [ box1, box2, box3, box4 ]; //Boxes that require found action 4 Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted September 23, 2018 5 hours ago, gokitty1199 said: hopefully @Grumpy Old Man will correct and explain the comment in the script above better so it makes more sense to you Basically what glorious @Larrow posted. Also good practice to keep things simple, like his suggestion of changing notFound to isFound to prevent double negatives from confusing you when debugging. These things tend to be hard to follow through and to get a grasp at first glance: //bad notDoSomething = true; if (!notDoSomething) then { //do something }; //good doSomething = false; if (doSomething) then { //do something }; Cheers 4 Share this post Link to post Share on other sites
ClickGamingNZ 2 Posted September 23, 2018 Cool, thank you @Larrow for helping refining the code and making it easy to understand and get my head around along with @Grumpy Old Man for also helping me understand it and having a good format when creating code. Along with @gokitty1199 that put their ideas forward. 1 Share this post Link to post Share on other sites