vapour 12 Posted December 19, 2016 Hi folks I've got an issue with trying to write a script that lets me keep doing an action until the point where I don't want to do the action any longer. A player has a camera in their gear. When they want to take a photo, the script fires up. The script makes them put away their current weapon, and an image of the back of a camera pops up on their screen. picture sharing Now the bit that has me stumped. I want to be able to have the player take as many photos as they want before putting the camera away. The script snippet I have for 'clicking' the camera is this: Quote waitUntil {inputAction "Fire" > 0}; CameraUnit Say3D "Shutter"; (I intend to add some other stuff in here too that will detect what the player is pointing the camera towards at the time that the 'click'). (The inputAction "Fire" is done by the player holding Left-Ctrl + Left mouse click). This works a treat in my script, but sadly can only be done once at the moment due to my lack of scripting know-how. I then have another script snippet which lets the rest of the script continue, thus closing the camera and letting the player get his weapon out again: Quote waitUntil {inputAction "toggleRaiseWeapon" > 0}; (The inputAction "toggleRaiseWeapon" by default is a double tap of the Left-Ctrl key). The other problem here is that the player has to take a photo before the script continues on to the part where the player can put the camera away. What if the player opens the camera, but then decides to put it away without taking any shots. He/she can't in the script's current state. Here's the whole script currently: Quote CameraUnit action ["SwitchWeapon", CameraUnit, CameraUnit, 100]; Sleep 1; _pic = "pics\CameraBack_ca.paa"; [ '<img align=''centre'' size=''8.5'' shadow=''0'' image='+(str(_pic))+' />', safeZoneX+0.825, safeZoneY+safeZoneH-1.32, 99999, 0, 0, 3090 ] spawn bis_fnc_dynamicText; //I NEED HELP FROM HERE waitUntil {inputAction "Fire" > 0}; CameraUnit Say3D "Shutter"; waitUntil {inputAction "toggleRaiseWeapon" > 0}; //TO HERE _pic = ""; [ '<img align=''centre'' size=''0'' shadow=''0'' image='+(str(_pic))+' />', safeZoneX, safeZoneY+safeZoneH, 99999, 0, 0, 3090 ] spawn bis_fnc_dynamicText; CameraUnit action ["SwitchWeapon", CameraUnit, CameraUnit, 0]; So in summery, I want the player to be able to point and 'click' the camera as many times and at as many objects as they want, then when they're ready, put the camera away. I hope that all makes sense. Any help with this is appreciated. Thanks heaps. Vapour Share this post Link to post Share on other sites
dchan200 18 Posted December 19, 2016 35 minutes ago, vapour said: (The inputAction "Fire" is done by the player holding Left-Ctrl + Left mouse click). This works a treat in my script, but sadly can only be done once at the moment due to my lack of scripting know-how. I then have another script snippet which lets the rest of the script continue, thus closing the camera and letting the player get his weapon out again: Easy way would be to use a while-loop encompassing both conditions. 35 minutes ago, vapour said: The other problem here is that the player has to take a photo before the script continues on to the part where the player can put the camera away. What if the player opens the camera, but then decides to put it away without taking any shots. He/she can't in the script's current state. Should be able to deal with this. I think this should fix it: CameraUnit action ["SwitchWeapon", CameraUnit, CameraUnit, 100]; Sleep 1; _pic = "pics\CameraBack_ca.paa"; [ '<img align=''centre'' size=''8.5'' shadow=''0'' image='+(str(_pic))+' />', safeZoneX+0.825, safeZoneY+safeZoneH-1.32, 99999, 0, 0, 3090 ] spawn bis_fnc_dynamicText; //I NEED HELP FROM HERE _close_camera = false; while {!_close_camera} do { if (inputAction "Fire" > 0) then { CameraUnit Say3D "Shutter"; } else { if (inputAction "toggleRaiseWeapon" > 0) then { _close_camera = true; }; }; }; //TO HERE _pic = ""; [ '<img align=''centre'' size=''0'' shadow=''0'' image='+(str(_pic))+' />', safeZoneX, safeZoneY+safeZoneH, 99999, 0, 0, 3090 ] spawn bis_fnc_dynamicText; CameraUnit action ["SwitchWeapon", CameraUnit, CameraUnit, 0]; Never used inputAction so I'm not sure how it interacts with the if-statements, but give it a try. 1 Share this post Link to post Share on other sites
vapour 12 Posted December 19, 2016 Wow dchan200, thanks for the super fast reply! I just gave it a go, and it was almost perfect. The issue that occurs with your script is that the Camera Say3D "Shutter"; line keeps repeating after only one click of the camera, even after putting the camera away. The second part to put the camera away works great. Share this post Link to post Share on other sites
dchan200 18 Posted December 19, 2016 That's strange, but I think we are on the right track. I'll look into how Say3D and inputAction works. Since it that part keeps repeating after only one click of the camera, I have a feeling it's a buffer issue. Share this post Link to post Share on other sites
vapour 12 Posted December 19, 2016 Okay. Thanks heaps for your help with this so far. Share this post Link to post Share on other sites
vapour 12 Posted December 19, 2016 I added the line Hint "Photo taken"; after CameraUnit Say3D "Shutter"; and it successfully only fires the hint once each time you click the camera, so it definitely looks like Say3D is the issue. Share this post Link to post Share on other sites
vapour 12 Posted December 19, 2016 Hi dchan200, I just did an experiment with say, say2D and PlaySound. say, say2D and say3D all have the issue where the sound continues on an endless loop. playSound works properly, with just one shutter sound each time you click, but the sound is not as good quality. If you find a solve for the looping sound I would love to know, but if there isn't an answer to the issue, at least I can use playSound. Once again, thanks for solving the main issue for me. I really appreciate it. You made my day! Cheers Share this post Link to post Share on other sites
dchan200 18 Posted December 19, 2016 No problem and I will let you know if I can fix it. I should note that I did some quick testing myself using a counter and found the following: It depends on how long you hold the mouse button. Even if I clicked quickly, it always resulted in more than one click according to the counter. Since I assumed that it runs only once per click, the code needs to be modified with this in mind. Root cause points to inputAction and my assumption. Share this post Link to post Share on other sites
dchan200 18 Posted December 19, 2016 Sorry for the double post. But, could you try the following: //I NEED HELP FROM HERE _close_camera = false; while {!_close_camera} do { if (inputAction "Fire" > 0) then { CameraUnit Say3D "Shutter"; // Only count once per mouse-click waitUntil { inputAction "Fire" == 0; }; } else { if (inputAction "toggleRaiseWeapon" > 0) then { _close_camera = true; }; }; }; //TO HERE Added a waitUntil to make sure it only counts once per-click. Share this post Link to post Share on other sites
vapour 12 Posted December 19, 2016 BINGO! You're a genius. Worked absolutely perfectly. Thank you, thank you, thank you! Share this post Link to post Share on other sites