Jump to content

Generating a phone number with first 3 numbers not changable


gaghaufgy

Recommended Posts

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

Link to comment
  • gaghaufgy changed the title to Generating a phone number with first 3 numbers not changable
  • Moderators
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.mtasa.com/topic/64228-the-ultimate-lua-tutorial/
- https://forum.mtasa.com/topic/34453-manuals

https://forum.mtasa.com/topic/121619-lua-for-absolute-beginners
- https://forum.mtasa.com/topic/95654-tut-debugging/
- https://forum.mtasa.com/topic/114541-tut-events/
- https://forum.mtasa.com/topic/117472-tut-scaling-dx/

 

Link to comment

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)

Link to comment
  • Moderators
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 by Patrick
Link to comment

.. 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 by gaghaufgy
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...