Jump to content

[HELP] GUI


Recommended Posts

Hello,

I want to make my small Bind / Command Scripts all together in 1 GUI

My GUI:

GUIEditor = { 
    button = {}, 
    window = {}, 
    progressbar = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(280, 730, 718, 60, "Dashboard", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.button[1] = guiCreateButton(9, 25, 117, 25, "Lights", false, GUIEditor.window[1]) 
        GUIEditor.button[2] = guiCreateButton(136, 25, 117, 25, "Engine", false, GUIEditor.window[1]) 
        GUIEditor.progressbar[1] = guiCreateProgressBar(260, 26, 196, 24, false, GUIEditor.window[1]) 
        GUIEditor.button[3] = guiCreateButton(464, 25, 117, 25, "Lock", false, GUIEditor.window[1]) 
        GUIEditor.button[4] = guiCreateButton(591, 25, 117, 25, "Close", false, GUIEditor.window[1])     
    end 
) 

What I want to happen is:

1. Lights (The Car Lights turns on/off)

2. Engine (The Car Engine turns on/off)

3. Km/h (Speedometer: Not figured out yet!)

4. Lock (The Car Doors un/lock: Not figured out yet!)

5. Close (The GUI closes)

Always when I put the GUI + Meta in a folder and run it the GUI is always open and no button works.

yea I know why.

But I want to know how I can convert my Bind / Commanded Scripts to a Clickable GUI script

Engine Script

function SwitchEngine( playerSource ) 
    local theVehicle = getPedOccupiedVehicle ( playerSource ) 
    if theVehicle and getVehicleController ( theVehicle ) == playerSource then 
        local state = getVehicleEngineState ( theVehicle ) 
        setVehicleEngineState ( theVehicle, not state ) 
    end 
end 
  
function BindKeys ( player ) 
    if ( eventName == "onVehicleStartEnter" ) then 
        bindKey ( player,"x","down",SwitchEngine ) 
    else 
        unbindKey ( player,"x","down",SwitchEngine ) 
    end 
end 
addEventHandler ( "onVehicleStartEnter", root, BindKeys ) 
addEventHandler ( "onVehicleStartExit", root, BindKeys ) 

Lights Script

local root = getRootElement () 
local thisResourceRoot = getResourceRootElement(getThisResource()) 
  
function thisResourceStart () 
    local players = getElementsByType ( "player" ) 
    for k,v in ipairs(players) do 
        bindKey ( v, "l", "down", toggleVehicleLights ) 
    end 
end 
  
function playerJoin () 
    bindKey ( source, "l", "down", toggleVehicleLights ) 
end 
  
addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) 
addEventHandler ( "onPlayerJoin", root, playerJoin ) 
  
function toggleVehicleLights ( player, key, state ) 
    if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then 
        local veh = getPedOccupiedVehicle ( player ) 
        if ( getVehicleOverrideLights ( veh ) ~= 2 ) then 
            setVehicleOverrideLights ( veh, 2 ) 
        else 
            setVehicleOverrideLights ( veh, 1 ) 
        end 
    end 
end 
  

Thanks for Helping!

Link to comment

how about this?

When I press "m" while in a car then Cursor is being showed.

press "m" again and it's hidden.

Only while in a car available!

function showCursor(player) 
    showCursor(player, true) 
end 
  
bindKey(player, m, down) 
addEventHandler("onVehicleEnter", player) 
  
function hideCursor(player) 
    showCursor(player, false) 
end 
  
unbindKey(player, m, down) 
addEventHandler("onVehicleExit", player) 
  

Link to comment

-- # Client Side 
bindKey("M","down", 
        function (  ) 
            if isPedInVehicle ( getLocalPlayer (    ) ) then 
                showCursor ( not isCursorShowing (  )   ) 
            end 
        end 
    ) 

Make it more easy .

Link to comment

next Step: Cursor Click on Car the whole GUI opens!

Try this:

addEventHandler("onClientClick", root, 
function(_,_,_,_,_,_,_, clickedElement) 
    if clickedElement == getPedOccupiedVehicle(localPlayer) then 
        guiSetVisible(GUIEditor.window[1], true) 
    end 
end 
) 

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