gaghaufgy Posted August 19, 2020 Posted August 19, 2020 Ok so , i wanna generate a phone number with 10numbers the first 3 numbers i want them to be 076 , and the rest randomly generated , and the whole number to have 10characters , not more , not less! I've got this in my script local attempts = 0 local itemValue = 1 while true do attempts = attempts + 1 itemValue = math.random(311111, attempts < 20 and 899999 or 8999999) local mysqlQ = mysql:query("SELECT `phonenumber` FROM `phones` WHERE `phonenumber` = '" .. itemValue .. "'") if mysql:num_rows(mysqlQ) == 0 then mysql:free_result(mysqlQ) break end mysql:free_result(mysqlQ) end
Moderators Patrick Posted August 19, 2020 Moderators Posted August 19, 2020 local number = "076" .. math.random(1000000, 9999999) 1 community profile | map converters | map images | pDownloader | pAttach | model encrypter
gaghaufgy Posted August 19, 2020 Author Posted August 19, 2020 Thank you Patrick, i'm experimenting on allready made scripts with the purpose of learning. I wanna learn more about scripting and stuff , one day i ll make my own gamemode from zero!
Moderators Patrick Posted August 19, 2020 Moderators Posted August 19, 2020 2 minutes ago, gaghaufgy said: Thank you Patrick, i'm experimenting on allready made scripts with the purpose of learning. I wanna learn more about scripting and stuff , one day i ll make my own gamemode from zero! Good to hear, here are some excellent resources to learn the basics of Lua scripting: - https://wiki.multitheftauto.com/wiki/Main_Page - https://wiki.multitheftauto.com/wiki/Scripting_Introduction - https://www.lua.org/manual/5.1/ - https://wiki.multitheftauto.com/wiki/Category:Tutorials - https://forum.multitheftauto.com/topic/64228-the-ultimate-lua-tutorial/ - https://forum.multitheftauto.com/topic/34453-manuals - https://forum.multitheftauto.com/topic/121619-lua-for-absolute-beginners - https://forum.multitheftauto.com/topic/95654-tut-debugging/ - https://forum.multitheftauto.com/topic/114541-tut-events/ - https://forum.multitheftauto.com/topic/117472-tut-scaling-dx/ community profile | map converters | map images | pDownloader | pAttach | model encrypter
gaghaufgy Posted August 19, 2020 Author Posted August 19, 2020 This is what i did local attempts = 0 local itemValue = 1 while true do attempts = attempts + 1 itemValue = "076" .. math.random(1000000, 9999999) --I edited here. local mysqlQ = mysql:query("SELECT `phonenumber` FROM `phones` WHERE `phonenumber` = '" .. itemValue .. "'") if mysql:num_rows(mysqlQ) == 0 then mysql:free_result(mysqlQ) break end For some reason the number "0" doesn't appear the number looks like this : 76(and the rest of random numbers)
Moderators Patrick Posted August 19, 2020 Moderators Posted August 19, 2020 (edited) 8 minutes ago, gaghaufgy said: For some reason the number "0" doesn't appear Probably because you store the phonenumber as Integer in database, and you can't start a number with 0. (so 011 equals to 11) Change phonenumber's type to VARCHAR in database. Edited August 19, 2020 by Patrick community profile | map converters | map images | pDownloader | pAttach | model encrypter
gaghaufgy Posted August 19, 2020 Author Posted August 19, 2020 (edited) https://imgur.com/a/UOAOQBV I managed to change it but... that didn't seem to fix it... I also restarted the server and everything (created a new character so that it generates a whole new phone.) Edited August 19, 2020 by gaghaufgy
Moderators Patrick Posted August 19, 2020 Moderators Posted August 19, 2020 10 minutes ago, gaghaufgy said: I managed to change it but... that didn't seem to fix it... Also change the length to 10. community profile | map converters | map images | pDownloader | pAttach | model encrypter
gaghaufgy Posted August 19, 2020 Author Posted August 19, 2020 (edited) .. i ll update you if it works Nope still doesn't work , the zero doesn't show up it's only 76(and the rest of the random numbers) This is the part of the script i edited local attempts = 0 local itemValue = 1 while true do attempts = attempts + 1 itemValue = "076" .. math.random(1000000, 9999999) local mysqlQ = mysql:query("SELECT `phonenumber` FROM `phones` WHERE `phonenumber` = '" .. itemValue .. "'") if mysql:num_rows(mysqlQ) == 0 then mysql:free_result(mysqlQ) break end mysql:free_result(mysqlQ) end exports.global:giveItem( client, 2, itemValue ) exports.anticheat:changeProtectedElementDataEx(client, "dbid") triggerClientEvent(client, "accounts:characters:new", client, 3, tonumber(id)) else triggerClientEvent(client, "accounts:characters:new", client, 2, 2) end end this is a photo of the table structure : https://imgur.com/a/YgQbObe Edited August 19, 2020 by gaghaufgy
gaghaufgy Posted August 19, 2020 Author Posted August 19, 2020 36 minutes ago, Patrick said: Also change the length to 10. What do you think the problem is :\
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