FWCentral Posted May 14, 2012 Posted May 14, 2012 Ok i have 3 numbers, How can i pick a random number out of them?
Castillo Posted May 14, 2012 Posted May 14, 2012 math.random San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
FWCentral Posted May 14, 2012 Author Posted May 14, 2012 Doesn't that only work say if i put math.random(1,20) it will pick a random number between them? and i should have said the 3 numbers are non consecutive.
Castillo Posted May 14, 2012 Posted May 14, 2012 Create a table. E.g: local numbers = { 1, 5, 8, 10 } outputChatBox ( numbers [ math.random ( #numbers ) ] ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
FWCentral Posted May 14, 2012 Author Posted May 14, 2012 The numbers are coming from a db, so like this? local skins = ( skin1, skin2, skin3 ) skins [ math.random ( #skins ) ]
Castillo Posted May 14, 2012 Posted May 14, 2012 No, wait, you're using parenthesis, not { }. local skins = { skin1, skin2, skin3 } skins [ math.random ( #skins ) ] San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Stanley Sathler Posted May 14, 2012 Posted May 14, 2012 I guess is like this, not? local skins = { skin1, skin2, skin3 } skins[math.random(#skins)] -- Note: I used "{ }", and not "( )" in table declarations --- Forget, you fixed your post. Software Engineer & Entrepreneur • Running Lustrel and VilarikA • Highly engaged on open source community
Castillo Posted May 14, 2012 Posted May 14, 2012 @StanleySathler: It has to get a random index from the table, so you have to give the max index in math.random, which you get with: #table, only if is a indexed table of course. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Stanley Sathler Posted May 14, 2012 Posted May 14, 2012 Solidsnake, yes bro, I got it. I fixed my post, I had forgotten this detail. Software Engineer & Entrepreneur • Running Lustrel and VilarikA • Highly engaged on open source community
Castillo Posted May 14, 2012 Posted May 14, 2012 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
FWCentral Posted May 14, 2012 Author Posted May 14, 2012 I didn't want to start a new topic but i got another problem, Im trying to spawn a player; function spawn(source, spawn) outputChatBox("work1") local gang = executeSQLQuery("SELECT gang FROM Spawn WHERE name = ?",tostring(spawn)) if gang == "none" then outputChatBox("work2") elseif gang ~= "none" then outputChatBox("work3") end end It shows in the chatbox work1 and work3 but the gang in the db is "none" (without quotes)
Castillo Posted May 14, 2012 Posted May 14, 2012 function spawn ( source, spawn ) outputChatBox ( "work1" ) local gang = executeSQLQuery ( "SELECT gang FROM Spawn WHERE name = ?", tostring ( spawn ) ) if ( gang ) then local gangName = gang [ 1 ] [ "gang" ] if ( gangName == "none" ) then outputChatBox ( "work2" ) else outputChatBox ( "work3" ) end end end San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
FWCentral Posted May 14, 2012 Author Posted May 14, 2012 It works thank you! but how does this work? local gangName = gang [ 1 ] [ "gang" ]
Castillo Posted May 14, 2012 Posted May 14, 2012 What do you mean by how does it work? you can google to check how SQLite works . P.S: You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Stanley Sathler Posted May 14, 2012 Posted May 14, 2012 The SQLQuery return a table. So you access the first item from table (gang[1]) and the column (["gang"]). Is it, I think. Software Engineer & Entrepreneur • Running Lustrel and VilarikA • Highly engaged on open source community
Castillo Posted May 14, 2012 Posted May 14, 2012 The SQLQuery return a table. So you access the first item from table (gang[1]) and the column (["gang"]). Is it, I think. Indeed, that's exactly what it is. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Stanley Sathler Posted May 14, 2012 Posted May 14, 2012 No problem, FWCentral. Software Engineer & Entrepreneur • Running Lustrel and VilarikA • Highly engaged on open source community
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