Sign in to follow this  
Dzsozi (h03)

setControlState("aim_weapon") error

Recommended Posts

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.

Share this post


Link to post
--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.

Share this post


Link to post
Posted (edited)

But we have a function, which created this in clientside instead of serverside, read the wiki.;)

 

Use getPedControlState on the client side.

Edited by CamarGoD

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.