wyattwic 38 Posted November 1, 2017 Hello guys! A while back I made a custom grenade script, but lately I've ran into a few issues mainly surrounding a few different revive systems and vehicles. My issue appeared to be centered around how we detect that the player wanted to toss a grenade. In my current implementation, we detect the keystroke, intercept it then do our magic. The issue is that the same keybind may be used in other applications where they wouldn't interfere normally. How would I detect that someone has actuated a specific action key, or is about to start throwing a grenade? So far, my best idea was to detect using the Fired EH, but that EH triggers after the throw animation. My goal is to stop that animation from happening, then run my own code. I'll keep experimenting, but input would be great! Share this post Link to post Share on other sites
wyattwic 38 Posted November 1, 2017 So, I need to refine my question after some more research - How do I detect when action "ThrowGrenade" is starting/in progress? How do I stop the action? Share this post Link to post Share on other sites
HazJ 1288 Posted November 1, 2017 Maybe this will help. This post here. Share this post Link to post Share on other sites
phronk 895 Posted November 1, 2017 This will detect when the player presses his "Throw" key: waitUntil{!(isNull(findDisplay 46))}; myKeyDownEH=(findDisplay 46)displayAddEventHandler["KeyDown","if(inputAction""Throw"">0)then{myCodeInHere;};"]; 4 Share this post Link to post Share on other sites
HazJ 1288 Posted November 1, 2017 That's a nice and simple way. One which I didn't even think of! :P Nice though. Share this post Link to post Share on other sites
wyattwic 38 Posted November 1, 2017 8 hours ago, phronk said: This will detect when the player presses his "Throw" key: waitUntil{!(isNull(findDisplay 46))}; myKeyDownEH=(findDisplay 46)displayAddEventHandler["KeyDown","if(inputAction""Throw"">0)then{myCodeInHere;};"]; Thank you!!! I completely forgot about inputaction. When I'm on lunch, test it out and let y'all know of the results! Share this post Link to post Share on other sites
wyattwic 38 Posted November 1, 2017 So, the problem persists. InputAction returns 1 if I am pusing the key associated. It doesn't fire when then the character is about to throw. Qualifying the above, it returns true if I am throwing a grenade, but also returns true if its pushed in a situation the action cant be completed. Do you all know of any way to determine if an action is possible? Maybe I could use that as a second qualifier for my script? EDIT: I dont think determining if an action is possible will work - Its picking up on switch grenade as well (Ctrl+G, or anything+G), so that isn't working out. Share this post Link to post Share on other sites
HazJ 1288 Posted November 1, 2017 You could use the above and count grenades? Share this post Link to post Share on other sites
wyattwic 38 Posted November 1, 2017 Its not so much if they have a grenade or not (I already am checking for that), its more that people are tossing nades when down/incapacitated or otherwise wouldn't be. My big issues is there are so many "otherwise shouldn't be" situation. Share this post Link to post Share on other sites
pierremgi 4739 Posted November 1, 2017 Perhaps, adding a condition with currentThrowable command? Share this post Link to post Share on other sites
wyattwic 38 Posted November 1, 2017 2 minutes ago, pierremgi said: Perhaps, adding a condition with currentThrowable command? I had no luck there, it still returns a throwable even if the player is not able to throw. Share this post Link to post Share on other sites
wyattwic 38 Posted November 1, 2017 So, more digging. At this point im convinced that I am after is engine based and I am not having a ton of luck. On the bright side, thanks to @phronk, I figured out inputaction is better for handling keydown type events. In the past if I was taking over something that required tracking an action bound to something weird, it make handling the DIK codes for it near impossible. Now I just watch inputaction and there we go! I'm giving up on this for now. Thanks for the help guys! Share this post Link to post Share on other sites
pierremgi 4739 Posted November 2, 2017 If this can help someone, player throwing grenade can be detected by: player addEventHandler ["FiredMan", { if (configname (inheritsFrom (configFile >> "cfgWeapons" >> "throw" >>(_this select 2) )) isEqualTo "ThrowMuzzle") then {hint "throwing grenade, chem, smoke"} }]; Note: works also from a vehicle. 2 2 Share this post Link to post Share on other sites
phronk 895 Posted November 2, 2017 I have no idea what script you're writing or what purpose you are looking to detect/stop throwning, but this code will instantly delete the player's thrown hand grenade: player addEventHandler["Fired",{if(_this select 2=="HandGrenadeMuzzle")then{deleteVehicle(_this select 6);};}]; Throwing of chemlights, smoke grenades, and IR strobes won't get deleted upon throwing them, unless those muzzle classnames are added. Although if you want to also delete those too, then pierremgi's code method is probably better. Share this post Link to post Share on other sites
wyattwic 38 Posted November 2, 2017 Thanks @pierremgi and @phronk. The goal of my script is to allow the player to pull the pin on their grenade and carry (or cook). It works in its current implementation by detecting the grenade DIK code on key down. Here is my issue - Outside of my script, the engine is very restrictive as to when you can activate a grenade, and permissive in unusual situations. Something I haven't been able to mimic accurately in my code. The goal of my post was to see if anyone knew of a way to detect when the engine was about to have a grenade throw happen, then intercept and run my own code. The issue with all of the implementations I have tried so far, is they fire after the throw animation or they return true when in actuality you wouldn't be able to throw something. Share this post Link to post Share on other sites
Tajin 348 Posted November 2, 2017 What about using the "AnimChanged" EH ? Aside from that, I am pretty sure you can completely disable default grenade usage, by simply removing the "THROW" weapon. Then you can just replace it with your scripted behaviour. Share this post Link to post Share on other sites
pognivet 150 Posted August 23, 2019 On 11/1/2017 at 6:34 PM, pierremgi said: If this can help someone, player throwing grenade can be detected by: player addEventHandler ["FiredMan", { if (configname (inheritsFrom (configFile >> "cfgWeapons" >> "throw" >>(_this select 2) )) isEqualTo "ThrowMuzzle") then {hint "throwing grenade, chem, smoke"} }]; Note: works also from a vehicle. it can help me. :D thanks. Share this post Link to post Share on other sites