Jump to content

Problem with toggleControl


Recommended Posts

Posted

Hello, i want to make a script where player is able to shoot only when he's aiming, but shooting is disabled when he's not aiming.

Here's my code:

local localPlayer = getLocalPlayer()
function togglePlayerControl(weapon) 
	toggleControl("fire", false) 
	if isPedAiming(localPlayer) then
		toggleControl("fire", true) 
	end 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(), togglePlayerControl)

Now, player cannot shoot when he's not aiming, and that's good. But he cannot shoot when he's aiming too. How do i fix it? I'm not really good in scripting.

Posted

any error or warning in the /debugscript 3?  also you have use the code the wiki has you need have it for that working because its a useful function

Posted
11 minutes ago, DiGiTal said:

Why he should use onclient render ?  As i see in the wiki its only for drawing things  ?  Thanks

@Fist

It's not just for DirectX Drawing functions intended. It's also intended for instant response. For example, you can also use a timer, but minimum value that updates it each time is 50 miliseconds, of course, 50 miliseconds from instant response ain't much but timers also eat more performance which on other hand onClientRender event doesn't. Telling from experience.

Posted
12 minutes ago, spaghettikiller said:

@Fist still doesn't work, tried both client and server side. I wrote meta.xml properly i hope


<meta>
	<info version="1.0.0" type="script" name="toggle" />
	<script src="toggle.lua" type="client" />
</meta>

 

client:

function togglePlayerControl(weapon) 
	toggleControl("fire", false) 
	if isPedAiming(localPlayer) then
		toggleControl("fire", true) 
	end 
end 
addEventHandler ( "onClientRender", root, togglePlayerControl)

 

Posted
3 hours ago, spaghettikiller said:

still doesn't work

did you even paste function isPedAiming() from wiki in same script as you pasted that code what i wrote down?

Posted

There was a bug where player could still shoot when he pressed only mouse1 button. So i changed code a bit and now it's not happening.

function togglePlayerControl(weapon) 
	toggleControl("fire", false) 
	if getKeyState( "mouse1" ) == true and getKeyState( "mouse2" ) == true then
		toggleControl("fire", true) 
	end 
end 
addEventHandler ( "onClientRender", root, togglePlayerControl)

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...