Jump to content

Help to fix a bug


Strike27208

Recommended Posts

Posted

Hello everyone i make a digital speedometer and i put a event "onClientVehicleEnter" but this event take every player which enter in my vehicle and the animation is restarted i used "InterpolateBetween" so please help to fix this bug. I tried every posibility :

1.

addEventHandler("onClientVehicleEnter",getLocalPlayer (),StartFunc) 

-----------------------------------------------------------------------------------

2.

local theVehicle = getPedOccupiedVehicle ( localPlayer ) 
   if (theVehicle) then  
 start = getTickCount() 
addEventHandler ("onClientRender", root, GetSpeed ) 

And more.

This is my code :

  
local x, y = guiGetScreenSize() 
local sW, sH =  (x/1366), (y/768) 
    function GetSpeed () 
    local theVehicle = getPedOccupiedVehicle ( localPlayer ) 
    if (theVehicle) then 
    local Vname = getVehicleName(getPedOccupiedVehicle(localPlayer)) 
    local sxs, sys, szs = getElementVelocity (getPedOccupiedVehicle(localPlayer)) 
    local speed = math.floor(((sxs^2 + sys^2 + szs^2)^(0.5))*180) 
    local vehiclespeed = speed 
     
    -------------------Animation----------------- 
    x,y = guiGetScreenSize() 
  
    ancho=550 
    alto=20 
  
    local now = getTickCount() 
    local elapsedTime = now - start 
    local endTime = start + 5000 
    local duration = endTime - start 
    local progress = elapsedTime / duration 
    local x1, y1, z1 = interpolateBetween ( 0, 0, 0, ancho, alto, 255, progress, "OutBounce") 
    local x2, y2, z2 = interpolateBetween ( 0, 0, 0, ancho, alto, alto/11, progress, 'OutBounce') 
  
    posx = (x/2)-(x1/2) 
    posy = (y/2)-(y1/2) 
     
        dxDrawText(""..tostring(speed).." KM/H",posx, posy-y2/2, x2, y2, tocolor(255,255,255,255), 1.5, "default-bold", "left", "center", false, false, true, false, false) 
        Carname1 = dxDrawRectangle ( 1228*sW,698*sH, 125*sW, 20*sH, tocolor(0 ,255 ,0,160) ,false) 
        dxDrawText(""..Vname,sW*2560, sH*1396, sW*20, sH*20,tocolor(255,255,255, 255),1.30,"default-bold","center","center",false,false,false) 
end 
end 
-----StartFunction------ 
function StartFunc() 
start = getTickCount() 
addEventHandler("onClientRender", root, GetSpeed ) 
end 
addEventHandler("onClientVehicleEnter",getLocalPlayer (),StartFunc) 
  
-------StopFunction-------- 
function StopFunc () 
removeEventHandler("onClientRender", getRootElement(), StartFunc)  
end 
addEventHandler("onClientVehicleExit", getRootElement(),StopFunc) 
  

Posted

Maybe it's resets when they EXIT?

addEventHandler("onClientVehicleExit", getRootElement(),StopFunc) 

addEventHandler("onClientVehicleExit", getLocalPlayer(),StopFunc) 

Posted
Maybe it's resets when they EXIT?
addEventHandler("onClientVehicleExit", getRootElement(),StopFunc) 

addEventHandler("onClientVehicleExit", getLocalPlayer(),StopFunc) 

I i forgot to say this not work

  
addEventHandler("onClientVehicleEnter",getLocalPlayer()),StartFunc) 
  

If i put this the function not work

But thanks for help.

Posted

Use getRootElement() and check if the player is the localPlayer. onClientVehicleEnter/Exit will trigger for EVERY player whoever enters or exists a vehicle in the server.

Posted
Use getRootElement() and check if the player is the localPlayer. onClientVehicleEnter/Exit will trigger for EVERY player whoever enters or exists a vehicle in the server.

