Jump to content

Organization path


XFawkes

Recommended Posts

something like that?

function getResourcesInPath(path) 
    local Resources = {} 
    for k,resource in ipairs(getResources()) do 
        local resourceName = getResourceName(resource) 
        if fileExists(":"..path.."/"..resourceName.."/meta.xml") then 
            table.insert(Resources,resource) 
        end 
    end 
    return Resources 
end 
  
getResourcesInPath("MyResources/Maps") 

edit:

If you mean the ftp path, idont think this is possible with only lua codes

Link to comment

Thanks, but I've tried that already, and I suppose fileExists only can accept resourcenames without their path..

I get 0 results using that function.

EDIT:

I am trying to find it out using OOP. Look:

https://wiki.multitheftauto.com/wiki/Resource

"A name, state, root element, base directory path are associated to a resource, among other attributes."

I can use:

resource.name, resource.state - and it works well, I am wondering if there is smth like:

resource.path <- It is not working, but I am trying to find it.

Is there any way to get all oop variables (name, state...)?

I've just found how to get all oop functions:

  
local t = getmetatable(res).__class 
for k,v in pairs(t) do 
  outputChatBox(k) 
end 
  

Any ideas how to help me?

EDIT2:

  
local t = getmetatable(res).__get 
for k,v in pairs(t) do 
  outputChatBox(k) 
end 
  

There is no path, for resource ;/

EDIT3:

I am thinking of using renameResource which supports orgizational path.

  
local name = getResourceName(res) 
local renamed = renameResource(res,name,"[mycategory]") 
if renamed then  
  -- I know that the resource wasnt in that folder 
else 
  -- Hurray I've found resource which is in [mycategory] path 
end 
  

^ works well, but I have a problem, when 'renamed' returns false, the resource is moved to mycategory, I could move it to root folder by doing renameResource again, but I'd like to move them to their original category...

(If they were moved from [firstcategory] to [mycategory] then I am loosing the info about firstcategory)

Link to comment

As far as I know, you can't access the file system outside resources, ergo you have no way of knowing where on the host machine a file/directory exists. I think MTA:EIR will change this, but I don't think using the EIR fork is an option.

You could add some info in their meta.xml though. If you are good at scripting, you could write some code that does it for you.

Basically it would do this: (Python-esque pseudocode)

for folder in category: 
  meta=folder.openXML("meta.xml")--iterate resource folders in the grouping folder 
    meta.getnode("info").add("category","somecategory")--open the folder's meta.xml file and add some tag into its info node 

Now you can iterate all resources and filter for one with that tag in its info. Not pretty, but it should work.

Link to comment

Yeah, I have made an external C# code yesterday which do such thing. Not a good way for me but I see no other options (I wanted to stick to MTA code so I can minimalise user interaction - as I am not the only one who will use it). But thanks, I think it would be great if MTA team add an variable to each resource which will hold the path.

resource.path

- ""

- "[maps]"

- "[maps]/[dm]"

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