Jump to content

Using Resources folder


Ericthecmh

Recommended Posts

Hey guys,

 

I've had quite a few scripters attempt to use the resources folder to load stuff without having to download them manually, so I figured I'd write a quick tutorial.

 

(I've put this in the scripter section because I'd rather not have new scripters throwing random shit into that folder. Please limit it to image/text only).

 

RESOURCES Folder location:

 

For a script, put the resources folder in the root of the script module (I think root of the git repo works too if you want to use global resources).

 

IE:

 

dreamscripts

--> DreamChopper

     --> resources

          --> ValkyrIsANoob.jpg

 

Accessing resource from your script:

 

Here's a quick test script that I created and submitted to SDN to check that it works: (You can pull out the code...)

package test;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.io.*;

/**
 * Created by ericthecmh on 8/26/15.
 */
@ScriptManifest(version = 1.0, author = "Ericthecmh", logo = "", info = "Amaze", name = "Llama")
public class Llama extends Script {

    private BufferedReader br;

    @Override
    public void onStart() {
        br = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/resources/LLAMAS.DAT")));
    }

    @Override
    public int onLoop() throws InterruptedException {
        try {
            String s = br.readLine();
            if (s != null)
                log(s);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return 1000;
    }z
}

I TESTED LOCALLY AND IT DOESN'T WORK???

 

Make sure that when you build the local jar, it contains the resources folder in the root of the jar:

 

DreamChopper.jar

--> resources/

     --> LLAMAS.DAT

--> org

     --> dreamscripts

          --> chopper

  • Like 8
Link to comment
Share on other sites

  • 2 years later...

I have followed every step in this tutorial and have verified the resource file is in the right spot on the jar and have tried this with a non osbot jar and everything works, but I cannot get this working in OSBOT at all. My guess is there has been security permissions that have changed this this post was made. Can anyone verify this still works because I have tried everything.

Link to comment
Share on other sites

18 minutes ago, battleguard said:

I have followed every step in this tutorial and have verified the resource file is in the right spot on the jar and have tried this with a non osbot jar and everything works, but I cannot get this working in OSBOT at all. My guess is there has been security permissions that have changed this this post was made. Can anyone verify this still works because I have tried everything.

The new directory is OSBot\data. You can get this directory in your script by doing getDirectoryData() and then concatenate the file name onto that.

  • Like 1
Link to comment
Share on other sites

1 hour ago, d0zza said:

The new directory is OSBot\data. You can get this directory in your script by doing getDirectoryData() and then concatenate the file name onto that.

the problem with the Osbot\data folder is I want to be able to bake resources into my jar so I do not have to download all the files off the web and put the cached version into the osbot\data folder. For example if I had images for my paint it would be nice to just put them in my resources folder instead of having to store them online and then download them when I want to run the script. Sure once I run it once I could cache them in the users osbot\data folder but I would rather not have to do that.

 

Also if that is the case now that OSBOT/data is supposed to be used for now on hopefully one of the mods can remove this sticky it might save some other scripter a couple hours of headache.

Edited by battleguard
Link to comment
Share on other sites

34 minutes ago, battleguard said:

the problem with the Osbot\data folder is I want to be able to bake resources into my jar so I do not have to download all the files off the web and put the cached version into the osbot\data folder. For example if I had images for my paint it would be nice to just put them in my resources folder instead of having to store them online and then download them when I want to run the script. Sure once I run it once I could cache them in the users osbot\data folder but I would rather not have to do that.

 

Also if that is the case now that OSBOT/data is supposed to be used for now on hopefully one of the mods can remove this sticky it might save some other scripter a couple hours of headache.

Yeah just put the images into your Osbot\data folder and you'll be able to use them.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...