spaghettikiller Posted December 10, 2017 Share Posted December 10, 2017 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. Link to comment
Dimos7 Posted December 10, 2017 Share Posted December 10, 2017 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 Link to comment
Fist Posted December 10, 2017 Share Posted December 10, 2017 (edited) change eventhandler from "onClientResourceStart" to "onClientRender" Edited December 10, 2017 by Fist Link to comment
DiGiTal Posted December 10, 2017 Share Posted December 10, 2017 Why he should use onclient render ? As i see in the wiki its only for drawing things ? Thanks @Fist Link to comment
Fist Posted December 10, 2017 Share Posted December 10, 2017 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. Link to comment
spaghettikiller Posted December 10, 2017 Author Share Posted December 10, 2017 @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> Link to comment
Fist Posted December 10, 2017 Share Posted December 10, 2017 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) Link to comment
spaghettikiller Posted December 11, 2017 Author Share Posted December 11, 2017 still doesn't work Link to comment
Fist Posted December 11, 2017 Share Posted December 11, 2017 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? Link to comment
spaghettikiller Posted December 11, 2017 Author Share Posted December 11, 2017 Yes, now it works! thank you for help. Link to comment
spaghettikiller Posted December 11, 2017 Author Share Posted December 11, 2017 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) 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