Headshot4Fun Posted September 10, 2011 Share Posted September 10, 2011 (edited) here goes the problem. Im making a rpg server, and im scripting like everything... anyway this is the real problem: my account system works like that: 1. You create your account 2. Choose your charater name 3. And we save the charater name in your account (setAccountData) Now, how can i detect if this name is already in use by another account, because getAccountData/setAccountData only works when the player is LOGGED IN. Is there another way? Because I Tried XML they told me XML its not the best idea because it can lag as hell the server, and mysql i don't understand the wiki exemples... are they trolling me? Thanks! Edited September 11, 2011 by Guest Link to comment
Castillo Posted September 11, 2011 Share Posted September 11, 2011 Do you mean, you want to check EVERY account for that character name? Link to comment
Headshot4Fun Posted September 11, 2011 Author Share Posted September 11, 2011 Do you mean, you want to check EVERY account for that character name?Exactly, so i can detect if the name is already in use. Link to comment
JR10 Posted September 11, 2011 Share Posted September 11, 2011 for index , account in ipairs ( getAccounts () ) do if getAccountData ( account , "charName" ) == newCharName then outputChatBox("BLABLA" , player ) return end end This will check if the account data == something, if so it will return (stops the rest of the code execution) Needs edit. I hope I understood you correctly. Link to comment
Headshot4Fun Posted September 11, 2011 Author Share Posted September 11, 2011 for index , account in ipairs ( getAccounts () ) do if getAccountData ( account , "charName" ) == newCharName then outputChatBox("BLABLA" , player ) return end end This will check if the account data == something, if so it will return (stops the rest of the code execution) Needs edit. I hope I understood you correctly. But it will even check for offline accounts? Link to comment
Castillo Posted September 11, 2011 Share Posted September 11, 2011 getAccounts() returns ALL server accounts, offline or online. Link to comment
Headshot4Fun Posted September 11, 2011 Author Share Posted September 11, 2011 (edited) getAccounts() returns ALL server accounts, offline or online.Hm, i get it.Thanks JR and Solid for helping me to solve this puzzle. Now i have everything that my server needs to work! Edited September 11, 2011 by Guest Link to comment
Headshot4Fun Posted September 11, 2011 Author Share Posted September 11, 2011 You welcome.Don't take this as offtopic, but lol, 1360 is the X resolution of my screen.Now admin/mod please close it or i will keep making offtopic posts here D: Link to comment
qaisjp Posted September 11, 2011 Share Posted September 11, 2011 Headshot4Fun, i recommend you create an sql table with a list of account names and their data using SQLite (it's inbuilt, not mysql) Link to comment
50p Posted September 11, 2011 Share Posted September 11, 2011 Headshot4Fun, i recommend you create an sql table with a list of account names and their data using SQLite (it's inbuilt, not mysql) As far as I remember, MTA uses SQL for accounts unless it's changed again but I doubt. So, no need to create another table for that. Link to comment
qaisjp Posted September 11, 2011 Share Posted September 11, 2011 Headshot4Fun, i recommend you create an sql table with a list of account names and their data using SQLite (it's inbuilt, not mysql) As far as I remember, MTA uses SQL for accounts unless it's changed again but I doubt. So, no need to create another table for that. it does, but using sql functions is better than acctn data. sometimes. Link to comment
Headshot4Fun Posted September 11, 2011 Author Share Posted September 11, 2011 So, this should work, after all, but debugscript keep saying: ERROR: ... server.lua:48: attempt to call a table value But the fun part, is that THATS what im trying to do... heres relevantpart the code. This basically checks a account data in all accounts, compare them if they are the same you input ( nome ) and add them to a table ( resultado ) then it checks if theres results, if theres results: -- fail, else -- works! function checarConta(nome) local resultado = {} for i,v in getAccounts() do if getPlayerData(v,"char.nome") == nome then table.insert(resultado,v) return else end end if resultado[1] then -- Fail elseif not resultado[1] then -- Win! end end addEventHandler ( "checarConta", getRootElement ( ), checarConta) Im trying to make this way so there is no floods, because otherwise, i would receive alot of -- works and only one --fail if there is one. Link to comment
JR10 Posted September 11, 2011 Share Posted September 11, 2011 What is getPlayerData. And specify the error line. Link to comment
bandi94 Posted September 11, 2011 Share Posted September 11, 2011 this is wrong for i,v in getAccounts() do it need to be for i,v in pairs(getAccounts()) do and getPlayerData is not a function that need to getAccountData(v,"char.none") and on tabel insert you instert whit v the account now i don't know if you wanna insert the account or the account data and if the "nome" is not a local nome = ... the need to be "nome" not nome function checarConta(nome) local resultado = {} for i,v in pairs (getAccounts()) do if getAccountData(v,"char.nome") == nome then table.insert(resultado,v) return else end end if resultado[1] then -- Fail elseif not resultado[1] then -- Win! end end addEventHandler ( "checarConta", getRootElement ( ), checarConta) Link to comment
Headshot4Fun Posted September 11, 2011 Author Share Posted September 11, 2011 What is getPlayerData.And specify the error line. Oh, what a idiot am i... changing it...this is wrong for i,v in getAccounts() do it need to be for i,v in pairs(getAccounts()) do and getPlayerData is not a function that need to getAccountData(v,"char.none") and on tabel insert you instert whit v the account now i don't know if you wanna insert the account or the account data and if the "nome" is not a local nome = ... the need to be "nome" not nome I Know, but for some reason i forgot it. Well, thats what happens when you try to script a gamemod at 3:00 am.Edit shit, i can't just make it works. it returns the --fail when should return --true, and also, doen't return --true. Can some one help me to make this function, it should searches a accountData in all accounts and return false if someone have it, and true if noone haves it. Heres the full relevant code: function checarConta(nome) local resultado = {} for i,v in pairs (getAccounts()) do if getAccountData(v,"char.nome") == tostring(nome) then return else table.insert(resultado,v) end end outputChatBox(resultado[1],source) if resultado[1] then --resultado={} outputChatBox("Fails",source) elseif not resultado[1] then outputChatBox("Works",source) setElementDimension ( source, 0) setPlayerName ( source,tostring(nome) ) local UsuarioCn = getPlayerAccount(source) setAccountData(UsuarioCn,"char.passouNoTutorial",true) setAccountData(UsuarioCn,"char.nome",nome) triggerClientEvent ( source, "DetectarNomeWin", source) end end addEventHandler ( "checarConta", getRootElement ( ), checarConta) Link to comment
Cadu12 Posted September 11, 2011 Share Posted September 11, 2011 Are you making chars 10 per account? Link to comment
JR10 Posted September 11, 2011 Share Posted September 11, 2011 Actually, if the char name exists, there will be no resultado [ 1 ], so basically you are reversing it. function checarConta(nome) local resultado = {} for i,v in pairs (getAccounts()) do if getAccountData(v,"char.nome") == tostring(nome) then return else table.insert(resultado,v) break end end outputChatBox(resultado[1],source) if not resultado[1] then --resultado={} outputChatBox("Fails",source) elseif resultado[1] then outputChatBox("Works",source) setElementDimension ( source, 0) setPlayerName ( source,tostring(nome) ) local UsuarioCn = getPlayerAccount(source) setAccountData(UsuarioCn,"char.passouNoTutorial",true) setAccountData(UsuarioCn,"char.nome",nome) triggerClientEvent ( source, "DetectarNomeWin", source) end end addEventHandler ( "checarConta", getRootElement ( ), checarConta) Link to comment
Headshot4Fun Posted September 11, 2011 Author Share Posted September 11, 2011 Actually, if the char name exists, there will be no resultado [ 1 ], so basically you are reversing it. function checarConta(nome) local resultado = {} for i,v in pairs (getAccounts()) do if getAccountData(v,"char.nome") == tostring(nome) then return else table.insert(resultado,v) break end end outputChatBox(resultado[1],source) if not resultado[1] then --resultado={} outputChatBox("Fails",source) elseif resultado[1] then outputChatBox("Works",source) setElementDimension ( source, 0) setPlayerName ( source,tostring(nome) ) local UsuarioCn = getPlayerAccount(source) setAccountData(UsuarioCn,"char.passouNoTutorial",true) setAccountData(UsuarioCn,"char.nome",nome) triggerClientEvent ( source, "DetectarNomeWin", source) end end addEventHandler ( "checarConta", getRootElement ( ), checarConta) Worked, thanks man. Now i tested with some of my friend and it worked.Thanks bro ;D 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