Jump to content

Pick a random?


Recommended Posts

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.

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

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.

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)

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 

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.

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