Jump to content

Gui problem


Blueman

Recommended Posts

In the code below it happens that my gui won't show, I'm just wondering if i made a mistake in the code.

I don't think it's the binds because I've tried using a command handler to open the gui and it fails as well.

I receive no errors through the console though. :|

  
function binds() 
//The variable MAccount is represented in another script 
CName = getPlayerName(getLocalPlayer()) 
if ( MAccount == "Gen" ) then  
   bindKey ( CName, "I", "down", build_MainWindow ) 
   else 
       if ( CName == "meep" ) then 
          bindKey ( CName, "I" "down", build_MainWindow ) 
      else 
    end 
  end 
end 
addEventHandler ("onClientResourceStart", getRootElement(), binds) 
  
function build_MainWindow() 
     
    local gui = {} 
    gui._placeHolders = {} 
     
    local screenWidth, screenHeight = guiGetScreenSize() 
    local windowWidth, windowHeight = 251, 174 
    local left = screenWidth/2 - windowWidth/2 
    local top = screenHeight/2 - windowHeight/2 
    gui["_root"] = guiCreateWindow(left, top, windowWidth, windowHeight, "MainWindow", false) 
    guiWindowSetSizable(gui["_root"], false) 
     
    gui["lineEdit"] = guiCreateEdit(70, 125, 161, 20, "", false, gui["_root"]) 
    guiEditSetMaxLength(gui["lineEdit"], 32767) 
     
    gui["pushButton"] = guiCreateButton(0, 35, 75, 23, "General", false, gui["_root"]) 
    if on_pushButton_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton"], General, false) 
    end 
     
    gui["pushButton_2"] = guiCreateButton(80, 35, 75, 23, "Coloniel", false, gui["_root"]) 
    if on_pushButton_2_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_2"], Coloniel, false) 
    end 
     
    gui["pushButton_3"] = guiCreateButton(0, 65, 75, 23, "Recruit", false, gui["_root"]) 
    if on_pushButton_3_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_3"], Recruit, false) 
    end 
     
    gui["pushButton_4"] = guiCreateButton(80, 65, 75, 23, "Private", false, gui["_root"]) 
    if on_pushButton_4_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_4"], Private, false) 
    end 
     
    gui["pushButton_5"] = guiCreateButton(160, 35, 75, 23, "Sargent", false, gui["_root"]) 
    if on_pushButton_5_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_5"], Sargent, false) 
    end 
     
    gui["pushButton_6"] = guiCreateButton(160, 65, 75, 23, "DrillSargent", false, gui["_root"]) 
    if on_pushButton_6_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_6"], DrillSargent, false) 
    end 
     
    gui["pushButton_7"] = guiCreateButton(0, 95, 75, 23, "NationalGaurd", false, gui["_root"]) 
    if on_pushButton_7_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_7"], NationalGaurd, false) 
    end 
     
    gui["pushButton_8"] = guiCreateButton(80, 95, 75, 23, "MilitaryScripter", false, gui["_root"]) 
    if on_pushButton_8_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_8"], MilitaryScripter, false) 
    end 
     
    gui["pushButton_9"] = guiCreateButton(160, 95, 75, 23, "Remove", false, gui["_root"]) 
    if on_pushButton_9_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_9"], Remove, false) 
    end 
     
    gui["label"] = guiCreateLabel(0, 15, 46, 13, "Options:", false, gui["_root"]) 
    guiLabelSetHorizontalAlign(gui["label"], "left", false) 
    guiLabelSetVerticalAlign(gui["label"], "center") 
     
    gui["label_2"] = guiCreateLabel(0, 125, 71, 16, "AccountName:", false, gui["_root"]) 
    guiLabelSetHorizontalAlign(gui["label_2"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_2"], "center") 
     
    return gui, windowWidth, windowHeight 
end 
  
function General() 
triggerServerEvent ("Gen", getLocalPlayer()) 
mtext = guiGetText ( editBoxgui["lineEdit"] ) 
  
function Coloniel() 
triggerServerEvent ("Col", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function Recruit() 
triggerServerEvent ("Rct", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function Private() 
triggerServerEvent ("Pvt", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function Sargent() 
triggerServerEvent ("Sgt", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function DrillSargent() 
triggerServerEvent ("Dsgt", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function NationalGaurd() 
triggerServerEvent ("Ng", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function MilitaryScripter() 
triggerServerEvent ("Mscr", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function Remove() 
triggerServerEvent ("Rem", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  

Link to comment
function binds() 
//The variable MAccount is represented in another script 
CName = getPlayerName(getLocalPlayer()) 
if ( MAccount == "Gen" ) then 
   bindKey ( CName, "I", "down", build_MainWindow ) 
   else 
       if ( CName == "meep" ) then 
          bindKey ( CName, "I" "down", build_MainWindow ) 
      else 
    end 
  end 
end 
addEventHandler ("onClientResourceStart", getRootElement(), binds) 
  
function build_MainWindow() 
    
    local gui = {} 
    gui._placeHolders = {} 
    
    local screenWidth, screenHeight = guiGetScreenSize() 
    local windowWidth, windowHeight = 251, 174 
    local left = screenWidth/2 - windowWidth/2 
    local top = screenHeight/2 - windowHeight/2 
    gui["_root"] = guiCreateWindow(left, top, windowWidth, windowHeight, "MainWindow", false) 
    guiWindowSetSizable(gui["_root"], false) 
    
    gui["lineEdit"] = guiCreateEdit(70, 125, 161, 20, "", false, gui["_root"]) 
    guiEditSetMaxLength(gui["lineEdit"], 32767) 
    
    gui["pushButton"] = guiCreateButton(0, 35, 75, 23, "General", false, gui["_root"]) 
    if on_pushButton_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton"], General, false) 
    end 
    
    gui["pushButton_2"] = guiCreateButton(80, 35, 75, 23, "Coloniel", false, gui["_root"]) 
    if on_pushButton_2_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_2"], Coloniel, false) 
    end 
    
    gui["pushButton_3"] = guiCreateButton(0, 65, 75, 23, "Recruit", false, gui["_root"]) 
    if on_pushButton_3_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_3"], Recruit, false) 
    end 
    
    gui["pushButton_4"] = guiCreateButton(80, 65, 75, 23, "Private", false, gui["_root"]) 
    if on_pushButton_4_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_4"], Private, false) 
    end 
    
    gui["pushButton_5"] = guiCreateButton(160, 35, 75, 23, "Sargent", false, gui["_root"]) 
    if on_pushButton_5_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_5"], Sargent, false) 
    end 
    
    gui["pushButton_6"] = guiCreateButton(160, 65, 75, 23, "DrillSargent", false, gui["_root"]) 
    if on_pushButton_6_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_6"], DrillSargent, false) 
    end 
    
    gui["pushButton_7"] = guiCreateButton(0, 95, 75, 23, "NationalGaurd", false, gui["_root"]) 
    if on_pushButton_7_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_7"], NationalGaurd, false) 
    end 
    
    gui["pushButton_8"] = guiCreateButton(80, 95, 75, 23, "MilitaryScripter", false, gui["_root"]) 
    if on_pushButton_8_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_8"], MilitaryScripter, false) 
    end 
    
    gui["pushButton_9"] = guiCreateButton(160, 95, 75, 23, "Remove", false, gui["_root"]) 
    if on_pushButton_9_clicked then 
        addEventHandler("onClientGUIClick", gui["pushButton_9"], Remove, false) 
    end 
    
    gui["label"] = guiCreateLabel(0, 15, 46, 13, "Options:", false, gui["_root"]) 
    guiLabelSetHorizontalAlign(gui["label"], "left", false) 
    guiLabelSetVerticalAlign(gui["label"], "center") 
    
    gui["label_2"] = guiCreateLabel(0, 125, 71, 16, "AccountName:", false, gui["_root"]) 
    guiLabelSetHorizontalAlign(gui["label_2"], "left", false) 
    guiLabelSetVerticalAlign(gui["label_2"], "center") 
    
    return gui, windowWidth, windowHeight 
end 
  
function General() -- You had a missing 'end' in this function. 
triggerServerEvent ("Gen", getLocalPlayer()) 
mtext = guiGetText ( editBoxgui["lineEdit"] ) 
end 
  
function Coloniel() 
triggerServerEvent ("Col", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function Recruit() 
triggerServerEvent ("Rct", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function Private() 
triggerServerEvent ("Pvt", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function Sargent() 
triggerServerEvent ("Sgt", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function DrillSargent() 
triggerServerEvent ("Dsgt", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function NationalGaurd() 
triggerServerEvent ("Ng", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function MilitaryScripter() 
triggerServerEvent ("Mscr", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 
  
function Remove() 
triggerServerEvent ("Rem", getLocalPlayer()) 
mtext = guiGetText ( gui["lineEdit"] ) 
end 

Try that.

Link to comment

Sure amd sorry about the double post :|

  
addEvent ("Gen", true) 
addEvent ("Col", true) 
addEvent ("Rct", true) 
addEvent ("Pvt", true) 
addEvent ("Sgt", true) 
addEvent ("Dsgt", true) 
addEvent ("Ng", true) 
addEvent ("Mscr", true) 
addEvent ("Rem", true) 
local M1 = "Gen" 
local M2 = "Col" 
local M3 = "Rct" 
local M4 = "Pvt" 
local m5 = "Sgt" 
local m6 = "Dsgt" 
local M7 = "NG" 
local M8 = "Mscr" 
local M9 = "Banned" 
function start() 
MPlayeraccount = getPlayerAccount (source) 
MAccount = getAccountData ( MPlayeraccount, "mili.pos" ) 
end 
addEventHandler ("onClientResourceStart", getRootElement(), start) 
  
function Gen() 
setAccountData ( mtext, "mili.pos", M1  ) 
end 
addEventHandler ("Gen", getRootElement(), Gen) 
  
function Col() 
setAccountData ( mtext, "mili.pos", M2  ) 
end 
addEventHandler ("Col", getRootElement(), Col) 
  
function Rct() 
setAccountData ( mtext, "mili.pos", M3  ) 
end 
addEventHandler ("Rct", getRootElement(), Rct) 
  
function Pvt() 
setAccountData ( mtext, "mili.pos", M4  ) 
end 
addEventHandler ("Pvt", getRootElement(), Pvt) 
  
function Sgt() 
setAccountData ( mtext, "mili.pos", M5  ) 
end 
addEventHandler ("Sgt", getRootElement(), Sgt) 
  
function Dsgt() 
setAccountData ( mtext, "mili.pos", M6  ) 
end 
addEventHandler ("Dsgt", getRootElement(), Dsgt) 
  
function Ng() 
setAccountData ( mtext, "mili.pos", M7  ) 
end 
addEventHandler ("Ng", getRootElement(), Ng) 
  
function Mscr() 
setAccountData ( mtext, "mili.pos", M8  ) 
end 
addEventHandler ("Mscr", getRootElement(), Mscr) 
  
function Rem() 
setAccountData ( mtext, "mili.pos", m9  )  
end 
addEventHandler ("Rem", getRootElement(), Rem ) 
  

Link to comment
  • Moderators
use triggerServerEvent to send data to the server side, and triggerClientEvent to send data to the client side.

And in your meta.xml you have to make like this:

<script src="server.lua" /> <!-- type="server" by default --> <!-- Now you can use server functions in this file --> 
<script src="client.lua" type="client" /> <!-- Now you can use client functions in this file --> 

and

use triggerServerEvent to send data to the server side, and triggerClientEvent to send data to the client side.
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...