Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
zxcharyy

Why does this do nothing?

Recommended Posts

Hi all, I'm still extremely new to scripting and i've been trying to practice a little bit. I wrote up this simple script in like 15 minutes to test myself and I can't figure out for the life of me why it just stands still when I start it.. suggestions?

Quote

package scripts;

import java.awt.Point;

import org.tribot.api.General;
import org.tribot.api.input.Mouse;
import org.tribot.api2007.Camera;
import org.tribot.api2007.GameTab;
import org.tribot.api2007.Inventory;
import org.tribot.api2007.NPCs;
import org.tribot.api2007.Player;
import org.tribot.api2007.types.RSNPC;
import org.tribot.script.Script;

public class JaxxFisher extends Script implements Runnable{
    
    private final int FEATHER = 314;
    private final int ROD = 309;
    
    private final int[] FISHINGSPOT = { 1526, 1527 };
    
    private boolean kandyce = true;

    @Override
    public void run() {
        while (kandyce);
        inv();
        sleep(100, 400);
        fish();
        sleep(100, 700);
        performAntiban();
        Mouse.leaveGame();
        
        // TODO Auto-generated method stub
        
    }
    
    
    
    
    public void fish() {
        if (Player.getAnimation() != -1);
            final RSNPC[] fishspot = NPCs.findNearest(FISHINGSPOT);
            if (fishspot[0].isOnScreen()) {
                fishspot[0].click("Lure");
                sleep(100, 600);
                moveMouseSlightly();
            }
        


}

    private void inv() {
        if (Inventory.isFull()) {
            Inventory.dropAllExcept(FEATHER, ROD);
        if (!Inventory.isFull()) {
            fish();
            sleep(100, 500);
        }
        }
        
    }


    public void moveMouseSlightly() {
        Point p = Mouse.getPos();
        int x = General.random(-20, 20);
        int y = General.random(-20, 20);
        Mouse.move(p.x + x, p.y + y);
}
    
    
     public void moveMouseFar() {
         Point p = Mouse.getPos();
         int x = General.random(-200, 200);
         int y = General.random(-200, 200);
         Mouse.move(p.x + x, p.y + y);
 }
    
     public void performAntiban() {
         int randomint = General.random(1, 100);
         int dhor = General.random(0, 360);

         switch (randomint) {
         case 1:
                 break;
         case 2:
                 if ((Player.getAnimation() != -1)) {
                         GameTab.open(GameTab.TABS.STATS);
                         sleep(80, 300);
                         Mouse.move(712 + General.random(0, 4),
                                         220 + General.random(0, 4));
                         sleep(500, 700);
                         GameTab.open(GameTab.TABS.INVENTORY);
                 }

                 break;
         case 3:
                 break;
         case 4:
                 Camera.setCameraRotation(dhor);

                 break;
         case 5:
                 moveMouseSlightly();
                 break;
         case 6:
                 break;
         case 7:
                 break;
         case 8:
                 moveMouseFar();
                 break;
         case 9:
                 break;
         case 10:
                 break;
         case 11:
                 break;
         case 12:
                 Camera.setCameraRotation(-dhor);
                 break;
         case 13:
                 break;
         case 14:
         case 15:
         }
 }
     
    

}

 

Share this post


Link to post
Share on other sites

I'm not certain what the issue is, but it may be that you have Runnable implemented and Script extended. I believe they both want you to have a Run method, which might be causing conflicts for TRiBot. That or your nested ifs are causing issues. It looks like you have some conditions that overlap

Share this post


Link to post
Share on other sites

Your while loop isn't constructed correctly. Currently It's While(true) {};. It will do nothing forever. You want your methods inside that the main loop.

Also some other quick things I noticed:

-Static sleeps aren't good. Look into using Timing.waitCondition; it's your best friend

-You separately call your "inv" and "fish" methods, but inside your "inv" method, you call "fish". If you're going to call both of these in your main loop, you don't need to nest them. I'd recommend writing out pseudo code as a first step to help with the logic to make sure it's not redundant.

-I recommend using Tribot's built in anti-ban, as it's a more developed, more human-like implementation of what you're trying to do. I believe there is an antiban class written by a prem scripter that makes implementing ABC2 into scripts easier. Even if you're not able to figure out reaction times, even just adding timed actions while fishing would be much better.

-You don't length check your NPC for the fishing spot. If that method ever returns a length of 0, you'll get a Null pointer and your script will stop.

-You're going to have your mouse leave the game every loop, regardless of situation. Maybe have it only leave the game if you've successfully clicked the pool and are fishing? Even then an antiban action that happens 100% of the time seems like a bad idea to me.

Share this post


