Jump to content

Random files from a folder


Recommended Posts

Posted

Hi,

I was wondering if it was possible to find a random file from a folder.

As example, I have 50 .xml files in a folder, and they all have different names.

Is there a function to get the contents of a folder, like files at a certain index, so I could just load a file when I have a number? Like 1-50?

I hope you guys understand this... :P

Regards,

Rutger Speksnijder.

Posted (edited)

So, import all files in the meta.xml, and then in the script:

math.random(1, 50)  

and then u load xml file whit the random number :D

Edited by Guest
Posted

Yeah okay, but the problem is that if I have to import all the files in the meta.xml, it takes kinda long. 'Cause in this case, it's like 150 files. So I was wondering if there was some sort of function for this.

Posted

Mhh, for open the files in the script i'm not sure that u need to insert these in the meta, u can try like:

xmlLoadFile(":"..getResourceName(getThisResource()).."/"..math.random(1, 150)) 
  

But i'm not sure that works :S try...

Posted
That doesn't work, because I said that the files all have a different name, and aren't just numbers.

ah, in that can u have to add in meta :S

  • MTA Team
Posted

Aha, are these xml's being generate by the same resource? In that case, when making an xml file, make a main xml file called master.xml, which specifies all the filenames of the generated ones. Then get the children, then use my function:

  
function table.getr(t, min) 
     return t[math.random(min or 1, table.getn(t))] 
end 

and then get the attributes and or value. But i cant guarantee itll work

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