Jump to content

Button help


Dannz0r

Recommended Posts

Well I have 2 GUI Windows that pops-up but I only want 1 to pop-up at one time, so I want my Login+Register window to pop-up with in a black background and after the player pressed the button to login or register I want the second GUI Window to pop-up in a 'CameraMatrix' position that I choose, here is the 'client' and 'server' side of both scripts.

Login/Register Client:

x,y = guiGetScreenSize() 
  
fadeCamera(true, 6, 0, 0, 0) 
setCameraMatrix(-1475.5, 831.18, 65.5, -1487.5, 800.18, 65.5) 
  
LoginWin = guiCreateWindow(x/1.37 - 125,y/3 - 100,280,350,"Login and Register | Panel",false) 
  
    guiWindowSetMovable ( LoginWin, false ) 
    guiWindowSetSizable ( LoginWin, false ) 
     
TabPanel = guiCreateTabPanel(0,20,260,152,false,LoginWin) 
  
TabLogin = guiCreateTab("Login | Panel",TabPanel) 
LblUsername = guiCreateLabel(80,13,300,16,"Nickname:",false,TabLogin) 
LoginUsername = guiCreateEdit(46,40,171,21,"",false,TabLogin) 
LblPassword = guiCreateLabel(110,72,70,16,"Password:",false,TabLogin) 
LoginPassword = guiCreateEdit(46,98,171,21,"",false,TabLogin) 
guiEditSetMasked(LoginPassword,true) 
  
TabRegister = guiCreateTab("Register | Panel",TabPanel) 
LblRegisterUsername = guiCreateLabel(10,4,300,16,"Nickname:",false,TabRegister) 
EditRegisterUsername = guiCreateEdit(46,22,171,21,"",false,TabRegister) 
LblRegisterPassword = guiCreateLabel(10,44,150,16,"Password:",false,TabRegister) 
EditRegisterPassword = guiCreateEdit(46,61,171,21,"",false,TabRegister) 
guiEditSetMasked(EditRegisterPassword,true) 
LblRegisterName = guiCreateLabel(10,83,150,16,"Real name:",false,TabRegister) 
EditRegisterName = guiCreateEdit(46,100,171,21,"",false,TabRegister) 
  
BtnAction = guiCreateButton(0,180,260,25,"Login or Register",false,LoginWin) 
  
guiSetVisible(LoginWin, false) 
  
logo = guiCreateStaticImage(0,217,260,120,"images/logo.png",false,LoginWin) 
  
local localPlayer = getLocalPlayer() 
  
function receiveVars( allow, name) 
  
    local playername = getPlayerName(localPlayer) 
     
    guiSetText(LoginUsername, "") 
    guiSetText(EditRegisterUsername, "") 
     
    if (name == "false") then 
        guiSetVisible(LblRegisterName, false) 
        guiSetVisible(EditRegisterName, false) 
    end 
     
    if (allow == "false") then 
        guiDeleteTab(TabRegister, TabPanel) 
    end 
     
    guiSetSelectedTab(TabPanel, TabLogin) 
    guiSetText(LoginUsername, playername) 
    guiSetText(EditRegisterUsername, playername) 
  
    guiSetVisible(LoginWin, true) 
    guiBringToFront(LoginWin) 
     
    guiSetInputEnabled(true) 
    showCursor(true) 
end 
addEvent( "onSendVars", true ) 
addEventHandler( "onSendVars", getRootElement(), receiveVars ) 
  
function windowHandler() 
    triggerServerEvent("onNeedVars", getLocalPlayer()) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), windowHandler) 
  
function onClickBtn(button, state) 
    if(button == "left" and state == "up") then 
        if(source == BtnAction) then 
            if(guiGetSelectedTab(TabPanel) == TabLogin) then 
                triggerServerEvent("on4XLogin", getRootElement(), localPlayer, guiGetText(LoginUsername), guiGetText(LoginPassword)) 
            else 
                triggerServerEvent("on4XRegister", getRootElement(), localPlayer, guiGetText(EditRegisterUsername), guiGetText(EditRegisterPassword), guiGetText(EditRegisterName)) 
            end 
        end 
    end 
end 
  
function hideLoginWindow() 
    guiSetInputEnabled(false) 
    guiSetVisible(LoginWin, false) 
end 
  
