Drakath Posted February 4, 2014 Share 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 Link to comment
TAPL Posted February 4, 2014 Share 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 Link to comment
K4stic Posted February 4, 2014 Share 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 ) Link to comment
Drakath Posted February 4, 2014 Author Share Posted February 4, 2014 TAPL's method worked. Thanks. Link to comment
Moderators IIYAMA Posted February 4, 2014 Moderators Share 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. 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