Jump to content

[Help]Lua GUI


JasperRieken

Recommended Posts

i made my first gui it opens and it sais bad event handler line 13 can't find out what's wrong somebody see somting?

ClietSide

marker = createMarker(2327.27,-3083.64,60.25,"cylinder",2,255,0,0,255) 
  
function gui() 
           if ( guiGetVisible (window) == true ) then -- check if the gui element is visible      
                showCursor(false)           
                guiSetVisible (window, false ) -- if it is, we hide it 
        else               
                guiSetVisible (window, false ) -- if not, we make it visible 
                showCursor(true) 
  
window = guiCreateWindow(471,278,366,401,"Xuju Vechile's",false) 
but1 = guiCreateButton(100,42,158,45,"BXM",false,window) 
addEventHandler("onClientGUIClick", but1, bmxBike, false) 
but2 = guiCreateButton(100,114,158,45,"Mountain Bike",false,window) 
but3 = guiCreateButton(101,192,158,45,"Bike",false,window) 
but4 = guiCreateButton(83,138,5,5,"",false,window) 
but5 = guiCreateButton(101,267,158,45,"Sanchez",false,window) 
but6 = guiCreateButton(26,362,82,30,"Close",false,window) 
end 
end 
addEventHandler("onClientMarkerHit", marker, gui) 
  
function bxmBike() 
guiSetVisible(window, false) 
showCursor(false) 
triggerServerEvent( "spawnBmx", getLocalPlayer(),getPlayerName( getLocalPlayer() ) ) 
end 
  

ServerSide

addEvent("spawnBmx", true)   
function bikeQ(playerName) 
local guy = getPlayerFromName( playerName ); 
        local x, y, z = getElementPosition ( guy ) 
        local r = getPedRotation ( guy ) 
        vehicle = createVehicle ( 481, x, y, z, 0, 0, r ) 
        warpPedIntoVehicle ( guy, vehicle ) 
        outputChatBox("Bmx spawned!", guy, 0, 255, 0) 
        end 
        addEventHandler ( "spawnBmx", getRootElement(), bikeQ ) 

Link to comment

Please use [ lua][ /lua] tags. You're function name is wrong, you really can detect that error yourself!

About the script, your window doesn't need to be created if it already exists, check for the window variable before checking it's visible. (And the last guiSetVisible is wrong)

function gui() 
    if not window then  --if the window doesn't exist, create it 
        window = guiCreateWindow(471,278,366,401,"Xuju Vechile's",false) 
        but1 = guiCreateButton(100,42,158,45,"BXM",false,window) 
        addEventHandler("onClientGUIClick", but1, bmxBike, false) 
        but2 = guiCreateButton(100,114,158,45,"Mountain Bike",false,window) 
        but3 = guiCreateButton(101,192,158,45,"Bike",false,window) 
        but4 = guiCreateButton(83,138,5,5,"",false,window) 
        but5 = guiCreateButton(101,267,158,45,"Sanchez",false,window) 
        but6 = guiCreateButton(26,362,82,30,"Close",false,window) 
    elseif ( guiGetVisible (window) == true ) then -- check if the gui element is visible     
        showCursor(false)           
        guiSetVisible (window, false ) -- if it is, we hide it 
    else               
        guiSetVisible (window, true ) -- if not, we make it visible 
        showCursor(true) 
    end 
end 

Link to comment

No need This scriped is Solved

ClientSide

marker = createMarker(2327.27,-3083.64,59.25,"cylinder",2,255,255,255,255) 
  
function gui(hitElement) 
          if getElementType( hitElement ) == "player" and hitElement == getLocalPlayer() then 
           if ( guiGetVisible (window) == true ) then -- check if the gui element is visible      
                showCursor(false)           
                guiSetVisible (window, false ) -- if it is, we hide it 
        else               
                guiSetVisible (window, false ) -- if not, we make it visible 
                showCursor(true) 
                end 
  
window = guiCreateWindow(471,278,366,401,"Xuju Vechile's",false) 
  
