ReeferMadness Posted October 24, 2016 Share Posted October 24, 2016 I need to find out how to find a player by checking for their account data for an SMS system. When you buy a phone, it gives you a random 6 digit number then sets it under your account data, this way you are able to have the same number every time you log in. Now, in my gui I have an edit box/memo for typing in a # and message, then it triggers a server event which checks: 1.)is the number entered stored in an account data and 2.)Who is the player that has that specific number. How do I do this? Link to comment
Captain Cody Posted October 24, 2016 Share Posted October 24, 2016 (edited) You could store it in an SQL database. https://wiki.multitheftauto.com/wiki/ExecuteSQLQuery Also you could use tables to keep track of who is online - number = {} number[player] = getAccountData(getPlayerAccount(player),"phoneNumber") Edited October 24, 2016 by CodyL Link to comment
ReeferMadness Posted October 24, 2016 Author Share Posted October 24, 2016 11 minutes ago, CodyL said: You could store it in an SQL database. https://wiki.multitheftauto.com/wiki/ExecuteSQLQuery Also you could use tables to keep track of who is online - number = {} number[player] = getAccountData(getPlayerAccount(player),"phoneNumber") What is SQL? Im looking over some of the documentation and it's making my head spin haha Link to comment
Captain Cody Posted October 24, 2016 Share Posted October 24, 2016 (edited) Give me a bit and I'll have an example ready. Here's just a quick example set up I threw together, with enough work it could be turned into a functional script. executeSQLQuery("CREATE TABLE IF NOT EXISTS `phoneNumbers` (`number` NUMERIC,`name` TEXT)") executeSQLQuery("CREATE TABLE IF NOT EXISTS `Messages` (`number` NUMERIC,`Snumber` NUMERIC,`text` TEXT)") -- Retreive source account name / check if said number exists -- Usage // local NumbersOwner = checkIfItExits(phoneNumber) function checkIfItExits(number) return executeSQLQuery("SELECT `name` FROM `phoneNumbers` WHERE `number`=?", number ) end -- Add a phone number -- Usage // addNumber(theNumber,AccountNameOfOwner) function addNumber(number,accountName) executeSQLQuery("INSERT INTO `phoneNumbers`(`number`,`name`) VALUES(?,?,?)", number, accountName ) end -- Send a message -- Usage // dropMessage(tonumber,fromnumber,text) function dropMessage(number,sourceNumber,text) if checkIfItExits(number) then executeSQLQuery("INSERT INTO `Messages`(`number`,`Snumber`,`text`) VALUES(?,?,?)", number, sourceNumber, text ) end end -- Retreive a persons messages -- Usage // getMessages(personsNumber) // Returns a table table[1] = text table[2] = fromNumber table[3] = senders name function getMessages(number) local table = {} local messages = executeSQLQuery("SELECT `*` FROM `Messages` WHERE `number`=?", number ) for i,v in pairs(messages) do local text = v.text local sourceNumber = v.Snumber local SourceName = checkIfItExits(sourceNumber) table.insert(table,{text,sourceNumber,SourceName}) end return table end -- Update a message -- Usage // updateMessage(originalMessage,newMessage) // Returns true or false 'I think' function updateMessage(originalMessage,newMessage) return executeSQLQuery("UPDATE `Messages` SET `text`=? WHERE `name`=?", newMessage, originalMessage) end If you have any questions ask em, and I'll try to answer them. Edited October 24, 2016 by CodyL New Additon Link to comment
ReeferMadness Posted October 24, 2016 Author Share Posted October 24, 2016 15 hours ago, CodyL said: Give me a bit and I'll have an example ready. Here's just a quick example set up I threw together, with enough work it could be turned into a functional script. executeSQLQuery("CREATE TABLE IF NOT EXISTS `phoneNumbers` (`number` NUMERIC,`name` TEXT)") executeSQLQuery("CREATE TABLE IF NOT EXISTS `Messages` (`number` NUMERIC,`Snumber` NUMERIC,`text` TEXT)") -- Retreive source account name / check if said number exists -- Usage // local NumbersOwner = checkIfItExits(phoneNumber) function checkIfItExits(number) return executeSQLQuery("SELECT `name` FROM `phoneNumbers` WHERE `number`=?", number ) end -- Add a phone number -- Usage // addNumber(theNumber,AccountNameOfOwner) function addNumber(number,accountName) executeSQLQuery("INSERT INTO `phoneNumbers`(`number`,`name`) VALUES(?,?,?)", number, accountName ) end -- Send a message -- Usage // dropMessage(tonumber,fromnumber,text) function dropMessage(number,sourceNumber,text) if checkIfItExits(number) then executeSQLQuery("INSERT INTO `Messages`(`number`,`Snumber`,`text`) VALUES(?,?,?)", number, sourceNumber, text ) end end -- Retreive a persons messages -- Usage // getMessages(personsNumber) // Returns a table table[1] = text table[2] = fromNumber table[3] = senders name function getMessages(number) local table = {} local messages = executeSQLQuery("SELECT `*` FROM `Messages` WHERE `number`=?", number ) for i,v in pairs(messages) do local text = v.text local sourceNumber = v.Snumber local SourceName = checkIfItExits(sourceNumber) table.insert(table,{text,sourceNumber,SourceName}) end return table end -- Update a message -- Usage // updateMessage(originalMessage,newMessage) // Returns true or false 'I think' function updateMessage(originalMessage,newMessage) return executeSQLQuery("UPDATE `Messages` SET `text`=? WHERE `name`=?", newMessage, originalMessage) end If you have any questions ask em, and I'll try to answer them. I get: Database query failed: 3 values for 2 columns for the addNumber function. Link to comment
pa3ck Posted October 24, 2016 Share Posted October 24, 2016 Remove one of the question marks in VALUES (?,?,?) in the addNumber function. Link to comment
Walid Posted October 24, 2016 Share Posted October 24, 2016 All what you need is : -- check if the number is stored in account data + get the account name of the owner function isStoredNumber(number) if number and tonumber(number) then local accounts = getAccounts() local owner = false for i=1, #accounts do local storedNumbers = getAccountData(accounts[i],"phoneNumber") if (tonumber(storedNumbers) == number) then owner = getAccountName(accounts[i]) break end end -- get the number owner if owner then return owner end end return false end Example how to use it local number = 331144 local owner = isStoredNumber(number) -- check if it's a stored number if owner then outputChatBox(owner) -- output the account name of the owner end Link to comment
Captain Cody Posted October 24, 2016 Share Posted October 24, 2016 That certainly works to. 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