Jump to content

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


t0r3

Recommended Posts

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 :)

Link to comment
Share on other sites

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
  • Like 2
Link to comment
Share on other sites

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 :) 

Link to comment
Share on other sites

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

 

 

  • Like 1
Link to comment
Share on other sites

@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
  • Like 2
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...