addEvent("hideLoginWindow", true) 
addEventHandler("onClientGUIClick", BtnAction, onClickBtn, false) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Login/Register Server:

function on4XLogin ( player, user, pass ) 
    local account = getAccount ( user, pass ) 
    if ( account ~= false ) then 
        if ( not isGuestAccount ( account ) ) then -- For every player that's logged in.... 
            logOut ( player ) -- Log them out. 
        end 
         
        if (logIn ( player, account, pass ) == true) then 
            triggerClientEvent ( player, "hideLoginWindow", getRootElement()) 
        else 
            outputChatBox ( "Login error!", player, 255, 255, 0 ) -- Output they got the details wrong. 
        end 
    else 
        outputChatBox ( "Wrong username or password!", player, 255, 255, 0 ) -- Output they got the details wrong. 
    end 
end 
addEvent( "on4XLogin", true ) 
addEventHandler( "on4XLogin", getRootElement(), on4XLogin ) 
  
function on4XRegister ( player, user, pass, name ) 
    local account = getAccount ( user, pass ) 
    if ( account ~= false ) then 
        if (logIn ( player, account, pass ) == true) then 
            triggerClientEvent ( player, "hideLoginWindow", getRootElement()) 
        else 
            outputChatBox ( "Login error!", player, 255, 255, 0 ) -- Output they got the details wrong. 
        end 
    else 
        account = addAccount ( user, pass ) 
        setAccountData ( account, "name", name) 
        if (logIn ( player, account, pass ) == true) then 
            triggerClientEvent ( player, "hideLoginWindow", getRootElement()) 
        else 
            outputChatBox ( "Register/Login error!", player, 255, 255, 0 ) -- Output they got the details wrong. 
        end 
    end 
end 
addEvent( "on4XRegister", true ) 
addEventHandler( "on4XRegister", getRootElement(), on4XRegister ) 
  
function needVars() 
    local allow_register = get("allow_register") 
    local name_on_register = get("name_on_register") 
    triggerClientEvent(source, "onSendVars", getRootElement(), allow_register, name_on_register) 
end 
addEvent("onNeedVars", true) 
addEventHandler("onNeedVars", getRootElement(), needVars) 

Team selection Client:

--[[Panel created by: [FOTL]Danny]]-- 
--[[On 17th August 2011]]-- 
  
x,y = guiGetScreenSize() 
  
JobsWin = guiCreateWindow(x/3 - 170,y/3 - 20,200,320,"Team selection | Panel",false) 
  
teamsList = guiCreateGridList(0,22,186,255,false,JobsWin) 
column = guiGridListAddColumn( teamsList, "Teams", 0.85 ) 
     
for id, team in ipairs(getElementsByType("team")) do 
        local row = guiGridListAddRow ( teamsList ) 
        guiGridListSetItemText ( teamsList, row, 1, getTeamName ( team ), false, false ) 
        guiGridListSetItemColor ( teamsList, row, 1, getTeamColor ( team ) ) 
end 
  
guiWindowSetMovable ( teamsList, false ) 
guiWindowSetMovable ( JobsWin, false ) 
guiWindowSetSizable ( teamsList, false ) 
guiWindowSetSizable ( JobsWin, false ) 
  
send = guiCreateButton(0,285,90,25,"Select",false,JobsWin) 
  
CloseButton = guiCreateButton(105,285,90,25,"Close",false,JobsWin) 
  
guiSetVisible(JobsWin, true) 
showCursor(true) 
setTimer ( showingTeams, 1000, 1) 
  
function close() 
if source == CloseButton then 
guiSetVisible(JobsWin, false) 
showCursor(false) 
end 
end 
  
addEventHandler ( "onClientGUIClick", root, 
function ( button ) 
if button == "left" then 
if source == send then 
local row, col = guiGridListGetSelectedItem ( teamsList ) 
local teamName = guiGridListGetItemText ( teamsList, row, col ) 
triggerServerEvent ( "onPlayerChooseTeam", getLocalPlayer(), teamName ) 
end 
end 
end) 
  
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), close) 

addEvent ( "onPlayerChooseTeam" , true ) 
addEventHandler ( "onPlayerChooseTeam" , root , 
function ( teamName ) 
local team = getTeamFromName ( teamName ) 
setPlayerTeam ( source , team ) 
outputChatBox("You have successfully choosed "..getTeamName(team).." team.", resPlayer, root, 0, 255, 0) 
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...