Link to post
Share on other sites
21 hours ago, Adventure_Time said:

Your while loop isn't constructed correctly. Currently It's While(true) {};. It will do nothing forever. You want your methods inside that the main loop.

Also some other quick things I noticed:

-Static sleeps aren't good. Look into using Timing.waitCondition; it's your best friend

-You separately call your "inv" and "fish" methods, but inside your "inv" method, you call "fish". If you're going to call both of these in your main loop, you don't need to nest them. I'd recommend writing out pseudo code as a first step to help with the logic to make sure it's not redundant.

-I recommend using Tribot's built in anti-ban, as it's a more developed, more human-like implementation of what you're trying to do. I believe there is an antiban class written by a prem scripter that makes implementing ABC2 into scripts easier. Even if you're not able to figure out reaction times, even just adding timed actions while fishing would be much better.

-You don't length check your NPC for the fishing spot. If that method ever returns a length of 0, you'll get a Null pointer and your script will stop.

-You're going to have your mouse leave the game every loop, regardless of situation. Maybe have it only leave the game if you've successfully clicked the pool and are fishing? Even then an antiban action that happens 100% of the time seems like a bad idea to me.

Thank you so much for the reply! You brought my attention to a lot of things I wouldn’t have originally noticed. I’ll fix this and see how it goes 🙂

Share this post


Link to post
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.


  • Our picks

    • This update features:

      Fixed broken hooks from today's update


      Fix wilderness level with RuneLite (Thanks @Todd)


      Add support for Kotlin .class files in scripts (Thanks @wastedbro)


      Overhaul Inventory API (Thanks @wastedbro)


      Add List support for common methods


      Change method grouping to make more sense (by functionality)


      Refactor methods to utilize Java 8 streams instead of cumbersome loops




      Recognize chatbox minimization (Thanks @JoeDezzy1)


      Fix Screen#isInViewport when NPC chat is open (Thanks @JoeDezzy1)


      Fix login bot bugs (Thanks @erickho123)


      Fix hint arrow return values (Thanks @Encoded)


      Fix depositAllExcept functionality (Thanks @wastedbro)


      Change containing box interface bound and adjust for Y values (Thanks @erickho123)
        • Sad
        • Like
      • 151 replies
    • This release will:

      Fix prayers and world hopper API (Thanks @JoeDezzy1 and @erickho123)


      Improve banking API (Thanks @Encoded)


      Adds methods for returning and using Java Lists, rather than arrays


      Slightly randomizes some hardcoded behaviour


      Removes sleeps from waitConditions; the efficiency saving potential is negligible in these use-cases, therefore cleaner code is preferable


      Other back-end improvements





      Note: If you are using LG, please restart both the RS client and TRiBot.
      • 90 replies
    • This release will:

      Add new internal framework for capturing exceptions


      Fix issue with not selecting the last column in world hopper (Thanks @Todd)


      Add a message about pin usage in Banking#openBank (Thanks @Todd)


      Disable the firewall by default (Thanks @Todd)


      Fix handling of the welcome screen after login (Thanks @Encoded)


      Fix wrong amount bank withdrawal (Thanks @Encoded)


      Fix Screen#isInViewport


      Fix Game#isInViewport (Thanks @Encoded)


      Call onBreakEnd for ListenerManager Breaking Listeners (Thanks @Encoded)


      Fix Prayer#getPrayerPoints NumberFormatException (Thanks @JoeDezzy1)



      Note: If you are using LG, please restart both the RS client and TRiBot.
      • 28 replies
    • This release will:

      Fix LG for both OSBuddy and RuneLite


      Fix issue where the resizable client isn't able to be made smaller (Thanks @JoeDezzy1)


      Fix detection of the logout game tab when resizable mode and side panels are enabled (Thanks @JoeDezzy1)


      Add initial support for Sentry to allow us to identify and easily debug exceptions happening with all TRiBot users


      Add methods to determine if the bank is actually loaded, and not just the overarching interface (Thanks @wastedbro)



      Upcoming updates:

      Improved CLI support


      Full Sentry support


      Much more
      • 64 replies
    • This release will:

      Fix NPE in Camera API (Thanks @wastedbro)


      Update deposit box interface ids (Thanks @Encoded)


      Add various bank methods (Thanks @wastedbro)


      Banking#getWithdrawXQuantity


      Banking#getDefaultWithdrawQuantity


      Banking#arePlaceholdersOn




      Fix resizeable minimap bug (Thanks @wastedbro)


      Remove Java 8 requirement


      Please note: TRiBot is not yet fully compatible with Java 10+




      Fix the break handler issues by ensuring the break handler thread never gets paused


      Fix broken settings hooks



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
      • 68 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...