Jump to content

Gui Not Working


Lloyd Logan

Recommended Posts

Hey,

so i created a a script so that when you enter a marker the gui comes up and you can buy a veh! The problem is that the GUI is always there and nothing happens when you click "BUY" Thanks!

GUIEditor = { 
    button = {}, 
    label = {}, 
    window = {}, 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        Window = guiCreateWindow(385, 158, 478, 385, "Buy A Vehicle", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.label[1] = guiCreateLabel(26, 98, 326, 34, "Infernous : $30000", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[1], "sa-header") 
        GUIEditor.button[1] = guiCreateButton(373, 108, 86, 29, "BUY", false, GUIEditor.window[1])     
    end 
) 
  
  
 local buyVeh = createMarker(1940.5185546875, -1707.1162109375, 13.3828125, "cylinder", 1.5, 255, 255, 0, 170) 
  
function visibleGui(thePlayer) 
    guiSetVisible(Window, true) 
    showCursor ( true ) 
end 
addEventHandler("onMarkerHit", buyVeh, visibleGui) 
  
function onClickBtn ( button, state ) 
    if (source == GUIEditor.button[1]) then 
        local x, y, z = getElementPosition(thePlayer) 
        createVehicle(411, x + 2, y, z) 
        utputChatBox("You Have successfully bought an Infernous!", thePlayer) 
        takePlayerMoney ( thePlayer, 30000) 
    end 
end 

Link to comment
You forgot the event onClientGUIClick

So,

function onClickBtn ( button, state ) 
  
    if (source == GUIEditor.button[1]) then 
  
        local x, y, z = getElementPosition(thePlayer) 
  
        createVehicle(411, x + 2, y, z) 
  
        outputChatBox("You Have successfully bought an Infernous!", thePlayer) 
  
        takePlayerMoney ( thePlayer, 30000) 
  
    end 
  
end 

Is wrong :L I'm not too sure

Link to comment

Okay, i'll put aside everything apart from the GUI itself, how do make this appear when Marker is hit?

Clien:

GUIEditor = { 
    button = {}, 
    label = {}, 
    window = {}, 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        Window = guiCreateWindow(385, 158, 478, 385, "Buy A Vehicle", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.label[1] = guiCreateLabel(26, 98, 326, 34, "Infernous : $30000", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[1], "sa-header") 
        bBuy = guiCreateButton(373, 108, 86, 29, "BUY", false, GUIEditor.window[1])     
    end 
) 
  
local buyVeh = createMarker(1940.5185546875, -1707.1162109375, 13.3828125, "cylinder", 1.5, 255, 255, 0, 170) 
  
function showGUII() 
guiSetVisible(Window,true) 
showCursor(true) 
end 
addEvent("showGUII",true) 
addEventHandler("showGUII", getRootElement(), showGUII) 

Server:

function showGUIp(hitPlayer) 
    setElementFrozen(source, true) 
    triggerClientEvent (hitPlayer,"showGUII") 
end 
addEventHandler("onClientMarkerHit", buyMark, showGUIp) 

Link to comment

All client side:

GUIEditor = { 
    button = {}, 
    label = {}, 
    window = {}, 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        Window = guiCreateWindow(385, 158, 478, 385, "Buy A Vehicle", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetVisible(GUIEditor.window[1], false) 
  
        GUIEditor.label[1] = guiCreateLabel(26, 98, 326, 34, "Infernous : $30000", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[1], "sa-header") 
        bBuy = guiCreateButton(373, 108, 86, 29, "BUY", false, GUIEditor.window[1])     
    end 
) 
  
local buyVeh = createMarker(1940.5185546875, -1707.1162109375, 13.3828125, "cylinder", 1.5, 255, 255, 0, 170) 
  
function showGUIp(hitPlayer) 
    if ( hitPlayer == localPlayer ) then 
        setElementFrozen ( localPlayer, true ) 
        guiSetVisible ( Window, true ) 
        showCursor ( true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", buyVeh, showGUIp ) 

Link to comment
All client side:
GUIEditor = { 
    button = {}, 
    label = {}, 
    window = {}, 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        Window = guiCreateWindow(385, 158, 478, 385, "Buy A Vehicle", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUIEditor.label[1] = guiCreateLabel(26, 98, 326, 34, "Infernous : $30000", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.label[1], "sa-header") 
        bBuy = guiCreateButton(373, 108, 86, 29, "BUY", false, GUIEditor.window[1])     
    end 
) 
  
local buyVeh = createMarker(1940.5185546875, -1707.1162109375, 13.3828125, "cylinder", 1.5, 255, 255, 0, 170) 
  
function showGUIp(hitPlayer) 
    if ( hitPlayer == localPlayer ) then 
        setElementFrozen ( localPlayer, true ) 
        guiSetVisible ( Window, true ) 
        showCursor ( true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", buyVeh, showGUIp ) 

The GU is still there when i login?

Link to comment
You're welcome.

How would i get rid of everything?

function initGUI() 
        cButton = guiSetVisible ( Window, false ) 
        cButton = guiSetInputEnabled(false) 
        cButton = showCursor ( false ) 
end 
addEventHandler ( "onClientGUIClick", cButton) 

Or How would i do use destroyElement?

Thanks Lloyd

Link to comment
You just need to hide the window.

P.S: You put "GUIEditor.window[1]" instead of "Window" as parent.

I used this, but it didn't work?

function initGUI() 
        cButton = guiSetVisible ( Window, false ) 
        cButton = guiSetInputEnabled(false) 
        cButton = showCursor ( false ) 
end 
addEventHandler ( "onClientGUIClick", cButton) 

Link to comment
GUIEditor = { 
    button = {}, 
    label = {}, 
    window = {}, 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        Window = guiCreateWindow(385, 158, 478, 385, "Buy A Vehicle", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetVisible(GUIEditor.window[1], false) 
  
        GUIEditor.label[1] = guiCreateLabel(26, 98, 326, 34, "Infernous : $30000", false, Window) 
        guiSetFont(GUIEditor.label[1], "sa-header") 
        bBuy = guiCreateButton(373, 108, 86, 29, "BUY", false, Window) 
    end 
) 
  
local buyVeh = createMarker(1940.5185546875, -1707.1162109375, 13.3828125, "cylinder", 1.5, 255, 255, 0, 170) 
  
function showGUIp(hitPlayer) 
    if ( hitPlayer == localPlayer ) then 
        setElementFrozen ( localPlayer, true ) 
        guiSetVisible ( Window, true ) 
        showCursor ( true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", buyVeh, showGUIp ) 
  
function initGUI ( ) 
    guiSetVisible ( Window, false ) 
    guiSetInputEnabled ( false ) 
    showCursor ( false ) 
end 
addEventHandler ( "onClientGUIClick", cButton, initGUI, false ) 

Link to comment
GUIEditor = { 
    button = {}, 
    label = {}, 
    window = {}, 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        Window = guiCreateWindow(385, 158, 478, 385, "Buy A Vehicle", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetVisible(GUIEditor.window[1], false) 
  
        GUIEditor.label[1] = guiCreateLabel(26, 98, 326, 34, "Infernous : $30000", false, Window) 
        guiSetFont(GUIEditor.label[1], "sa-header") 
        bBuy = guiCreateButton(373, 108, 86, 29, "BUY", false, Window) 
    end 
) 
  
local buyVeh = createMarker(1940.5185546875, -1707.1162109375, 13.3828125, "cylinder", 1.5, 255, 255, 0, 170) 
  
function showGUIp(hitPlayer) 
    if ( hitPlayer == localPlayer ) then 
        setElementFrozen ( localPlayer, true ) 
        guiSetVisible ( Window, true ) 
        showCursor ( true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", buyVeh, showGUIp ) 
  
function initGUI ( ) 
    guiSetVisible ( Window, false ) 
    guiSetInputEnabled ( false ) 
    showCursor ( false ) 
end 
addEventHandler ( "onClientGUIClick", cButton, initGUI, false ) 

Thank you! What does the false do at the very end?

Link to comment
It's the "getPropagated" argument, if you don't set it to false, it'll trigger the function by any other GUI element clicked.

Sorry, it still doesn't hide?

GUIEditor = { 
    button = {}, 
    label = {}, 
    window = {}, 
} 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
     Window = guiCreateWindow(0, 0, 1279, 715, "Buy A Vehicle", false) 
        guiWindowSetSizable(Window, false) 
        guiSetVisible(Window, false) 
         
        lInfer = guiCreateLabel(26, 98, 326, 34, "Infernous : $30000", false, GUIEditor.window[1]) 
        guiSetFont(lInfer, "sa-header") 
        guiSetVisible(lInfer, false) 
         
        bBuy = guiCreateButton(373, 108, 86, 29, "BUY", false, GUIEditor.window[1])     
        guiSetVisible(bBuy, false) 
         
        cButton = guiCreateButton(1088, 668, 125, 35, "CLOSE", false, GUIEditor.window[2])  
        guiSetVisible(GUIEditor.button[3], false) 
        guiSetVisible(cButton, false) 
    end 
) 
  
local buyVeh = createMarker(1940.5185546875, -1707.1162109375, 12.3828125, "cylinder", 1.5, 255, 255, 0, 170) 
  
  
function showGUIp(hitPlayer) 
    if ( hitPlayer == localPlayer ) then 
        setElementFrozen ( localPlayer, false ) 
        guiSetVisible ( Window, true ) 
        guiSetVisible ( lInfer, true ) 
        guiSetVisible ( bBuy, true ) 
        guiSetVisible (cButton, true) 
        showCursor ( true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", buyVeh, showGUIp ) 
  
function initGUI( ) 
    guiSetVisible (Window, false ) 
    guiSetVisible (bBuy, false ) 
    guiSetVisible (lInfer, false ) 
    guiSetVisible (cButton, false ) 
    guiSetInputEnabled ( false ) 
    showCursor ( false ) 
end 
addEventHandler ("onClientGUIClick", cButton, initGUI, false ) 

Link to comment
GUIEditor = { 
    button = {}, 
    label = {}, 
    window = {}, 
} 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
    function( ) 
        GUIEditor.window[ 1 ] = guiCreateWindow( 0, 0, 1279, 715, "Buy A Vehicle", false ); 
        guiWindowSetSizable( GUIEditor.window[ 1 ], false ); 
        guiSetVisible( GUIEditor.window[ 1 ], false ); 
        
        GUIEditor.label[ 1 ] = guiCreateLabel( 26, 98, 326, 34, "Infernous : $30000", false, GUIEditor.window[ 1 ] ); 
        guiSetFont( GUIEditor.label[ 1 ], "sa-header" ); 
  
        GUIEditor.button[ 1 ] = guiCreateButton( 373, 108, 86, 29, "BUY", false, GUIEditor.window[ 1 ] ); 
  
        GUIEditor.button[ 2 ] = guiCreateButton( 1088, 668, 125, 35, "CLOSE", false, GUIEditor.window[ 1 ] ); 
    end 
) 
  
local buyVeh = createMarker( 1940.5185546875, -1707.1162109375, 12.3828125, "cylinder", 1.5, 255, 255, 0, 170 ); 
  
  
function showGUIp( hitPlayer ) 
    if ( hitPlayer == localPlayer ) then 
        setElementFrozen ( localPlayer, false ); 
        guiSetVisible( GUIEditor.window[ 1 ], not guiGetVisible( GUIEditor.window[ 1 ] ) ); 
        showCursor( guiGetVisible( GUIEditor.window[ 1 ] ) ); 
    end 
end 
addEventHandler ( "onClientMarkerHit", buyVeh, showGUIp ) 
  
function initGUI( ) 
    guiSetVisible ( GUIEditor.window[ 1 ], not guiGetVisible( GUIEditor.window[ 1 ] ) ); 
    guiSetInputEnabled ( guiGetVisible( GUIEditor.window[ 1 ] ) ); 
    showCursor ( guiGetVisible( GUIEditor.window[ 1 ] ) ); 
end 
addEventHandler ("onClientGUIClick", GUIEditor.button[ 2 ], initGUI, false ) 

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...