Drakath Posted February 4, 2014 Posted February 4, 2014 So, I'm making a Speedometer script and I keep getting this error: "addEventHandler: 'onClientRender' with this function is already handled" function speed ( ) addEventHandler ( "onClientRender", root, draw ) end addEventHandler ("onClientVehicleEnter", root, speed) function hideSpeed ( ) removeEventHandler ( "onClientRender", root, draw ) end addEventHandler("onClientVehicleExit", root, hideSpeed) function draw ( ) --this is where I have dxdraw stuff. end
TAPL Posted February 4, 2014 Posted February 4, 2014 function speed (player) if player == localPlayer then addEventHandler ( "onClientRender", root, draw ) end end addEventHandler ("onClientVehicleEnter", root, speed) function hideSpeed (player) if player == localPlayer then removeEventHandler ( "onClientRender", root, draw ) end end addEventHandler("onClientVehicleExit", root, hideSpeed) function draw ( ) --this is where I have dxdraw stuff. end
K4stic Posted February 4, 2014 Posted February 4, 2014 why can't do it easyer? :3 function draw() if ( isPedInVehicle ( localPlayer ) == false ) then return end --this is where I have dxdraw stuff. end addEventHandler ( "onClientRender", root, draw ) Giving a Fuck? Nope, That isn't in My Skill Set
Moderators IIYAMA Posted February 4, 2014 Moderators Posted February 4, 2014 why can't do it easyer? :3 function draw() if ( isPedInVehicle ( localPlayer ) == false ) then return end --this is where I have dxdraw stuff. end addEventHandler ( "onClientRender", root, draw ) Simply because it uses more memory. The easy way isn't always the best way. Even so, his version can get bugged, while yours can't. So the best result will be: onVehicleEnter + render check if he is in the vehicle else remove the handler. A combination would be the best. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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