Jump to content

[HELP]dx Problem


stevensalvaro

Recommended Posts

Hello,

I just have this script , but why if i enter the vehicle all player on my server can see this HUD ? How can i change this ?

  
THIS_RESOURCE = getThisResource(); 
ROOT_ELEMENT = getRootElement(); 
fuellessVehicle = { [594]=true, [537]=true, [538]=true, [569]=true, [590]=true, [606]=true, [607]=true, [610]=true, [590]=true, [569]=true, [611]=true, [584]=true, [608]=true, [435]=true, [450]=true, [591]=true, [472]=true, [473]=true, [493]=true, [595]=true, [484]=true, [430]=true, [453]=true, [452]=true, [446]=true, [454]=true, [497]=true, [592]=true, [577]=true, [511]=true, [548]=true, [512]=true, [593]=true, [425]=true, [520]=true, [417]=true, [487]=true, [553]=true, [488]=true, [563]=true, [476]=true, [447]=true, [519]=true, [460]=true, [469]=true, [513]=true, [509]=true, [510]=true, [481]=true } 
local fuel = 0 
  
  
GUI = { 
    button1 = false , 
    button2 = false , 
    button3 = false , 
    button4 = false , 
    button5 = false , 
    button6 = false  
}; 
local sx,sy = guiGetScreenSize() 
local px,py = 1366,768 
local x,y =  (sx/px), (sy/py)  
OnResourceStart = function(resource) 
    if resource == THIS_RESOURCE then        
        GUI.button1 =  guiCreateStaticImage( x*300, y*680, 64, 64, "images/engine.png", false ) 
        GUI.button2 =  guiCreateStaticImage( x*420, y*680, 64, 64, "images/lamp.png", false ) 
        GUI.button3 =  guiCreateStaticImage( x*540, y*680, 64, 64, "images/lock.png", false ) 
        GUI.button4 =  guiCreateStaticImage( x*660, y*680, 64, 64, "images/brake.png", false ) 
        GUI.button5 =  guiCreateStaticImage( x*780, y*680, 64, 64, "images/belt.png", false ) 
        GUI.button6 =  guiCreateStaticImage( x*900, y*680, 64, 64, "images/window.png", false ) 
        guiSetVisible(GUI.button1, false); 
        guiSetVisible(GUI.button2, false); 
        guiSetVisible(GUI.button3, false); 
        guiSetVisible(GUI.button4, false); 
        guiSetVisible(GUI.button5, false); 
        guiSetVisible(GUI.button6, false); 
    end 
    return; 
end 
  
  
OnResourceStop = function(resource) 
    if resource == THIS_RESOURCE then 
        if GUI.button1 ~= false then 
            destroyElement(GUI.button1); 
        end 
        if GUI.button2 ~= false then 
            destroyElement(GUI.button2); 
        end 
        if GUI.button3 ~= false then 
            destroyElement(GUI.button3); 
        end 
        if GUI.button4 ~= false then 
            destroyElement(GUI.button4); 
        end 
        if GUI.button5 ~= false then 
            destroyElement(GUI.button5); 
        end 
        if GUI.button6 ~= false then 
            destroyElement(GUI.button6); 
        end 
    end 
    return; 
end 
  
OnVehicleEnter = function(player, seat, jacked) 
    -- source = vehicle_element 
    if GUI.button1 ~= false then 
        guiSetVisible(GUI.button1, true); 
    end 
    if GUI.button2 ~= false then 
        guiSetVisible(GUI.button2, true); 
    end 
    if GUI.button3 ~= false then 
        guiSetVisible(GUI.button3, true); 
    end 
    if GUI.button4 ~= false then 
        guiSetVisible(GUI.button4, true); 
    end 
    if GUI.button5 ~= false then 
        guiSetVisible(GUI.button5, true); 
    end 
    if GUI.button6 ~= false then 
        guiSetVisible(GUI.button6, true); 
    end 
    return; 
end 
  
OnVehicleExit = function(player, seat, jacked) 
    -- source = vehicle_element 
    if GUI.button1 ~= false then 
        guiSetVisible(GUI.button1, false); 
    end 
    if GUI.button2 ~= false then 
        guiSetVisible(GUI.button2, false); 
    end 
    if GUI.button3 ~= false then 
        guiSetVisible(GUI.button3, false); 
    end 
    if GUI.button4 ~= false then 
        guiSetVisible(GUI.button4, false); 
    end 
    if GUI.button5 ~= false then 
        guiSetVisible(GUI.button5, false); 
    end 
    if GUI.button6 ~= false then 
        guiSetVisible(GUI.button6, false); 
    end 
    return; 