but1 = guiCreateButton(100,42,158,45,"BXM",false,window) 
addEventHandler("onClientGUIClick", but1, bmxBike, false) 
but2 = guiCreateButton(100,114,158,45,"Mountain Bike",false,window) 
addEventHandler("onClientGUIClick", but2, mountainBike, false) 
but3 = guiCreateButton(101,192,158,45,"Bike",false,window) 
addEventHandler("onClientGUIClick", but3, Bike, false) 
but4 = guiCreateButton(101,267,158,45,"Sanchez",false,window) 
addEventHandler("onClientGUIClick", but4, Sanchez, false) 
but5 = guiCreateButton(26,362,82,30,"Close",false,window) 
addEventHandler("onClientGUIClick", but5, hideWindow, false) 
end 
end 
addEventHandler("onClientMarkerHit", marker, gui) 
  
function bmxBike() 
guiSetVisible(window, false) 
showCursor(false) 
triggerServerEvent( "spawnBmx", getLocalPlayer(),getPlayerName( getLocalPlayer() ) ) 
end 
  
function mountainBike() 
guiSetVisible(window, false) 
showCursor(false) 
triggerServerEvent( "spawnMountainbike", getLocalPlayer(),getPlayerName( getLocalPlayer() ) ) 
end 
  
function Bike() 
guiSetVisible(window, false) 
showCursor(false) 
triggerServerEvent( "spawnBike", getLocalPlayer(),getPlayerName( getLocalPlayer() ) ) 
end 
  
function Sanchez() 
guiSetVisible(window, false) 
showCursor(false) 
triggerServerEvent( "spawnSanchez", getLocalPlayer(),getPlayerName( getLocalPlayer() ) ) 
end 
  
function hideWindow() 
guiSetVisible(window, false) 
showCursor(false) 
end 
  
  

ServerSide

addEvent("spawnBmx", true)   
function bikeQ(playerName) 
local guy = getPlayerFromName( playerName ); 
        local x, y, z = getElementPosition ( guy ) 
        local r = getPedRotation ( guy ) 
        vehicle = createVehicle ( 481, x, y, z, 0, 0, r ) 
        warpPedIntoVehicle ( guy, vehicle ) 
        outputChatBox("Bmx spawned!", guy, 0, 255, 0) 
        end 
        addEventHandler ( "spawnBmx", getRootElement(), bikeQ ) 
         
addEvent("spawnMountainbike", true)   
function bikeQ(playerName) 
local guy = getPlayerFromName( playerName ); 
        local x, y, z = getElementPosition ( guy ) 
        local r = getPedRotation ( guy ) 
        vehicle = createVehicle ( 510, x, y, z, 0, 0, r ) 
        warpPedIntoVehicle ( guy, vehicle ) 
        outputChatBox("MountainBike spawned!", guy, 0, 255, 0) 
        end 
        addEventHandler ( "spawnMountainbike", getRootElement(), bikeQ ) 
         
addEvent("spawnBike", true)   
function bikeQ(playerName) 
local guy = getPlayerFromName( playerName ); 
        local x, y, z = getElementPosition ( guy ) 
        local r = getPedRotation ( guy ) 
        vehicle = createVehicle ( 509, x, y, z, 0, 0, r ) 
        warpPedIntoVehicle ( guy, vehicle ) 
        outputChatBox("Bike spawned!", guy, 0, 255, 0) 
        end 
        addEventHandler ( "spawnBike", getRootElement(), bikeQ ) 
         
addEvent("spawnSanchez", true)   
function bikeQ(playerName) 
local guy = getPlayerFromName( playerName ); 
        local x, y, z = getElementPosition ( guy ) 
        local r = getPedRotation ( guy ) 
        vehicle = createVehicle ( 468, x, y, z, 0, 0, r ) 
        warpPedIntoVehicle ( guy, vehicle ) 
        outputChatBox("Sanchez spawned!", guy, 0, 255, 0) 
        end 
        addEventHandler ( "spawnSanchez", getRootElement(), bikeQ ) 
         
         
         

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