You want to make this ?

addEventHandler("onClientVehicleExit", getRootElement(localPlayer),StopFunc) 

If you want to make this i tried already .

Posted

Just do a constant onClientRender

  
veh = nil 
if getElementData(getLocalPlayer(), "state") == "alive" then 
    if isElement(getCameraTarget(getLocalPlayer())) and getElementType(getCameraTarget(getLocalPlayer())) == "vehicle" then 
    veh = getCameraTarget(getLocalPlayer()) 
    end 
elseif getElementData(getLocalPlayer(), "state") == "dead" then 
    if isElement(getCameraTarget(getLocalPlayer())) and getElementType(getCameraTarget(getLocalPlayer())) == "vehicle" then 
    veh = getCameraTarget(getLocalPlayer()) 
    end 
elseif getElementData(getLocalPlayer(), "state") == "waiting" then 
    if getCameraTarget(getLocalPlayer()) then 
    if isElement(getCameraTarget(getLocalPlayer())) and getElementType(getCameraTarget(getLocalPlayer())) == "vehicle" then 
    veh = getCameraTarget(getLocalPlayer()) 
    end 
    end 
end 
-- OVERRIDE SPECTATING WHILE ALIVE 
    if getCameraTarget(getLocalPlayer()) then 
    if getElementType(getCameraTarget(getLocalPlayer())) == "vehicle" then 
    veh = getCameraTarget(getLocalPlayer()) 
    end 
    end 
if not veh then return end 

Posted
Just do a constant onClientRender
  
veh = nil 
if getElementData(getLocalPlayer(), "state") == "alive" then 
    if isElement(getCameraTarget(getLocalPlayer())) and getElementType(getCameraTarget(getLocalPlayer())) == "vehicle" then 
    veh = getCameraTarget(getLocalPlayer()) 
    end 
elseif getElementData(getLocalPlayer(), "state") == "dead" then 
    if isElement(getCameraTarget(getLocalPlayer())) and getElementType(getCameraTarget(getLocalPlayer())) == "vehicle" then 
    veh = getCameraTarget(getLocalPlayer()) 
    end 
elseif getElementData(getLocalPlayer(), "state") == "waiting" then 
    if getCameraTarget(getLocalPlayer()) then 
    if isElement(getCameraTarget(getLocalPlayer())) and getElementType(getCameraTarget(getLocalPlayer())) == "vehicle" then 
    veh = getCameraTarget(getLocalPlayer()) 
    end 
    end 
end 
-- OVERRIDE SPECTATING WHILE ALIVE 
    if getCameraTarget(getLocalPlayer()) then 
    if getElementType(getCameraTarget(getLocalPlayer())) == "vehicle" then 
    veh = getCameraTarget(getLocalPlayer()) 
    end 
    end 
if not veh then return end 

Thanks i will try.

Posted
Use getRootElement() and check if the player is the localPlayer. onClientVehicleEnter/Exit will trigger for EVERY player whoever enters or exists a vehicle in the server.

You want to make this ?

addEventHandler("onClientVehicleExit", getRootElement(localPlayer),StopFunc) 

If you want to make this i tried already .

function stopFunc(tPlayer) 
    if (tPlayer == localPlayer) then 
        --Stuff 
    end 
end 
  
addEventHandler("onClientVehicleExit", getRootElement(), stopFunc) 

Posted
Use getRootElement() and check if the player is the localPlayer. onClientVehicleEnter/Exit will trigger for EVERY player whoever enters or exists a vehicle in the server.

You want to make this ?

addEventHandler("onClientVehicleExit", getRootElement(localPlayer),StopFunc) 

If you want to make this i tried already .

function stopFunc(tPlayer) 
    if (tPlayer == localPlayer) then 
        --Stuff 
    end 
end 
  
addEventHandler("onClientVehicleExit", getRootElement(), stopFunc) 

Thanks man it's work :D I love you :P

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...