Dzsozi (h03) Posted November 7, 2016 Share Posted November 7, 2016 Hey, I'm trying to make a simple script to prevent the only headshot "bug" when a player only holds the fire key and not aiming. I would like to make the player automatically aim when he holds the fire button, but I have some issues. When I release the fire button my character keeps aiming until I click the aim or fire button once manually. How can I make this script working or is there any other way for this that is more effective? Here's how I tried to do it: function fixCrosshairBugging() if getControlState("fire") and not getControlState("aim_weapon") then setControlState("aim_weapon", true) elseif not getControlState("fire") and not getControlState("aim_weapon") then setControlState("aim_weapon", false) end end addEventHandler("onClientRender", root, fixCrosshairBugging) So I would like to keep the default binds and etc., so I could aim the weapon manually as well, but I'd like the players to aim automaticall when they are only holding the fire key, and disable the aiming when they release it. Link to comment
LoPollo Posted November 7, 2016 Share Posted November 7, 2016 --Line 4 elseif not getControlState("fire") and not getControlState("aim_weapon") then --delete the not of aim_weap elseif not getControlState("fire") and getControlState("aim_weapon") then This will make you stop aiming when you stop fire... but there are still 2 problems: 1. this will also prevent you from aiming normally (e.g. clicking RMB) 2. this does not check for a keychange (e.g. while firing the rmb get pressed, after relasing lmb you will stop aiming even if the rb is pressed) So i think the best method would be checking the keys bound to the controls "fire" and "aim_weapon" and handle the press and relase of these keys. Link to comment
Dzsozi (h03) Posted November 7, 2016 Author Share Posted November 7, 2016 Alright, something came into my mind, I will try that, thank you! Link to comment
CamarGoD Posted July 30, 2019 Share Posted July 30, 2019 (edited) But we have a function, which created this in clientside instead of serverside, read the wiki. Use getPedControlState on the client side. Edited July 30, 2019 by CamarGoD Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now