Jump to content

Table filling problem


Recommended Posts

Hey!

I have more than 40 pictures in my resource's image folder, and I wanna create them when a client player clicks on a gui button.

I want to show only 1 picture in the same time, from a table, but I dunno how to fill up it first.

(the table would contains the name of the files, without ".png")

How can I do the filling?

Thanks

Nonameman :)

Link to comment
filling?, once you made the table no need for filling.

You want it random?

If so here how you can get a random element from a table:

local randomElement = theTable[math.random(#theTable)] 

how said JR10, u can use a random:

this can be the img path:

"img/"..theTable[math.random(#theTable)]..".png" 

Link to comment

Something like this:

local images = {} 
for i, image in ipairs(getResourceFiles(getThisResource(), ".png")) do 
table.insert(images, image) 
end 
triggerClientEvent("recieveImagesTable", root, images) 
  
  
function getResourceFiles(resource, ext) 
    local filesTable = {} 
    ext = ext or "" 
    local meta = xmlLoadFile(":"..getResourceName(resource).."/meta.xml") 
    if meta then 
        local i = 0 
        while xmlNodeGetChildren(meta, i) ~= false do 
            local node = xmlNodeGetChildren(meta, i) 
            local src = xmlNodeGetAttribute (node, "src") 
            if src then 
                if src:lower():find(ext) then 
                    table.insert(filesTable, src) 
                end 
            end 
            i = i + 1 
        end 
        xmlUnloadFile(meta) 
    end 
    return filesTable 
end 

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