Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Final Calibur

[Snippet] Asynchronous Camera API

17 posts in this topic

Update: ACamera was updated on 1/11/2016. Please check the updated source if you don't have it.
 
Hello everybody,
 
So @wastedbro and I were talking and we thought it would be a good idea to make an Asynchronous Camera API for all to use. 
 
Pretty much this is used so that the bot can move the camera and do actions at the same time (such as moving the camera and walking, or moving the camera and clicking on something).
 
Not only does this simulate human behavior better, but it also alleviates the actual execution of moving the camera from the script.
 
Without further ado, here it is (50% credit to @wastedbro):
 
Methods for you to use:

  • setAngle(int angle)
  • setRotation(int rotation)
  • turnToTile(Positionable tile)

If you are simply trying to get the camera rotation or angle, use the standard TriBot Camera API for that.
 
How to use the API in your script:

  • Create a new ACamera object in your script, like so:

    • private ACamera aCamera = new ACamera(this);
  • Use the ACamera object just as you would the normal Camera API. Example:

    • aCamera.turnToTile(tile);

Note: The turnToTile method works very effectively, but the algorithm is far from refined and 100% accurate. Feel free to change it yourself, and share it with the rest of us if you would like!

FOR USERS WHO USE WORTHY'S NODE FRAMEWORK:


You can also change the Node class from this:



import org.tribot.script.Script;/** * The node framework base class. *  * @author Worthy from TriBot * */public abstract class Node {			/**	 *	This will execute the node. Essentially a "process()" method.	 */	public abstract void execute();	/**	 *	Will return whether or not the Node should execute	 * 		 * 	@[member="Return"] true if the node should execute. False if otherwise	 */	public abstract boolean validate();	}

to this:

import org.tribot.script.Script;/** * The node framework base class. *  * @author Worthy from TriBot * */public abstract class Node {	protected ACamera aCamera;        public Node(ACamera aCamera)        {            this.aCamera = aCamera;        }		/**	 *	This will execute the node. Essentially a "process()" method.	 */	public abstract void execute();	/**	 *	Will return whether or not the Node should execute	 * 		 * 	@[member="Return"] true if the node should execute. False if otherwise	 */	public abstract boolean validate();	}

By doing this, you would simply have to make an ACamera object in your main script class, and then pass it in each of your node constructors when you add them to the ArrayList in the beginning of your script. Example:

Collections.addAll(nodes, new WorldHop(aCamera), new OpenShop(aCamera), new SellItems(aCamera));

 To use the ACamera in any of your nodes, simply call:

this.aCamera


Get the code here

Edited by Final Calibur
3 people like this

Share this post


Link to post
Share on other sites

What's wrong with using conditions? .-. I'll admit that your method is more efficient though.

Edited by Flamo353

Share this post


Link to post
Share on other sites

The point of this class is to allow camera movement to be as fluid as it would be in the hands of an actual human.,

 

For example, currently there is no way to move the camera up/down AND side-to-side at the same time. This is a very common human behavior and this class allows it.

 

Also, this class is suppose to let scripters make their script click NPCs/Objects while the camera is moving, another common human behavior that is impossible with the standard API.

1 person likes this

Share this post


Link to post
Share on other sites

What's wrong with using conditions? .-. I'll admit that your method is more efficient though.

 

The problem with using conditions is that camera movement is executed in a serial fashion, as its on the same thread. As @wastedbro said, this means that there is no way to execute any action at the same exact time as moving the camera (even changing the rotation and angle at the same time).

 

This system remedies that problem, as both camera rotation and camera angle are handled on their own separate threads. You simply make the call to update the camera, and the separate threads handle the actual execution. This allows your script to do actions at the same time as moving the camera.  :D

 

I hope I answered your question sufficiently. 

Edited by Final Calibur

Share this post


Link to post
Share on other sites

I suggest using this whenever possible.

 

Could possibly help decrease bans, though I have not tested this.

 

I think it would, though, based on previous research, assuming it's implemented well and edited a bit for more antiban.

Share this post


Link to post
Share on other sites

Set the Camera#setrotatinmethod or w.e to use keys only, otherwise this won't work as intended

Share this post


Link to post
Share on other sites

Set the Camera#setrotatinmethod or w.e to use keys only, otherwise this won't work as intended

 

Updated the tutorial accordingly, thank you!

Share this post


Link to post
Share on other sites

Update: ACamera now uses Thread.wait() and Thread.notify() instead of Thread.sleep(). This improves efficiency and cleanliness.

Share this post


Link to post
Share on other sites

Source now links to my bitbucket, which is a lot more convenient than a downloadable attachment.

 

I've made some minor changes that have cleaned up the class a bit.

Share this post


Link to post
Share on other sites

Not to be rude, but shouldn't this be called synchronous camera? asynchronous means not at the same time, and for the purposes of this class, you want mouse movements and camera movements happening fluidly at the same time, yes?

Share this post


Link to post
Share on other sites

Not to be rude, but shouldn't this be called synchronous camera? asynchronous means not at the same time, and for the purposes of this class, you want mouse movements and camera movements happening fluidly at the same time, yes?

 

It is asynchronous in relation to the flow of execution. Take a look at this, and also this, for a better explanation.

Share this post


Link to post
Share on other sites

It is asynchronous in relation to the flow of execution. Take a look at this, and also this, for a better explanation.

Looking at the definitions of the words, those links are incorrect.

Share this post


Link to post
Share on other sites

Looking at the definitions of the words, those links are incorrect.

 

The issue is that you're looking at it in the wrong context.

 

As explained in the links (which are correct, by the way), execution is asynchronous in terms of "not using the same clock". I would urge you to go back and thoroughly re-read the stackoverflow link in particular, in which the comments on the top answer address your particular issue clearly and concisely.

 

If you need further explanation, do a quick google search on synchronous vs asynchronous execution. Any of the links should be able to help you understand the context.

 

In essence it's simply semantics, so I'm not going to discuss this further.

Edited by Final Calibur

Share this post


Link to post
Share on other sites

The issue is that you're looking at it in the wrong context.

 

As explained in the links (which are correct, by the way), execution is asynchronous in terms of "not using the same clock". I would urge you to go back and thoroughly re-read the stackoverflow link in particular, in which the comments on the top answer address your particular issue clearly and concisely.

 

If you need further explanation, do a quick google search on synchronous vs asynchronous execution. Any of the links should be able to help you understand the context.

 

In essence it's simply semantics, so I'm not going to discuss this further.

I must not understand the words then. To me, synchrony means happening at the same time, while asynchrony means not happening at the same time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.