Solved it!:D
For others who wants to do the same, this is how I did it.
Code:
def setImageAI ={ name, pic -> //Takes name (of mistress) and pic (the type of prefix)
def folder = new File(System.getProperty("user.dir")+"/images/(YOUR PROJECT NAME)/"+name+"/")
def fileArray = folder.listFiles()
def numberOfImages = 0
for (def i= 0; i < fileArray.length;i++){ //Sorts through all the files in the folder
if(fileArray[i].toString().contains(pic)) numberOfImages++ //if there are files with the prefix in it increase the number
}
setImage("(YOUR PRJECT NAME)/"+name+"/"+pic+(getRandom(numberOfImages)+1)+".jpg")
}
and to initiate the function:
Code:
setImageAI("Michaela", "breasts")
This will basically take a folder named Michaela, sort through all the files, and every time it encounters a file which contains the name "breasts", it will increase the variable called numberOfImages.
After that you can simply setImage to a random one containing that prefix.
I just have a folder called Michaela, and the several files called breasts1, breasts2, ass1, ass2, ass3, etc.
No matter how many files you have of one type, the function still chooses a random image from those with that prefix.