end 
  
OnGUIClick = function(button1, state, x, y) 
    -- source = gui 
    if state then 
        if source == GUI.button1 and guiGetVisible(GUI.button1) == true then 
            triggerServerEvent("toggleEngine", localPlayer, localPlayer) 
        end 
        if source == GUI.button2 and guiGetVisible(GUI.button2) == true then 
            triggerServerEvent("toggleLights", localPlayer, localPlayer) 
        end 
        if source == GUI.button3 and guiGetVisible(GUI.button3) == true then 
            triggerServerEvent("toggleLock", localPlayer, localPlayer) 
        end 
        if source == GUI.button4 and guiGetVisible(GUI.button4) == true then 
            triggerServerEvent("toggleHandbrake", localPlayer, localPlayer) 
        end 
        if source == GUI.button5 and guiGetVisible(GUI.button5) == true then 
            triggerServerEvent("toggleBelt", localPlayer, localPlayer) 
        end 
        if source == GUI.button6 and guiGetVisible(GUI.button6) == true then 
            triggerServerEvent("toggleWindow", localPlayer, localPlayer) 
        end 
    end 
    return; 
end 
addEventHandler("onClientResourceStart",    ROOT_ELEMENT,   OnResourceStart ); 
addEventHandler("onClientResourceStop",    ROOT_ELEMENT,   OnResourceStop      ); 
addEventHandler("onClientVehicleEnter",    ROOT_ELEMENT,   OnVehicleEnter      ); 
addEventHandler("onClientVehicleExit",      ROOT_ELEMENT,   OnVehicleExit       ); 
addEventHandler("onClientGUIClick",      ROOT_ELEMENT,   OnGUIClick          ); 
  
  
--Speedometer & Odometer 
function setUp(startedResource) 
    if(startedResource == getThisResource()) then 
        oX,oY,oZ = getElementPosition(getLocalPlayer()) 
        distanceTraveled = 0 
    end 
end 
addEventHandler("onClientResourceStart",getRootElement(),setUp) 
  
function monitoring() 
    if(isPlayerInVehicle(getLocalPlayer())) then 
        vehicle = getPlayerOccupiedVehicle(getLocalPlayer()) 
        x,y,z = getElementPosition(getLocalPlayer()) 
        distanceTraveled = distanceTraveled + getDistanceBetweenPoints3D(x,y,z,oX,oY,oZ) 
        oX = x 
        oY = y 
        oZ = z 
    end 
end 
addEventHandler("onClientRender",getRootElement(),monitoring) 
  
function getDistanceTraveled() 
    return distanceTraveled 
end 
  
  
             
