Jump to content

Chin Hunter Script doesn't walk or pick up traps


TheManWhoBots

Recommended Posts

Hello, I am new to scripting for bots and have recently created a Chin Hunter Script. The Script's logic is fine and should function after reading the code. However, this is not the case. The Script idles after doing nothing in the first state then switches to the second state and begins to idle while using a massive amount of CPU.

 

When the Script calls the onLoop() method, everything works as intended. I am using a "Case-Switch" method to determine which action should be taken at each interval of the Script. The logic works fine, because I can use the logger to determine that different states are being activated. However the ingame player doesn't actually do the actions as intended. Instead the code is simply read then executed WITHOUT doing any of the osBot API actions (WebWalking, getInventory() interactions, Item recognition, etc). Despite all of this, the logger accurately confirms that the actions such as WebWalking are being executed.

 

Here is a snipplet of the code (with documentation):

 

case LAYTRAP: 
			log("LAYING TRAPS...");
			if (!maxTrapsLaid()) {   // maxTrapsLaid() - method that returns boolean of whether trapsLaid equals calculated max traps based on level (works)
				getWalking().webWalk(randomizePosition()); // WebWalk to random position defined by randomizePosition(), returns a Position within 'huntArea'
				getInventory().interact("Box Trap", "Lay"); // GetInventory interaction with a Box Trap to lay the trap (doesn't work)
				sleep(random(1500,3000)); // script delays to lay the next trap in timely manner
				trapsLaid++; // executed after each trap is laid to count amount of traps currently laid, corresponds with maxTrapsLaid() (works)
			}
			break;

 Here is the code without documentation:

case LAYTRAP: 
			log("LAYING TRAPS...");
			if (!maxTrapsLaid()) {
				getWalking().webWalk(randomizePosition());
				getInventory().interact("Box Trap", "Lay");
				sleep(random(1500, 3000));
				trapsLaid++;
			}
			break;

 

