Jump to content

Couple of noob questions


slimy

Recommended Posts

Ok, I am VERY new to the world of Java scripting, I have been reading up and such in the last  couple weeks when I have the time and it's a struggle, but I am getting there lol.  That said, bear with me as I'm sure these are super noob question.

Also, quick shoutout, since I am super new I have been dissecting other peoples scripts and using them to learn, the one I am currently trying to make started with Malcom's GF Buyer for reference and it has been extremely useful in learning how/why things act and respond the way they do in the codes, so thanks a million for the open source script.  With that said, clearly I have no claim to the content in this script, and am only displaying it to illustrate my questions.

 

First super noob question, what is the code for withdraw "X" amount of coins from bank?  and can someone please explain how to write "Inventory empty except coins" lol, you'll notice I dont have it set to take money out cuz I havent found that line yet lol... 

Second noob question, I am piecing together a buyer bot from the dissected bits of the GF Buyer script. I would like it to only announce the "Buying Offer" if it has not done so in X amount of Milliseconds, but still cycle through the trade listener/accept processes in the interim, so that it doesn't spam annoy the hell out of everyone.  The following code may NOT work at all, I managed to make the GF buyer script hop worlds if it completed a trade (using a second account to activate trades n stuff), made it bank everything and accept any trade etc. and THINK I have this coded slightly right using those references... If it is just a complete fail, please just tell me so, and I will try again rather than asking you nice people to help me learn and rebuild the entire code if it's already FUBAR lol.

 

Ok, the reason I can't wrap my head around how to do this is as follows - The short code below would (i think) Check to see has it been 30 seconds since announced, if so, announce, then log a NEW announcetime

                if (System.currentTimeMillis() > (announceofferTime + 30000))             {
                    typeStringInstant("Buying Santa Hats");
                   announceofferTime = System.currentTimeMillis() ;

 

So, I am not sure how to trigger it for the very first time, as in, how can it check ">" against a value that has yet to be written to begin the cycle?  I thought, perhaps, the first line could trigger off the startTime in the script, but then how to make it switch to checking the announceofferTime henceforth.  If this is harder than I am assuming it is, I don't expect anyone to waste a lot of valuable time so some noob can piddle around with scripting, but if there are simple methods that I am missing and someone could give me a push the right direction I would appreciate it tremendously.

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

@ScriptManifest(author = "ThatGuy", info = "Announces Buy, Trades, Hops, Rinse&Repeat", name = "GE Buddy", version = 1.0, logo = "")
public class GeBuddy extends Script {

    @Override
    public void onStart() {
        log("Let's Buy Stuff & Things");
    }

    long startTime;
    long announceofferTime;
    long tradeTime;
    public int onLoop() throws InterruptedException {
        
        startTime = System.currentTimeMillis();
            if (!getInventory().isEmpty()) {
                if  (getBank().open()) {
                    if (getBank().depositAll()) {
                        if (getBank().close()) {}
    } else {    
            if (System.currentTimeMillis() > (startTime + 300000)) {
                if (getWorlds().hopToP2PWorld()) {
    } else 
            if (!getTrade().isCurrentlyTrading()) {
                if (getTrade().getRequestListener() != null) {
                    if (getTrade().getLastRequestingPlayer() != null) {
                        if (getTrade().getLastRequestingPlayer().interact("Trade with")) {
                                    tradeTime = System.currentTimeMillis();
          } else {
              
          }
                                new ConditionalSleep(10000) {
                                    @Override
                                    public boolean condition() throws InterruptedException {
                                        return (!getInventory().isEmpty());

                                    }
                                }.sleep();
                            }

Edited by slimy
Link to comment
Share on other sites

And yes I am wholly aware there is a giant chunk of script missing lmao, I am frankensteining it together as I go... Just trying to sort how to use the commands I inquired about so I can add them in as I go, thanks again in advance

EDIT:

Follow up, and possible answer to my own question.  Is there a way to set a value for announceofferTime = startTime UNTIL an announceTime has recorded a value?! I feel like this is the answer, I just don't know how to connect the dots lol

 

Or, will adding it here fix this since it returns BELOW this line in the future?!

   long startTime;
    long announceofferTime;
    long tradeTime;
    public int onLoop() throws InterruptedException {
        
        startTime = System.currentTimeMillis();

        announceofferTime = System.currentTimeMillis();

            if (!getInventory().isEmpty()) {
                if  (getBank().open()) {
                    if (getBank().depositAll()) {
                        if (getBank().close()) {}

 

While typing this that came to me lol, I feel dumb, and will feel dumber if i am still wrong lol

Edited by slimy
Link to comment
Share on other sites

Quote

First super noob question, what is the code for withdraw "X" amount of coins from bank

https://osbot.org/api/org/osbot/rs07/api/Bank.html#withdraw-java.lang.String-int-

This is how you withdraw a certain amount of an item.

Quote

can someone please explain how to write "Inventory empty except coins"

https://osbot.org/api/org/osbot/rs07/api/Inventory.html#isEmptyExcept-int...-

Quote

                if (System.currentTimeMillis() > (announceofferTime + 30000))             {
                    typeStringInstant("Buying Santa Hats");
                   announceofferTime = System.currentTimeMillis() ;

    public long lastAnnounceTime = 0L;
    public void announceIfNecessary() {
        if ((System.currentTimeMillis() - lastAnnounceTime) > 3_000) {
            typeStringInstance("");
            lastAnnounceTime = System.currentTimeMillis();
        }
    }

 

Link to comment
Share on other sites

1 hour ago, NoxMerc said:

https://osbot.org/api/org/osbot/rs07/api/Bank.html#withdraw-java.lang.String-int-

This is how you withdraw a certain amount of an item.

https://osbot.org/api/org/osbot/rs07/api/Inventory.html#isEmptyExcept-int...-


    public long lastAnnounceTime = 0L;
    public void announceIfNecessary() {
        if ((System.currentTimeMillis() - lastAnnounceTime) > 3_000) {
            typeStringInstance("");
            lastAnnounceTime = System.currentTimeMillis();
        }
    }

 

Thanks, I have no clue what the 0L is in the public long, but as I said, I am very new, I will user the links you provided to sort the banking thing, then start looking into the code you provided, thanks again for the reply

Link to comment
Share on other sites

    public long startTime;
    public long announceofferTime;
    public long tradeTime;
    public int onLoop() throws InterruptedException {
        
        startTime = System.currentTimeMillis();
        announceofferTime = System.currentTimeMillis();
            if (!getInventory().isEmpty()) {
                if  (getBank().open()) {
                    if (getBank().depositAll()) {
                        if (getBank().close()) {}
            } else {
                 if (!getTrade().isCurrentlyTrading()) {
                        if (System.currentTimeMillis() > (announceofferTime + 30000))
                            typeStringInstant("Buying Santa Hats");
                                announceofferTime = System.currentTimeMillis();
            } else {
                    if (getTrade().getRequestListener() != null) {
                        if (getTrade().getLastRequestingPlayer() != null) {
                            if (getTrade().getLastRequestingPlayer().interact("Trade with")) {
                                    tradeTime = System.currentTimeMillis();
                                        new ConditionalSleep(10000) {
                                            @Override
                                                public boolean condition() throws InterruptedException {
                                                    return !getTrade().isCurrentlyTrading();

 

This is how I worked it out, I still havent run the bot to see if it works, there are still too many errors in the later code to save it properly, but I believe this has the effect I am looking for?  I will still look into the method suggested above, but can anyone that sees this give any input on whether this would function?

Edited by slimy
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...