Jump to content

Pick a random?


Recommended Posts

Posted
math.random 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

3677124c9d4d768da64a55d5bebf578e.png
Posted

Create a table.

E.g:

local numbers = { 1, 5, 8, 10 } 
  
outputChatBox ( numbers  [ math.random ( #numbers ) ] ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

No, wait, you're using parenthesis, not { }.

local skins = { skin1, skin2, skin3 } 
skins [ math.random ( #skins )  ] 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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. :P

Software Engineer & Entrepreneur Running Lustrel and VilarikA • Highly engaged on open source community

Posted

@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.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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)

3677124c9d4d768da64a55d5bebf578e.png
Posted
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.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

Posted
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.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...