Opening files outside the resource folder

I’d like to load the playerdb.json file that txadmin creates in order to display player total time on my loading screen. I can’t get any file handle with lua’s io.open(…).
Does anyone know how to do this?

Hello.

The way I would do it may not be the fastest and however this method will be able to show you the what you need even when you cant access the full storage directory.

What I would suggest is to put print(GetResourcePath(GetCurrentResourceName())) into a server side script and restart that script and look at the server console, this will print the path to that resource which is useful for getting data form files within a resource, however for your use case you want to reference a file outside of the resource.

To reference a file outside of a resource you essentially just find that files path, which is fairly straight forward once you know the above resource’s path which you can just modify. Lets say your server files are located on a drive by the following directory FiveMserver/serverfiles/ and lets say you have two folders at this path, your serverdata folder and your txadmin folder. Your printed resource path would look something like FiveMserver/serverfiles/serverdata/resources/[your resouce] what you basically want to do is modify the path to FiveMserver/serverfiles/txadmin/data/playerdb.json

Essentially, once you print the resource file path, find a common directory between the resource and the file you want to open and change the path from the common directory to now refence the file.

Another potential way, however i have not been able to test it is to find the path to the file, lets say its on your c drive so it would be something like C:\FiveMserver\serverfiles just turn it into FiveMserver/serverfiles and you should be good. For the example above the normal path in file explorer would look like C:\FiveMserver\serverfiles\txadmin\data\playerdb.json

Let me know how you go, and if you need anymore help let me know. Sorry if I have over complicated it, its a bit late where I am and I am tired :slight_smile:

Mm, I was using a relative path to the io.open function. Maybe I missed a level. Will try what you’re suggesting. Thanks.

Ok, I actually did have the relative address correct if you are in windows explorer. Running the calls you mentioned does give me the path to the resource where I was starting my …/ from BUT that code returns an extra level of depth, notice the // :
g:/TestRP/server-data/resources//[testrp]/testrp_loading

[testrp] IS actually in the resources folder so I don’t see why it’s showing an extra slash. But when I add an extra …/ then it manages to find the json file.

Thanks heaps.

Your welcome, if you need any more help with lua file stuff let me know :slightly_smiling_face:

Actually on one other point I’ve tried using require statements that fail. Is the only option the to add external libraries to the fxmanifest?

What are you trying to require?

Any lua library.

I am not to sure as I have never use require. Best guess is you import it in the fxmanifest