I know the Script logic works, because in the Logger I have seen it switch from states "Laying traps" to "Catching Chins", despite doing nothing. The issue is that WebWalking does nothing and Inventory interaction does nothing.. (I've tried to use both String values and Integer values for the first ID parameter of the interact() method)

 

Where have I gone wrong?

 

**EDIT**

I fixed the getInventory().interact() method, it lays traps properly. However it still doesn't detect GroundItems or do any walking.

Edited by TheManWhoBots
Link to comment
Share on other sites

22 minutes ago, Chris said:

Read the docs for the default methods.

 

I've realized that the action and string id parameters were switched, that's why the inventory interaction wouldn't work. It seems to be working now. However walking still does nothing. I've even checked that the script detects the player in the pre-defined 'huntArea', then get the player to move to a random spot within that area.

 

The method looks like: 

getWalking().walk(position);

Where 'position' is the return of a position randomizing method. It doesn't walk, it does nothing.

 

Link to comment
Share on other sites

4 hours ago, TheManWhoBots said:

I've realized that the action and string id parameters were switched, that's why the inventory interaction wouldn't work. It seems to be working now. However walking still does nothing. I've even checked that the script detects the player in the pre-defined 'huntArea', then get the player to move to a random spot within that area.

 

The method looks like: 


getWalking().walk(position);

Where 'position' is the return of a position randomizing method. It doesn't walk, it does nothing.

 

Have you tried to set the minimum walking distance threshold to 0? This way the script walks to the exact position you want to go to.

https://osbot.org/api/org/osbot/rs07/event/WalkingEvent.html

Link to comment
Share on other sites

4 hours ago, Hannes7337 said:

Have you tried to set the minimum walking distance threshold to 0? This way the script walks to the exact position you want to go to.

https://osbot.org/api/org/osbot/rs07/event/WalkingEvent.html

No, I haven't. I guess I haven't read enough of the API. I will try this and test it.

Link to comment
Share on other sites

4 hours ago, Hannes7337 said:

Have you tried to set the minimum walking distance threshold to 0? 

Just tried this. I initialized a new WalkingEvent in the onStart() method, called the setMinimumDistanceThreshold(0), then tried getWalking().getWalk(position) with no luck. My player still does not walk.

 

Could it be that my position coordinates are off, because any example source code I examine uses the same walk() method(s)? My program does detect that my player is in the pre-defined 'huntArea' with chins in it. I've tested it using the logger and the debugger settings.

Link to comment
Share on other sites

Hi @TheManWhoBots,

Could you please show us this method randomizePosition() also don't forget to place that trap I imagine you would need to break out of the WebWalking place the trap and then initialise it again. so something like.

final WebWalkEvent trapLocation = new WebWalkEvent(randomPosition());

trapLocation.setBreakCondition(new Condition() {
	@Override
	public boolean condition() {
		return !maxTrapsLaid();
	}
});

script.execute(trapLocation);

And then to check if you have enough traps laid don't quote me if I'm wrong but I'd imagine when you successfully place a trap something a long the lines of 

Quote

You successfully place a trap.

Should print out in the chat box I don't know too much about hunter myself so I'm not sure, anyways you would override the onMessage() and just check if the message contains anything of the likes of successfully placing a trap if so add on to your trapsLaid.

@Override
public void onMessage(Message msg) {
	if (msg.getMessage().contains("You successfully place a trap"))
		trapsLaid++;
	}

I hope this helps you in some way best of luck.

  • Like 1
Link to comment
Share on other sites

@01053 

Hi there, Sorry I won't reveal my method for randomizing the position for various privacy/safety reasons. My scripts aren't open source, and they have a very heavy emphasis on anti-ban along with functionality. I like to keep my code snipplets generic and sparse without revealing the true internal methods to limit the potential privacy leak.

I will however state that I got the script working properly by using some of your code. It seems the getWalking() method doesn't actually work, and what does work is using the generic "execute()" method with a paramaterized instantiation of a local WalkingEvent object. My program works flawlessly now, in terms of walking, and selects a random position with weighted odds to cater to specific tiles(with other various actions).

Thank you for your input.

(Working code) 

case LAYTRAP:
if (!maxTrapsLaid()) {
      WalkingEvent walkingPath = new WalkingEvent(position);
      walkingPath.setMiniMapDistanceThreshold(0);
      walkingPath.setMinDistanceThreshold(0);
      execute(walkingPath);

	  layTrap();
}
break;

 

Edited by TheManWhoBots
  • Like 1
Link to comment
Share on other sites

6 minutes ago, TheManWhoBots said:

@01053 

Hi there, Sorry I won't reveal my method for randomizing the position for various privacy/safety reasons. My scripts aren't open source, and they have a very heavy emphasis on anti-ban along with functionality. I like to keep my code snipplets generic and sparse without revealing the true internal methods to limit the potential privacy leak.

I will however state that I got the script working properly by using some of your code. It seems the getWalking() method doesn't actually work, and what does work is using the generic "execute()" method with a paramaterized instantiation of a local WalkingEvent object. My program works flawlessly now, in terms of walking, and selects a random position with weighted odds to cater to specific tiles(with other various actions).

Thank you for your input.

(Working code) 


case LAYTRAP:
if (!maxTrapsLaid())
      WalkingEvent walkingPath = new WalkingEvent(position);
      walkingPath.setMiniMapDistanceThreshold(0);
      walkingPath.setMinDistanceThreshold(0);
      execute(walkingPath);

	  layTrap();
break;

 

The getWalking method does the exact same thing; creates a WalkingEvent and executes it.
The difference lies in the distance thresholds you set. And possibly from attempting to re-use the same event

  • Like 1
Link to comment
Share on other sites

1 minute ago, FrostBug said:

The getWalking method does the exact same thing; creates a WalkingEvent and executes it.
The difference lies in the distance thresholds you set. And possibly from attempting to re-use the same event

For some reason getWalking() didn't work for me. Maybe because I wasn't accessing the WalkingEvent properly when setting the minimum thresholds. I tried to implement a new instance locally & globally, and even used the default object. Idk? Glad I got it to work this way though.

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