scaryface87 Posted August 9, 2014 Share Posted August 9, 2014 Hello , I would like to know how too know if a thing is already used for example if i want to buy a name and the name is already used it says "its already in use" I tried already some things and im willing to LEARN how to get this working I know i dont have every function yet if im right but im willing to learn since im out of clue function getName() name = guiGetText(editbox) -- to get the name inside the box if name then outputChatBox("Does this works?") -- debugger if that code up works setElementData(thePlayer,"name") -- not sure about this one too if it gets the name wich is in the box or not end -- the gui function guiOpen() window1 = guiCreateWindow(243, 147, 305, 264, "Buy your name!", false) guiWindowSetSizable(window1, false) editbox = guiCreateEdit(44, 62, 212, 28, "", false, window1) label = guiCreateLabel(46, 44, 206, 18, "Put here your name :", false, window1) button1 = guiCreateButton(23, 232, 74, 22, "Done", true, window1) guiSetProperty(button1, "NormalTextColour", "FF36FC01") addEventHandler("onClientGUIClick",button1,done) --- event button2 = guiCreateButton(182, 232, 74, 22, "Cancel", true, window1) guiSetProperty(button2, "NormalTextColour", "FFFE0000") addEventHandler("onClientGUIClick",button2,cancel) --- event end addCommandHandler("buyname",guiOpen) function cancel() guiSetVisible(false) end addEvent("cancel",true) addEventHandler("cancel",getRootElement(),cancel) function done() guiSetVisible(false) -- idk what to put here end addEvent("done",true) addEventHandler("done",getRootElement(),done) Greetings , Scaryface87 Link to comment
Castillo Posted August 9, 2014 Share Posted August 9, 2014 Well, you could use element data to set it, and then loop all the players and see if any of them has that element data. getElementsByType getElementData http://www.lua.org/pil/4.3.4.html Link to comment
scaryface87 Posted August 9, 2014 Author Share Posted August 9, 2014 Hello , I dont think that will work since it sets a elemtndata to everyone then if im right?(else u cant loop to all players to see if he has the elementdata) Or do u mean that it loops every player's elementdata? If so i can use it normal is it like this? : for i,v in ipairs getElementsByType("players") if getElementData(v,"name") then outputChatBox("This name is already taken!!") else outputChatBox("Congratz! this name is yours") setElementData(player,"name") Greetings , scaryface87 Link to comment
Max+ Posted August 9, 2014 Share Posted August 9, 2014 remove s form 'players' "player": A player connected to the server Link to comment
scaryface87 Posted August 9, 2014 Author Share Posted August 9, 2014 remove s form 'players'"player": A player connected to the server Sorry but dont i have to use "players" since u said" "player" : a player connected to the server " cuz i want to check if someone got it or not , even if hes ofline so if someone got the name and hes ofline , i cant take it Link to comment
Max+ Posted August 10, 2014 Share Posted August 10, 2014 well i think you have to use getAccountData --- get the players name setAccountData --- set players name and save it to account Link to comment
Et-win Posted August 10, 2014 Share Posted August 10, 2014 If you do that, all players will need an account. So, also check or they are logged in @ scaryface87 Link to comment
Max+ Posted August 10, 2014 Share Posted August 10, 2014 If you do that, all players will need an account. So, also check or they are logged in @ scaryface87 Exactly They Must have account to store the name and if he logged in his name will change to the old one he saved and if any one tryed to store a name alredy another player have outputMsg to player you Should Use tabel or , XML to store them so they wont be lost . Link to comment
scaryface87 Posted August 10, 2014 Author Share Posted August 10, 2014 Ok so like this ; but i dont think it gonna look at everyones account no? local playerAccount = getPlayerAccount(source) -- get his account not sure if its from everyone's if (playerAccount) then if getAccountData(playerAccount,"name") then outputChatBox("This name is already taken!!") else outputChatBox("Congratz! this name is yours") setAccountData(playerAccount,"name") Link to comment
scaryface87 Posted August 11, 2014 Author Share Posted August 11, 2014 Hm not working is it even possible with this? else i just do it with the players online! cuz i dont have knowledge with SQL Link to comment
Drakath Posted August 11, 2014 Share Posted August 11, 2014 Source is the player who triggered the event. I think what you want is to get the account with a specific username. getAccount Link to comment
scaryface87 Posted August 11, 2014 Author Share Posted August 11, 2014 i want everyones account actualy Link to comment
Et-win Posted August 11, 2014 Share Posted August 11, 2014 The only thing I can think of to do this, is using the database. You can also save every name in a XML file. Link to comment
scaryface87 Posted August 11, 2014 Author Share Posted August 11, 2014 Hm can you maybe help me to learn how to use database? (sql if im right?) let me try it already ; (sorry if its that bad) function createSQL() executeSQLCreateTable ( "names", "account TEXT,name TEXT" ) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),createSQL) function test() name = executeSQLSelect ( "names", "account", "name = '" .. sourcename .. "'" ) -- stuck here end Link to comment
Castillo Posted August 11, 2014 Share Posted August 11, 2014 function test ( ) local data = executeSQLQuery ( "SELECT account FROM names WHERE name = ?", tostring ( sourcename ) ) if ( data ) then -- If there is data local account = data [ 1 ] [ "account" ] -- Get the account from it -- stuck here end end Link to comment
scaryface87 Posted August 11, 2014 Author Share Posted August 11, 2014 For knowing if its used or not should i do something like this ; local test = data [2] ["name"] if name = test then ? (this is just a guess) Or should i do it otherS? Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now