local sx,sy = guiGetScreenSize() 
local px,py = 1366,768 
local x,y =  (sx/px), (sy/py)  
function Vel() 
local vehicle = getPedOccupiedVehicle( getLocalPlayer() ) 
    if ( vehicle ) then 
        local odometer = math.floor(getDistanceTraveled(vehicle)/1000) 
        local speedX, speedY, speedZ = getElementVelocity ( vehicle  ) 
        local actualSpeed = (speedX^2 + speedY^2 + speedZ^2)^(0.5) 
        speed = exports.global:getVehicleVelocity(vehicle) 
        local KMH = math.floor(actualSpeed*180)  
            if ( getElementHealth( vehicle ) >= 1000 ) then 
            vehsaude = 100 
            else 
            vehsaude = math.floor(getElementHealth ( vehicle )/10) 
    end 
        dxDrawRectangle(x*1134, y*710, x*222, y*32, tocolor(0, 0, 0, 200), false) 
        dxDrawRectangle(x*1140, y*715, x*211, y*20, tocolor(0, 42, 170, 230), false) 
    if KMH < 250 then 
        dxDrawRectangle(x*1140, y*716, x*211/250*KMH, y*19, tocolor(0, 255, 0, 230), false) 
    else 
        dxDrawRectangle(x*1140, y*716, x*211, y*19, tocolor(0, 175, 240, 230), false) 
    end 
        dxDrawText(KMH.." KM/h", x*1140 - 1, y*715 - 1, x*1351 - 1, y*735 - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
        dxDrawText(KMH.." KM/h", x*1140 + 1, y*715 - 1, x*1351 + 1, y*735 - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
        dxDrawText(KMH.." KM/h", x*1140 - 1, y*715 + 1, x*1351 - 1, y*735 + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
        dxDrawText(KMH.." KM/h", x*1140 + 1, y*715 + 1, x*1351 + 1, y*735 + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
        dxDrawText(KMH.." KM/h", x*1140, y*715, x*1351, y*735, tocolor(254, 254, 254, 227), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
        dxDrawRectangle(x*1134, y*674, x*222, y*32, tocolor(0, 0, 0, 200), false) 
        dxDrawRectangle(x*1140, y*680, x*211, y*19, tocolor(255, 0, 0, 227), false) 
        dxDrawRectangle(x*1134, y*638, x*222, y*32, tocolor(0, 0, 0, 200), false) 
        dxDrawRectangle(x*1140, y*644, x*211, y*19, tocolor(40, 255, 0, 200), false) 
        dxDrawImage(x*1063, y*680, x*60, y*50, "images/hudspeedo.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) 
        dxDrawText("Odometer: " ..odometer, x*1140 - 1, y*679 - 1, x*1351 - 1, y*699 - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
        dxDrawText("Odometer: " ..odometer , x*1140 + 1, y*679 - 1, x*1351 + 1, y*699 - 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
        dxDrawText("Odometer: " ..odometer, x*1140 - 1, y*679 + 1, x*1351 - 1, y*699 + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
        dxDrawText("Odometer: " ..odometer, x*1140 + 1, y*679 + 1, x*1351 + 1, y*699 + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
        dxDrawText("Odometer: " ..odometer, x*1140, y*679, x*1351, y*699, tocolor(254, 254, 254, 227), 1.00, "default-bold", "center", "center", false, false, false, false, false) 
    end 
end 
addEventHandler("onClientRender", root, Vel) 
-- END of Speedometer & Odometer -- 
  
  
  

Link to comment

Yeah I forgot to mention that my example would do that.

Fixed:

THIS_RESOURCE = getThisResource(); 
ROOT_ELEMENT = getRootElement(); 
LOCAL_PLAYER = getLocalPlayer(); 
  
GUI = { 
    -- BUTTONS 
    button = false 
}; 
  
OnResourceStart = function(resource) 
    if resource == THIS_RESOURCE then 
        GUI.button = guiCreateButton(0.40, 0.75, 0.20, 0.10, "CLICK ME", true, nil); -- x_position, y_position, width, height, text, relative, parent 
        
        guiSetVisible(GUI.button, false); 
    end 
    return; 
end 
  
OnResourceStop = function(resource) 
    if resource == THIS_RESOURCE then 
        if GUI.button ~= false then 
            destroyElement(GUI.button); 
        end 
    end 
    return; 
end 
  
OnVehicleEnter = function(player, seat, jacked) 
    -- source = vehicle_element 
    if player == LOCAL_PLAYER then 
        if GUI.button ~= false then 
            guiSetVisible(GUI.button, true); 
        end 
    end 
    return; 
end 
  
OnVehicleExit = function(player, seat, jacked) 
    -- source = vehicle_element 
    if player == LOCAL_PLAYER then 
        if GUI.button ~= false then 
            guiSetVisible(GUI.button, false); 
        end 
    end 
    return; 
end 
  
OnGUIClick = function(button, state, x, y) 
    -- source = gui 
    if state == "up" then 
        if source == GUI.button and guiGetVisible(GUI.button) == true then 
            outputChatBox("You've clicked me!"); 
        end 
    end 
    return; 
end 
  
addEventHandler("onClientResourceStart",    ROOT_ELEMENT,   OnResourceStart ); 
addEventHandler("onClientResourceStop",     ROOT_ELEMENT,   OnResourceStop  ); 
addEventHandler("onClientVehicleEnter",     ROOT_ELEMENT,   OnVehicleEnter  ); 
addEventHandler("onClientVehicleExit",      ROOT_ELEMENT,   OnVehicleExit   ); 
addEventHandler("onClientGUIClick",         ROOT_ELEMENT,   OnGUIClick      ); 

If you have any more problems or concerns, you can always contact me by Private Messaging me and I will fulfill any problem or question you may have. :)

Link to comment

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