Jump to content

Using tables with if statement


Egekan

Recommended Posts

Posted

Hello, I'm a newbie scripter and I'm trying to script somethings for fun. I have a private scripting server. I have an accesspanel gui, there are some dev. access codes(passwords) to login as a scripter. Is is possible to use allow some poeple login with their own codes?

First one checks if the code which is in the editbox is exists or not. As you see if it does, the person will be able to click the button.

function devenable() 
local acscodes = {"1234", "1231"} 
  
if guiGetText(accesscode.edit) == acscodes then -- Checks if the code is valid or not. 
guiSetEnabled(connect.button, true) 
else 
guiSetEnabled(connect.button, false) 
end 
end 
setTimer(devenable, 1000,0) 
  
  
  
function devaccess() 
if guiGetEnabled(connect.button,true) then 
guiSetVisible(ServAccess.window, false) 
showCursor(false) 
end 
if guiGetText(accesscode.edit) == acscodes[1] then 
outputChatBox("Hello, Egekan. Developer Mode is enabled!", 0, 200, 0) 
elseif guiGetText(accesscode.edit) == acscodes[2] then 
outputChatBox("Hello, AnyPerson. Developer Mode is enabled!", 0, 200, 0) 
end 
end 
addEventHandler("onClientGUIClick", connect.button, devaccess) 
  

it's fine if I use this one instead, which means the script is good enough :lol::lol:

local acscodes = 1234 

Thank you for helping

Posted (edited)

You've put the table locally in your devenable function.

Put it above the function or remove local then devaccess function should work.

Edited by Guest
Posted

use this:

local acscodes = {"1234", "1231"} 
  
local passwordEntred = guiGetText(accesscode.edit) 
if  passwordEntred ~= "" then 
    for _,password in pairs (acscodes) do 
        if passwordEntred == password then  
            -- your code here 
        end  
    end  
end  

Posted

Take Walid's example and use this

outputChatBox("Hello, "..getPlayerName(localPlayer)..". Developer Mode is enabled!", 0, 200, 0) 

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