knightscript Posted February 19, 2016 Share Posted February 19, 2016 Hello, I have a doubt, i would like to know if there is a way to output the account name of all accounts that have for example the AccountData "admin", if there is a way what functions should I use, thanks! Link to comment
tosfera Posted February 19, 2016 Share Posted February 19, 2016 use GetAccounts to get the accounts, after that loop over the accounts with a simple; "for i = 1, #var", use getAccountData to see if the player has that data. Link to comment
knightscript Posted February 19, 2016 Author Share Posted February 19, 2016 Thanks @tosfera, one more question, is there a way to set an account data of an account that is offline? this is what I am trying: local offlineacc = getAccount(online) local antihead = setAccountData( offlineacc, "antiheadshot", "on" ) local antiheadexpire = setAccountData( offlineacc, "antiheadexpira", ending) but i think the problem is I need to write the password in, and I dont have that, thanks EDIT: just checked out "password" is an optional argument, but I am getting this error on debugscript: [12:40:30] WARNING: [gameplay]/headshot/vipantiheadshot.lua:15: Bad argument @ ' setAccountData' [Expected account at argument 1, got boolean] LINE 15: local antiheadexpire = setAccountData( offlineacc, "antiheadexpira", ending) EDIT: fixed it, i was passing the wrong variable, in getAccount, thanks!. Link to comment
knightscript Posted February 19, 2016 Author Share Posted February 19, 2016 (edited) Hello, going back to the output thing, I have never used "FOR" before, I´ve searched on google but haven´t found anything, can you give me a small example or a usage tutorial? thanks. EDIT: Found this tutorial: https://wiki.multitheftauto.com/wiki/GetAllElementData gonna adapt it to what I need, thanks Edited February 19, 2016 by Guest Link to comment
tosfera Posted February 19, 2016 Share Posted February 19, 2016 it's quite simple; local allAccounts = getAccounts(); for i = 1, do -- you can simply say getAccountData ( allAccounts [ i ], "key" ); end Link to comment
knightscript Posted February 19, 2016 Author Share Posted February 19, 2016 Thanks tosfera, one last thing, this is my code: function printAllData ( thePlayer ) local allAccounts = getAccounts(); for i = 1,#allAccounts do local account = getAccountName( allAccounts[i] ) local text = getAccountData (allAccounts[i], "antiheadshot" ); outputChatBox("ACCOUNT: "..account.."RESULT: "..text) end end addCommandHandler( "getall", printAllData ) I would like to show the account that has the account data, this shows the first entry but it gives me an error on debugscript: [13:17:55] ERROR: [gameplay]/headshot/vipantiheadshot.lua:33: attempt to concate nate local 'text' (a boolean value) Thanks!. EDIT: It was happening because an account doesnt have that accountdata, is there a way to skip it or just show N/A for example? thanks!. EDIT: Fixed it, hahaha, i just added an else, which shows N/A instead of the result of the local "text", here is my full code for someone that needs it: function printAllData ( thePlayer ) local allAccounts = getAccounts(); for i = 1,#allAccounts do local account = getAccountName( allAccounts[i] ) local text = getAccountData (allAccounts[i], "antiheadexpira" ); if (text) then outputChatBox("cuenta: "..account.."TEXTO: "..text) else outputChatBox("cuenta: "..account.."TEXTO: N/A") end end end addCommandHandler( "getall", printAllData ) Link to comment
tosfera Posted February 19, 2016 Share Posted February 19, 2016 You can do that with a ternary statement. That'll keep it smaller, like so; outputChatBox ( "cuenta: ".. account .." TEXTO: ".. ( text and text or "N/A" ) ) This actually says; if ( text ) then text or "N/A". So, if the text isn't false ( so it has some data ), it'll add the text after that outputchatbox. Else it'll add "N/A". Link to comment
knightscript Posted February 19, 2016 Author Share Posted February 19, 2016 Thanks so much tosfera! always helping me out Link to comment
tosfera Posted February 19, 2016 Share Posted February 19, 2016 No problem, glad I could help. (: 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