Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/03/22 in all areas

  1. @Burak5312There is no issue to solve, the original code is working and has no perf problems. Also your code won't work, you forgot to flip the boolean inside show and hide functions. @CronossYour code is fine. And you are right, technically it's better because "onClientRender" won't call your lua function for nothing (if the speedometer is hidden). local isSpeedoVisible = false function drawSpeedometer() if not isSpeedoVisible then return end -- cancel immediatly -- drawing end addEventHandler("onClientRender", root, drawSpeedometer) ------ function A1(player) if player == localPlayer then return end -- you forgot this btw or else other players will trigger it too vehicle = getPedOccupiedVehicle(player) if getPedOccupiedVehicleSeat(player) == 0 or getPedOccupiedVehicleSeat(player) == 1 then isSpeedoVisible = true end end addEventHandler("onClientVehicleEnter", root, A1) function A2(player) if player == localPlayer then return end -- you forgot this btw or else other players will trigger it too isSpeedoVisible = false end addEventHandler("onClientVehicleStartExit", root, A2) If you had something like this, it is fine too and the perf are so close that the difference can be ignored (but technically it's better to add and remove the event handler like in your original post). If you are having perf issues with your speedometer, make sure you don't call get/set ElementData inside the drawing function. Those methods are expensive.
    1 point
  2. actually you can solve this with a single variable instead of using "isEventHandlerAdded" Since there are more operations in the isEventHandlerAdded function, you can do it economically with a single variable. local isSpeedoMeterVisible = false --speedometer visibility status function hideSpeedometer() if(isSpeedoMeterVisible) then -- Is the speedometer visible? removeEventHandler("onClientRender", root, speedoMeterGUI) end end function showSpeedometer() if(isSpeedoMeterVisible == false) then -- Is the speedometer invisible? addEventHandler("onClientRender", root, speedoMeterGUI) end end ---------------------------------------------- function A1(player) vehicle = getPedOccupiedVehicle(player) if getPedOccupiedVehicleSeat(player)==0 or getPedOccupiedVehicleSeat(player)==1 then showSpeedometer() -------call to create the handler end end addEventHandler("onClientVehicleEnter", root, A1) function A2() hideSpeedometer() -----call to remove the handler end addEventHandler("onClientVehicleStartExit", root, A2)
    1 point
×
×
  • Create New...