Jump to content

Destroying GUI


Tomc0

Recommended Posts

Hello guys, I have a problem with destroying a GUI. So, I'm doing a script where the player can select his spawn skin in a GUI, and if he clicks "Select", the script saves the selected skin and spawns the player with it. The main part of the script is okay, it works, but if the player spawns, I want to destroy GUI, but it doesn't work. Here's the code:

CharacterCreation.lua (Server)

choosenPed = 10 
  
addEvent("incrementPedSkinValue",true) 
addEvent("decrementPedSkinValue",true) 
addEvent("selectSkin",true) 
  
function setPosition() 
    setElementInterior(source,10,246.62,246.62,1003.2) 
    setCameraMatrix(source,215.70843505859,112.55171203613,999.42083740234,214.82604980469,109.06959533691,999.67327880859) 
    outputChatBox(choosenPed) 
    ped = createPed(1,214.89999389648,108.80000305176,999,0.00274658) 
    setElementInterior(ped,10) 
end 
  
function incrementPedSkinValue()  
    choosenPed = choosenPed + 1 
    setElementModel(ped,choosenPed) 
end 
  
function decrementPedSkinValue()  
    if not (choosenPed < 10) then 
        choosenPed = choosenPed - 1 
        setElementModel(ped,choosenPed) 
    end 
end 
  
function selectSkin() 
    skin = getElementModel(ped) 
    spawnPlayer(client,214.89999389648,108.80000305176,999,0.00274658,skin,10) 
    destroyElement(ped) 
    setCameraTarget(client,client) 
    showCursor(client,false) 
    triggerClientEvent(client,"destroyChooserGUI",client) 
end 
  
addEventHandler("incrementPedSkinValue",getRootElement(),incrementPedSkinValue) 
addEventHandler("decrementPedSkinValue",getRootElement(),decrementPedSkinValue) 
addEventHandler("selectSkin",getRootElement(),selectSkin) 

SkinChooser.lua (CLIENT)

function drawChooser() 
    local gui = {} 
    gui._placeHolders = {} 
     
    local screenWidth, screenHeight = guiGetScreenSize() 
    local windowWidth, windowHeight = 299, 61 
    local left = (screenWidth/4 + screenWidth/3)*1.065 
    local top = screenHeight/4 + screenHeight/1 - (screenWidth/3 * 0.-- s8) -->
    gui["_root"] = guiCreateWindow(left, top, windowWidth, windowHeight, "Please choose a skin", false) 
    guiWindowSetSizable(gui["_root"], false) 
     
    gui["leftButton"] = guiCreateButton(20, 25, 75, 23, "<-", false, gui["_root"]) 
    if on_leftButton_clicked then 
        addEventHandler("onClientGUIClick", gui["leftButton"], on_leftButton_clicked, false) 
    end 
     
    gui["select"] = guiCreateButton(123, 31, 46, 13, "Select", false, gui["_root"]) 
    if on_selectButton_clicked then 
        addEventHandler("onClientGUIClick",gui["select"],on_selectButton_clicked,false) 
    end 
     
    gui["rightButton"] = guiCreateButton(200, 25, 75, 23, "->", false, gui["_root"]) 
    if on_rightButton_clicked then 
        addEventHandler("onClientGUIClick", gui["rightButton"], on_rightButton_clicked, false) 
    end 
     
    return gui, windowWidth, windowHeight 
end 
  
addEvent("drawChooser",true) 
addEventHandler("drawChooser",root,drawChooser) 
  
function on_leftButton_clicked() 
    triggerServerEvent("decrementPedSkinValue",getRootElement()) 
end 
  
function on_rightButton_clicked()  
    triggerServerEvent("incrementPedSkinValue",getRootElement()) 
end 
  
function on_selectButton_clicked() 
    triggerServerEvent("selectSkin",getRootElement()) 
end 
  
function destroyChooserGUI()  
    destroyElement(gui["_root"]) 
end 
addEvent("destroyChooserGUI",true) 
addEventHandler("destroyChooserGUI",getRootElement(),destroyGUI) 

Maybe the problem is that the selectSkin() function is attached to the GUI, because if you click on the "Select" button it runs... So maybe that's why I can't call the setGuiVisible() function...

If someone have an idea, please help.

Thansk!

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