Jump to content

Buttons...


ASiT

Recommended Posts

hey i successfully have a login screen for my script but now i want to create a window that spawns after you log in.

On this window i want to have 2 buttons that if you press one it spawns you one place and if you press the other it spawn u somewhere else ... does anyone know the code id use for this...? And since im so new do i put the code for this second code in the same .lua as the login screen ....any help would be greatly appreciated....

everything i try just doesnt work...

Link to comment

sorry about the double post ...( thought the first one was about something else that got answered didnt know i had included the same thing) :oops:

but ya another question i have my first login in window once thats dissappears and logs u in i want another window to come up but so far everything ive tried hasnt worked and results in niether of the windows showing up ....the screen just stays black (and i know its not fadecamera()

but do i just put another function CreateSelectWindow() at the bottom ...? and will that make it appear after the login...? or do i have to put something like

addeventhandler("onClientGUIClick",btnLogin,CreateLoginWindow) in...? ( <--- i think thats what its supposed to say...

any help...

Link to comment

heres what i have ... i took ur advice and added a triggerClientevent... tell me if this is how im supposed to do it...because this didnt work either

local localPlayer = getLocalPlayer() 
local localPlayerName = getPlayerName(localPlayer) 
local localRootElement = getRootElement() 
local newUser 
local passwordAttempts = 0 
  
function CreateLoginWindow() 
    wdwLogin = guiCreateWindow(0.375,0.350,0.300,0.250,"Log In v0.1.2",true) 
    guiWindowSetSizable(wdwLogin,false) 
    guiWindowSetMovable(wdwLogin,false) 
  
    guiCreateLabel(0.080,0.200,0.250,0.250,"Username:",true,wdwLogin) 
    guiCreateLabel(0.080,0.450,0.250,0.250,"Password:",true,wdwLogin) 
  
    edtUser = guiCreateEdit(0.380,0.190,0.500,0.150,localPlayerName,true,wdwLogin) 
    guiEditSetReadOnly(edtUser,true) 
    edtPass = guiCreateEdit(0.380,0.440,0.500,0.150,"",true,wdwLogin) 
    guiEditSetMaxLength(edtPass,20) 
    guiEditSetMasked(edtPass,true) 
  
    btnLogin = guiCreateButton(0.630,0.650,0.250,0.150,"Log In",true,wdwLogin) 
  
    guiSetVisible(wdwLogin,false) 
     
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        CreateLoginWindow() 
        lblDisplayArea = guiCreateLabel(0.100,0.800,0.800,0.100,"",true) 
        guiLabelSetHorizontalAlign(lblDisplayArea,"center",true) 
             
        addEventHandler("onClientGUIClick",btnLogin,clientSubmitLogin,false) --Mouseclick on the Login button... 
        addEventHandler("onClientGUIAccepted",edtPass,clientEnterLogin,false) --Hitting 'enter' key in password box... 
  
        triggerServerEvent ("checkValidAct",localPlayer,localPlayerName) --Check if they have an account to log in to... 
    end 
) 
  
function clientNewUserHandler() --Called when no account exists for this players name... 
    newUser = true 
    guiSetText(lblDisplayArea,"No account exists for your username. Please create a password.") 
    if(wdwLogin) then 
        guiSetVisible(wdwLogin,true) 
        guiBringToFront(edtPass) --Puts the cursor into the password box for typing... 
    end 
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
addEvent("clientNewUser",true) 
addEventHandler("clientNewUser",localRootElement,clientNewUserHandler) 
  
function clientReturningUserHandler() --Called when there is an existing account for this player's name... 
    newUser = false 
    guiSetText(lblDisplayArea,"You are using a registered nickname - please enter your password.") 
    if(wdwLogin) then 
        guiSetVisible(wdwLogin,true) 
        guiBringToFront(edtPass) --Puts the cursor into the password box for typing... 
    end 
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
addEvent("clientReturningUser",true) 
addEventHandler("clientReturningUser",localRootElement,clientReturningUserHandler) 
  
function clientEnterLogin() 
    if(newUser) then 
        triggerServerEvent("SubmitCreate",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
    else 
        triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
    end 
end 
  
function clientSubmitLogin(button) 
    if(button == "left") then 
        if(newUser) then 
            triggerServerEvent("SubmitCreate",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
            triggerClientEvent("SelectCreate", getRootElement()) 
        else 
            triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
            triggerClientEvent("SelectCreate", getRootElement()) 
        end 
    end 
end 
  
function clientDisplayAreaHandler(theMessage) 
    guiSetText(lblDisplayArea,theMessage) 
end 
addEvent("clientDisplayArea",true) 
addEventHandler("clientDisplayArea",localRootElement,clientDisplayAreaHandler) 
  
function clientWrongPasswordHandler(theMessage) 
    passwordAttempts = passwordAttempts + 1 
    if(passwordAttempts > 3) then 
        guiSetText(lblDisplayArea,"Too many incorrect password attempts.  Please disconnect.") 
        destroyElement(wdwLogin) 
        triggerServerEvent("removePlayer",localPlayer) 
    end 
end 
addEvent("clientWrongPassword",true) 
addEventHandler("clientWrongPassword",localRootElement,clientWrongPasswordHandler) 
  
function clientLoginSuccessHandler() 
    guiSetInputEnabled(false) 
    destroyElement(wdwLogin) 
    destroyElement(lblDisplayArea) 
    wdwLogin = nil 
    newUser = nil 
    lblDisplayArea = nil 
    passwordAttempts = nil 
    localPlayer = nil 
    localPlayerName = nil 
    localRootElement = nil 
    showCursor(false) 
end 
addEvent("clientLoginSuccess",true) 
addEventHandler("clientLoginSuccess",localRootElement,clientLoginSuccessHandler) 
  
function createSelectWindow() 
  
        local X = 0.375 
        local Y = 0.375 
        local Width = 0.25 
        local Height = 0.25 
        wdwSelect = guiCreateWindow(X, Y, Width, Height, "Please Select a Class", true) 
        
        X = 0.415 
        Y = 0.2 
        Width = 0.5 
        Height = 0.15 
        btnCops = guiCreateButton(X, Y, Width, Height, "Cops", true, wdwSelect) 
        Y = 0.5 
        btnRobs = guiCreateEdit(X, Y, Width, Height, "Robbers", true, wdwSelect) 
        
        guiSetVisible(wdwSelect, false) 
end 
  
addEvent("SelectCreate", true) 
addEventHandler("SelectCreate", getRootElement(), createSelectWindow) 

Link to comment

Yes, that's they way you have to do it but also you must understand how it works, otherwise you won't know how to make something that uses triggerClientEvent/triggerServerEvent. That's the whole point in your script, you have to tell server he wants to log in (triggerServerEvent, in client-side script) and if he logged in successfully, tell the client script that he logged in and you want to show a new window (triggerClientEvent, in server-side script).

What I see is a function to create & hide a window (which is not called, unless you used triggerClientEvent to trigger SelectCreate). What exactly doesn't work? If you successfully log in the "Log in" window disappear and a new window doesn't appear?

I see you have an event "clientLoginSuccess", you can create a window in this event or call createSelectWindow() from clientLoginSuccessHandler.

Link to comment

so with what ur saying to add createSelectWindow() in the login success the last 2 paragraph i guess you could call them should look like this...?

function clientLoginSuccessHandler() 
    guiSetInputEnabled(false) 
    destroyElement(wdwLogin) 
    destroyElement(lblDisplayArea) 
    wdwLogin = nil 
    newUser = nil 
    lblDisplayArea = nil 
    passwordAttempts = nil 
    localPlayer = nil 
    localPlayerName = nil 
    localRootElement = nil 
    showCursor(false) 
     
    createSelectWindow() 
end 
addEvent("clientLoginSuccess",true) 
addEventHandler("clientLoginSuccess",localRootElement,clientLoginSuccessHandler) 
  
function createSelectWindow() 
  
        local X = 0.375 
        local Y = 0.375 
        local Width = 0.25 
        local Height = 0.25 
        wdwSelect = guiCreateWindow(X, Y, Width, Height, "Please Select a Class", true) 
        
        X = 0.415 
        Y = 0.2 
        Width = 0.5 
        Height = 0.15 
        btnCops = guiCreateButton(X, Y, Width, Height, "Cops", true, wdwSelect) 
        Y = 0.5 
        btnRobs = guiCreateEdit(X, Y, Width, Height, "Robbers", true, wdwSelect) 
        
        guiSetVisible(wdwSelect, false) 
end 

or do i leave the

addEvent("SelectCreate", true) 
addEventHandler("SelectCreate", getRootElement(), createSelectWindow) 

in the code

Link to comment

It should be fine without custom event because one event is triggered when you successfully log in (which is clientLoginSuccess). Remove guiSetVisible( wdwSelect, false ) from createSelectWindow function and add it somewhere else (where player is successfully spawned). Also don't hide cursor if you still need to use it (player logged in and you show new window but you hide cursor therefore he can't use the new window).

Link to comment

I have another problem (so many :P ) so this is what i want my gui to look like (made using gui editor)...

http://img186.imageshack.us/my.php?image=mtascreen0003nm7.png

so i made some changes because the code given didnt work until the code looked like this

local localPlayer = getLocalPlayer() 
local localPlayerName = getPlayerName(localPlayer) 
local localRootElement = getRootElement() 
local newUser 
local passwordAttempts = 0 
  
function CreateLoginWindow() 
    wdwLogin = guiCreateWindow(0.375,0.350,0.300,0.250,"Log In v0.1.2",true) 
    guiWindowSetSizable(wdwLogin,false) 
    guiWindowSetMovable(wdwLogin,false) 
  
    guiCreateLabel(0.080,0.200,0.250,0.250,"Username:",true,wdwLogin) 
    guiCreateLabel(0.080,0.450,0.250,0.250,"Password:",true,wdwLogin) 
  
    edtUser = guiCreateEdit(0.380,0.190,0.500,0.150,localPlayerName,true,wdwLogin) 
    guiEditSetReadOnly(edtUser,true) 
    edtPass = guiCreateEdit(0.380,0.440,0.500,0.150,"",true,wdwLogin) 
    guiEditSetMaxLength(edtPass,20) 
    guiEditSetMasked(edtPass,true) 
  
    btnLogin = guiCreateButton(0.630,0.650,0.250,0.150,"Log In",true,wdwLogin) 
  
    guiSetVisible(wdwLogin,false) 
     
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        CreateLoginWindow() 
        lblDisplayArea = guiCreateLabel(0.100,0.800,0.800,0.100,"",true) 
        guiLabelSetHorizontalAlign(lblDisplayArea,"center",true) 
             
        addEventHandler("onClientGUIClick",btnLogin,clientSubmitLogin,false) --Mouseclick on the Login button... 
        addEventHandler("onClientGUIAccepted",edtPass,clientEnterLogin,false) --Hitting 'enter' key in password box... 
  
        triggerServerEvent ("checkValidAct",localPlayer,localPlayerName) --Check if they have an account to log in to... 
    end 
) 
  
function clientNewUserHandler() --Called when no account exists for this players name... 
    newUser = true 
    guiSetText(lblDisplayArea,"No account exists for your username. Please create a password.") 
    if(wdwLogin) then 
        guiSetVisible(wdwLogin,true) 
        guiBringToFront(edtPass) --Puts the cursor into the password box for typing... 
    end 
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
addEvent("clientNewUser",true) 
addEventHandler("clientNewUser",localRootElement,clientNewUserHandler) 
  
function clientReturningUserHandler() --Called when there is an existing account for this player's name... 
    newUser = false 
    guiSetText(lblDisplayArea,"You are using a registered nickname - please enter your password.") 
    if(wdwLogin) then 
        guiSetVisible(wdwLogin,true) 
        guiBringToFront(edtPass) --Puts the cursor into the password box for typing... 
    end 
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
addEvent("clientReturningUser",true) 
addEventHandler("clientReturningUser",localRootElement,clientReturningUserHandler) 
  
function clientEnterLogin() 
    if(newUser) then 
        triggerServerEvent("SubmitCreate",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
    else 
        triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
    end 
end 
  
function clientSubmitLogin(button) 
    if(button == "left") then 
        if(newUser) then 
            triggerServerEvent("SubmitCreate",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
            triggerClientEvent("SelectCreate", getRootElement()) 
        else 
            triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
            triggerClientEvent("SelectCreate", getRootElement()) 
        end 
    end 
end 
  
function clientDisplayAreaHandler(theMessage) 
    guiSetText(lblDisplayArea,theMessage) 
end 
addEvent("clientDisplayArea",true) 
addEventHandler("clientDisplayArea",localRootElement,clientDisplayAreaHandler) 
  
function clientWrongPasswordHandler(theMessage) 
    passwordAttempts = passwordAttempts + 1 
    if(passwordAttempts > 3) then 
        guiSetText(lblDisplayArea,"Too many incorrect password attempts.  Please disconnect.") 
        destroyElement(wdwLogin) 
        triggerServerEvent("removePlayer",localPlayer) 
    end 
end 
addEvent("clientWrongPassword",true) 
addEventHandler("clientWrongPassword",localRootElement,clientWrongPasswordHandler) 
  
function clientLoginSuccessHandler() 
    guiSetInputEnabled(false) 
    destroyElement(wdwLogin) 
    destroyElement(lblDisplayArea) 
    wdwLogin = nil 
    newUser = nil 
    lblDisplayArea = nil 
    passwordAttempts = nil 
    localPlayer = nil 
    localPlayerName = nil 
    localRootElement = nil 
     
    createSelectWindow()     
end 
addEvent("clientLoginSuccess",true) 
addEventHandler("clientLoginSuccess",localRootElement,clientLoginSuccessHandler) 
  
function createSelectWindow() 
    wdwSelect = guiCreateWindow(0,0,0.5,0.4,"Select a Character Class", true) 
    tbpCharSelect = guiCreateTabPanel(0.0622,0.1086,0.8466,0.7629,true,wdwSelect) 
    tabCops = guiCreateTab("Cops",tbpCharSelect) 
    tabCivs = guiCreateTab("Civilians",tpbCharSelect) 
    tabArmy = guiCreateTab("Army",tpbCharSelect) 
    btnArmy = guiCreateButton(0.0165,0.8264,0.967,0.1504,"Join Team Army!",true,tabArmy) 
    btnCivs = guiCreateButton(0.0165,0.8264,0.967,0.1504,"Join Team Civilians!",true,tabCivs) 
    btnCops = guiCreateButton(0.0165,0.8264,0.967,0.1504,"Join Team Cops!",true,tabCops) 
    memCops = guiCreateMemo(0.1293,0.1504,0.7503,0.6594,"Police Sample Text....",true,tabCops) 
    memCivs = guiCreateMemo(0.1293,0.1504,0.7503,0.6594,"Civilian Sample Text...",true,tabCivs) 
    memArmy = guiCreateMemo(0.1293,0.1504,0.7503,0.6594,"Army Sample Text...",true,tabArmy) 
    lblCops = guiCreateLabel(0.294,0.0017,0.4144,0.1722,"Team Cops",true,tabCops) 
    guiSetFont(lblCops,"sa-gothic") 
    lblCivs = guiCreateLabel(0.294,0.0017,0.4144,0.1722,"Team Civilians",true,tabCivs) 
    guiSetFont(lblCivs,"sa-gothic") 
    lblArmy = guiCreateLabel(0.294,0.0017,0.4144,0.1722,"Team Army",true,tabArmy) 
    guiSetFont(lblArmy,"sa-gothic") 
  
end 

but now when i run the script it comes out like this

http://img262.imageshack.us/my.php?image=mtascreen0007ey4.png

any help...?

Link to comment

To be honest... In looking over about 6 times I didn't see what COULD be wrong... Or well, I couldn't see it for those 2 screens...

I did see this: the coordinates for the window are 0,0? In the first screenshot, it more looks like 0.25 and 0.3... Probably not related, but I can't see any other trouble in createSelectWindow()...

Link to comment

you made a typo here

... 
tabCops = guiCreateTab("Cops",tbpCharSelect) 
tabCivs = guiCreateTab("Civilians",tpbCharSelect) 
tabArmy = guiCreateTab("Army",tpbCharSelect) 
... 

you put tpbCharSelect instead of tbpCharSelect for the second and third tabs

Link to comment
you made a typo here

... 
tabCops = guiCreateTab("Cops",tbpCharSelect) 
tabCivs = guiCreateTab("Civilians",tpbCharSelect) 
tabArmy = guiCreateTab("Army",tpbCharSelect) 
... 

you put tpbCharSelect instead of tbpCharSelect for the second and third tabs

And if the parent isn't found, the tab will become a different window. Correct? Must be, since it was wrong for Cops and that one has an whole new window. Right?

Link to comment

k im moved on to spawning the player and have run into another problem ... once the player is spawned the cursor remains onscreen despite the showcursor(false) command

the full client script below....

local localPlayer = getLocalPlayer() 
local localPlayerName = getPlayerName(localPlayer) 
local localRootElement = getRootElement() 
local newUser 
local passwordAttempts = 0 
  
function CreateLoginWindow() 
    wdwLogin = guiCreateWindow(0.375,0.350,0.300,0.250,"Log In v0.1.2",true) 
    guiWindowSetSizable(wdwLogin,false) 
    guiWindowSetMovable(wdwLogin,false) 
  
    guiCreateLabel(0.080,0.200,0.250,0.250,"Username:",true,wdwLogin) 
    guiCreateLabel(0.080,0.450,0.250,0.250,"Password:",true,wdwLogin) 
  
    edtUser = guiCreateEdit(0.380,0.190,0.500,0.150,localPlayerName,true,wdwLogin) 
    guiEditSetReadOnly(edtUser,true) 
    edtPass = guiCreateEdit(0.380,0.440,0.500,0.150,"",true,wdwLogin) 
    guiEditSetMaxLength(edtPass,20) 
    guiEditSetMasked(edtPass,true) 
  
    btnLogin = guiCreateButton(0.630,0.650,0.250,0.150,"Log In",true,wdwLogin) 
  
    guiSetVisible(wdwLogin,false) 
     
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
    function() 
        CreateLoginWindow() 
        lblDisplayArea = guiCreateLabel(0.100,0.800,0.800,0.100,"",true) 
        guiLabelSetHorizontalAlign(lblDisplayArea,"center",true) 
             
        addEventHandler("onClientGUIClick",btnLogin,clientSubmitLogin,false) --Mouseclick on the Login button... 
        addEventHandler("onClientGUIAccepted",edtPass,clientEnterLogin,false) --Hitting 'enter' key in password box... 
  
        triggerServerEvent ("checkValidAct",localPlayer,localPlayerName) --Check if they have an account to log in to... 
    end 
) 
  
function clientNewUserHandler() --Called when no account exists for this players name... 
    newUser = true 
    guiSetText(lblDisplayArea,"No account exists for your username. Please create a password.") 
    if(wdwLogin) then 
        guiSetVisible(wdwLogin,true) 
        guiBringToFront(edtPass) --Puts the cursor into the password box for typing... 
    end 
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
addEvent("clientNewUser",true) 
addEventHandler("clientNewUser",localRootElement,clientNewUserHandler) 
  
function clientReturningUserHandler() --Called when there is an existing account for this player's name... 
    newUser = false 
    guiSetText(lblDisplayArea,"You are using a registered nickname - please enter your password.") 
    if(wdwLogin) then 
        guiSetVisible(wdwLogin,true) 
        guiBringToFront(edtPass) --Puts the cursor into the password box for typing... 
    end 
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
addEvent("clientReturningUser",true) 
addEventHandler("clientReturningUser",localRootElement,clientReturningUserHandler) 
  
function clientEnterLogin() 
    if(newUser) then 
        triggerServerEvent("SubmitCreate",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
    else 
        triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
    end 
end 
  
function clientSubmitLogin(button) 
    if(button == "left") then 
        if(newUser) then 
            triggerServerEvent("SubmitCreate",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
            triggerClientEvent("SelectCreate", getRootElement()) 
        else 
            triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 
            triggerClientEvent("SelectCreate", getRootElement()) 
        end 
    end 
end 
  
function clientDisplayAreaHandler(theMessage) 
    guiSetText(lblDisplayArea,theMessage) 
end 
addEvent("clientDisplayArea",true) 
addEventHandler("clientDisplayArea",localRootElement,clientDisplayAreaHandler) 
  
function clientWrongPasswordHandler(theMessage) 
    passwordAttempts = passwordAttempts + 1 
    if(passwordAttempts > 3) then 
        guiSetText(lblDisplayArea,"Too many incorrect password attempts.  Please disconnect.") 
        destroyElement(wdwLogin) 
        triggerServerEvent("removePlayer",localPlayer) 
    end 
end 
addEvent("clientWrongPassword",true) 
addEventHandler("clientWrongPassword",localRootElement,clientWrongPasswordHandler) 
  
function clientLoginSuccessHandler() 
    guiSetInputEnabled(false) 
    destroyElement(wdwLogin) 
    destroyElement(lblDisplayArea) 
    wdwLogin = nil 
    newUser = nil 
    lblDisplayArea = nil 
    passwordAttempts = nil 
    localPlayer = nil 
    localPlayerName = nil 
    localRootElement = nil 
     
    createSelectWindow()     
     
    addEventHandler("onClientGUIClick",btnCops,clientAssignCops,false) 
     
end 
addEvent("clientLoginSuccess",true) 
addEventHandler("clientLoginSuccess",localRootElement,clientLoginSuccessHandler) 
  
function createSelectWindow() 
    wdwSelect = guiCreateWindow(0.2,0.2,0.7,0.7,"Select a Character Class", true) 
     
    tbpCharSelect = guiCreateTabPanel(0.0622,0.1086,0.8466,0.7629,true,wdwSelect) 
     
    tabCops = guiCreateTab("Cops",tbpCharSelect) 
    tabCivs = guiCreateTab("Civilians",tbpCharSelect) 
    tabArmy = guiCreateTab("Army",tbpCharSelect) 
     
    btnArmy = guiCreateButton(0.0165,0.8264,0.967,0.1504,"Join Team Army!",true,tabArmy) 
    btnCivs = guiCreateButton(0.0165,0.8264,0.967,0.1504,"Join Team Civilians!",true,tabCivs) 
    btnCops = guiCreateButton(0.0165,0.8264,0.967,0.1504,"Join Team Cops!",true,tabCops) 
     
    memCops = guiCreateMemo(0.1293,0.1504,0.7503,0.6594,"Police Sample Text....",true,tabCops) 
    memCivs = guiCreateMemo(0.1293,0.1504,0.7503,0.6594,"Civilian Sample Text...",true,tabCivs) 
    memArmy = guiCreateMemo(0.1293,0.1504,0.7503,0.6594,"Army Sample Text...",true,tabArmy) 
     
    lblCops = guiCreateLabel(0.294,0.0017,0.4144,0.1722,"Team Cops",true,tabCops) 
    guiSetFont(lblCops,"sa-gothic") 
    lblCivs = guiCreateLabel(0.35,0.0017,0.4144,0.1722,"Civilians",true,tabCivs) 
    guiSetFont(lblCivs,"sa-gothic") 
    lblArmy = guiCreateLabel(0.294,0.0017,0.4144,0.1722,"Team Army",true,tabArmy) 
    guiSetFont(lblArmy,"sa-gothic") 
  
end 
  
function clientAssignCops(button) 
         
        if (button == "left") then 
         
            triggerServerEvent("assignCopTeam",getRootElement()) 
            guiSetVisible(wdwSelect, false) 
            guiSetInputEnabled(false) 
            showcursor(false) 
             
        end 
end      

and the server script below

local welcomeMessageNewUser = "Welcome to our server!" 
local welcomeMessageReturningUser = "Welcome back to the server!" 
  
function createTeamsOnStart () 
  
        teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) 
        teamCops = createTeam ( "LSPD", 101, 101, 215 ) 
        teamArmy = createTeam ( "Army", 26, 51, 0 ) 
end 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function clientAttemptLogin(username,password) 
    local userAccount = getAccount(username) 
    local tryToLog 
    if (client) then 
        tryToLog = logIn(client,userAccount,password) 
        if (tryToLog) then 
            outputChatBox(welcomeMessageReturningUser,client) 
            triggerClientEvent(source,"clientLoginSuccess",getRootElement()) 
        else 
            triggerClientEvent(source,"clientDisplayArea",getRootElement(),"Incorrect password, please try again.") 
            triggerClientEvent(source,"clientWrongPassword",getRootElement()) 
        end 
    end 
end 
addEvent("SubmitLogin",true) 
addEventHandler("SubmitLogin",getRootElement(),clientAttemptLogin) 
  
function clientAttemptCreate(username,password) 
    if (password ~= nil and password ~= "") then 
        addAccount(username,password) 
        local userAccount = getAccount(username) 
        local tryToLog 
        if (client and userAccount ~= false and userAccount ~= nil) then 
            tryToLog = logIn(client,userAccount,password) 
            if (tryToLog) then 
                outputChatBox(welcomeMessageNewUser,client) 
                triggerClientEvent(source,"clientLoginSuccess",getRootElement()) 
            else 
                triggerClientEvent(source,"clientDisplayArea",getRootElement(),"Unable to log in to new account, try again.") 
            end 
        else 
            triggerClientEvent(source,"clientDisplayArea",getRootElement(),"Unable to create new account, try again.") 
        end 
    else 
        triggerClientEvent(source,"clientDisplayArea",getRootElement(),"Please create a password for your new account.") 
    end 
end 
addEvent("SubmitCreate",true) 
addEventHandler("SubmitCreate",getRootElement(),clientAttemptCreate) 
  
function checkValidActHandler(thePlayer) 
    local theAccount = getAccount(thePlayer) 
    if (theAccount) then 
        triggerClientEvent(source,"clientReturningUser",getRootElement()) 
    else 
        triggerClientEvent(source,"clientNewUser",getRootElement()) 
    end 
end 
addEvent("checkValidAct",true) 
addEventHandler("checkValidAct",getRootElement(),checkValidActHandler) 
  
function removePlayerHandler() 
    kickPlayer(source) 
end 
addEvent("removePlayer",true) 
addEventHandler("removePlayer",getRootElement(),removePlayerHandler) 
  
function assignCopTeam () 
   
  local spawnX = 1552.4109 
  local spawnY = -1675.0485 
  local spawnZ = 16.1953 
  spawnPlayer(client,spawnX,spawnY,spawnZ) 
  fadeCamera(client,true) 
   
  setPlayerTeam (client, teamCops) 
  giveWeapon (client, 31, 10000 ) 
  giveWeapon (client, 24, 10000 ) 
  giveWeapon (client, 25, 10000 ) 
  giveWeapon (client, 29, 10000 ) 
  giveWeapon (client, 17, 10000 ) 
  giveWeapon (client, 42, 10000 ) 
  setPlayerArmor (client, 0 ) 
  setPlayerSkin (client, 280 ) 
  setPlayerNametagColor (client, 101, 101, 215 ) 
   
end 
addEvent("assignCopTeam",true) 
addEventHandler("assignCopTeam",getRootElement(), assignCopTeam) 
  
function afterWasted() 
     respawnPlayer(source, getPlayerTeam(source)) 
end 
  
function respawnPlayer(source, theTeam) 
  local spawnX = 1552.4109 
  local spawnY = -1675.0485 
  local spawnZ = 16.1953 
  spawnPlayer(client,spawnX,spawnY,spawnZ) 
  fadeCamera(client,true) 
   
  setPlayerTeam (client, teamCops) 
  giveWeapon (client, 31, 10000 ) 
  giveWeapon (client, 24, 10000 ) 
  giveWeapon (client, 25, 10000 ) 
  giveWeapon (client, 29, 10000 ) 
  giveWeapon (client, 17, 10000 ) 
  giveWeapon (client, 42, 10000 ) 
  setPlayerArmor (client, 0 ) 
  setPlayerSkin (client, 280 ) 
  setPlayerNametagColor (client, 101, 101, 215 ) 
   
end 
  
addEventHandler( "onPlayerWasted", getRootElement(), afterWasted ) 

and help....would be greatly appreciated (again :D )....

Link to comment

using the code i posted above it works great with the cursor fix but when someone else joins the server the select screen shows up for all players if they are in game or not .... whats the problem....? im guessing its something like needing to specify that only the player joining should see it but i dont know how to do that....

Link to comment

You first trigger Server event like this, which is right

triggerServerEvent ("checkValidAct",localPlayer,localPlayerName) --Check if they have an account to log in to... 

But then you trigger it with source being root element :S

triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 

When the source is root element (not the localplayer), then the source here

  
if (tryToLog) then  
outputChatBox(welcomeMessageReturningUser,client) 
triggerClientEvent(source,"clientLoginSuccess",getRootElement()) 
else 
triggerClientEvent(source,"clientDisplayArea",getRootElement(),"Incorrect password, please try again.") 
triggerClientEvent(source,"clientWrongPassword",getRootElement()) 
end 

is also root element, as the event you triggered called this function.. So it triggers this client side event for all clients. What you have to do is change

triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass)) 

into

triggerServerEvent("SubmitLogin",localPlayer,guiGetText(edtUser),guiGetText(edtPass)) 

And that for all the triggerServerEvents that you use there.. If you want the source to be the local player

Makes more sense?

Link to comment

thanks worked perfectly but i have another question :P does anyone know how to do random events (if they have those in lua)....so i have 3 spawn points and i want the people to randomly spawn at the different spawn points....so when you choose a team everyone doesnt spawn in the exact same place... any help...?

Link to comment
thanks worked perfectly but i have another question :P does anyone know how to do random events (if they have those in lua)....so i have 3 spawn points and i want the people to randomly spawn at the different spawn points....so when you choose a team everyone doesnt spawn in the exact same place... any help...?

Yes, I use this method:

spawnpoint={{0,0,3}, {500,500,30}, {-500,-500,30}} --creates table/array spawnpoint with a few spawnpoints. (between { and }, xyz) 
  
function spawnThePlayerOfWhoIDontKnowTheNameYouSee(player) 
    local spawnNo=math.random(1,#spawnpoint) -- this will draw a random ROUND number, starting at 1 and ending at how much spawnpoints the table contains. 
    local a=spawnpoint[spawnNo] -- put the chosen spawnpoint in a local variable. Makes it a bit easier  
    spawnPlayer(player,a[1],a[2],a[3]) -- spawn the player at the given spawnpoint 
end 
addCommandHandler("spawn",spawnThePlayerOfWhoIDontKnowTheNameYouSee) -- usually, I don't use command handlers in these cases  

So it might still have some bugs/typo's, but this is how I do it. :P

Link to comment
thanks worked perfectly but i have another question :P does anyone know how to do random events (if they have those in lua)....so i have 3 spawn points and i want the people to randomly spawn at the different spawn points....so when you choose a team everyone doesnt spawn in the exact same place... any help...?

Yes, I use this method:

spawnpoint={{0,0,3}, {500,500,30}, {-500,-500,30}} --creates table/array spawnpoint with a few spawnpoints. (between { and }, xyz) 
  
function spawnThePlayerOfWhoIDontKnowTheNameYouSee(player) 
    local spawnNo=math.random(1,#spawnpoint) -- this will draw a random ROUND number, starting at 1 and ending at how much spawnpoints the table contains. 
    local a=spawnpoint[spawnNo] -- put the chosen spawnpoint in a local variable. Makes it a bit easier  
    spawnPlayer(player,a[1],a[2],a[3]) -- spawn the player at the given spawnpoint 
end 
addCommandHandler("spawn",spawnThePlayerOfWhoIDontKnowTheNameYouSee) -- usually, I don't use command handlers in these cases  

So it might still have some bugs/typo's, but this is how I do it. :P

You should pull the spawn points from a map file, don't specify them in lua. Use getElementsByType.

Link to comment
You should pull the spawn points from a map file, don't specify them in lua. Use getElementsByType.

Why is it better to put it in a map file, actually?

Usually more adaptable. Not really better if you want to keep something for yourself and don't want to change it, but in examples it's always better to show the map file way I think.

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