Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Beginner Scripting] How to count, log and display on screen how many (ex.) logs cut? :)

Featured Replies

Hey :) 

Started learning how to script a few days ago, and I am now in need of some help :)

I know how to display for how long the script has been running / and how many levels I have gained.

How would I go about counting, logging and displaying f.ex amount of logs chopped since I started the script? - what code could I use? 

Thanks :)

Well first you gotta determine how would the script know when you woodcutted? One way would be to read in-game messages e.g. 'you chopped the tree and got some logs' or w/e it is, then add on to a simple int, e.g. treesChopped++;

So you would implement something like

	// declare this outside of a method
	private int treesChopped;
	// add this if you don't already have it, on your main script class
    public void onMessage(Message m) {
	if (m.getMessage().contains("got some logs")) {
	treesChopped++;
}
	}
	

Of course it is basic (no null-checks, doesn't check if messages are from a player or the game) and isn't the correct message (I forget the exact message) so you gotta edit the message and it should be fine. But the idea is there.

Edited by Czar

  • Author
3 hours ago, Czar said:

Well first you gotta determine how would the script know when you woodcutted? One way would be to read in-game messages e.g. 'you chopped the tree and got some logs' or w/e it is, then add on to a simple int, e.g. treesChopped++;

So you would implement something like


	// declare this outside of a method
	private int treesChopped;
	// add this if you don't already have it, on your main script class
    public void onMessage(Message m) {
	if (m.getMessage().contains("got some logs")) {
	treesChopped++;
}
	}
	

Of course it is basic (no null-checks, doesn't check if messages are from a player or the game) and isn't the correct message (I forget the exact message) so you gotta edit the message and it should be fine. But the idea is there.

Hey, thanks! :D I like how many of the main scripters here are so friendly in this community :)

put it like this ;

public void onMessage(Message m) {
    if (getChatbox().getMessages()) {
        fishCount++;
    }
}

I need to have a message type first in the parameters for getMessages, - what messagetype is the string "You caught some shrimp/anchovies"? Sry if it is obvious haha :) 

28 minutes ago, t0r3 said:

Hey, thanks! :D I like how many of the main scripters here are so friendly in this community :)

put it like this ;


public void onMessage(Message m) {
    if (getChatbox().getMessages()) {
        fishCount++;
    }
}

I need to have a message type first in the parameters for getMessages, - what messagetype is the string "You caught some shrimp/anchovies"? Sry if it is obvious haha :) 

I haven't scripted for a while, but I believe it's GAME. You don't need to do getChatbox().getMessages() either. :)

 

 

  • Author

@HeyImJamie @Czar 

Got it working! :D Now paint shows how many shrimps and how many anchovies I caught :D

private int shrimpCount;
private int anchoviesCount;

 

public void onMessage(Message m) {

    if (m.getMessage().contains("You catch some shrimps.")) {

        shrimpCount++;

    } else if (m.getMessage().contains("You catch some anchovies.")) {

        anchoviesCount++;

    }

}

 

Thank you so much! This is fun :D

 

Edited by t0r3

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.