Jump to content

T12: Selection API update (with snippet)


Botre

Recommended Posts

c62c2a31744f26cbf4938f376e342d8b.png

@ScriptManifest(author = "Botre", info = "", logo = "", name = "Selection Listener Example", version = 0)
public class SelectionListenerExample extends Script implements SelectionListener<NPC> {

	private Sapi sapi;
	
	@Override
	public void onStart() throws InterruptedException {
		super.onStart();
		sapi = new Sapi(this);
		sapi.registerMouseAdapter();
		sapi.setSelector(Module.NPC);
		sapi.getNpcSelector().getSelectionListeners().add(this);
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		//...
		return 500;
	}
	
	@Override
	public void onPaint(Graphics2D g2d) {
		super.onPaint(g2d);
		for (NPC npc : sapi.getNpcSelector().getSelection()) {
			Painter.defaultEntity().paint(g2d, this, npc);
		}
	}
	
	@Override
	public void onExit() throws InterruptedException {
		sapi.unregisterMouseAdapter();
		super.onExit();
	}

	@Override
	public void onSelection(List<NPC> selection) {
		for (NPC npc : selection) {
			if(npc != null) {
				log("Selected npc with name: " + npc.getName());
				if(npc.getActions() == null) continue;
				log("This npc has the following actions:");
				for (String action : npc.getActions()) {
					log("\t" + action);
				}
			}
		}
	}

}
Edited by Botre
  • Like 3
Link to comment
Share on other sites

Shoudln't one of those actions be 'Walk here'? 

Also, why are you displaying 3 'null's

 

Other than that it looks pretty intersting

 

"Walk-here" is actually a tile action, not an entity action.

I just didn't bother filtering the null actions out since this is just a testing / demonstration snippet, but since you're my special friend:

if(action == null) continue;
log("\t" + action);
  • Like 1
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...