Jump to content

teddros

Members
  • Posts

    4
  • Joined

  • Last visited

  • Feedback

    0%

Profile Information

  • Gender
    Male

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

teddros's Achievements

Newbie

Newbie (1/10)

0

Reputation

  1. //If you start this code with fish still in your inventory it will count those fish, so be careful private int numSalmonCaught;//Total number of salmon caught. Initialize at 0. private int numTroutCaught;//Total number of trout caught. Initialize at 0. private int inventorySlotIndex;//This is the inventory slot number that we are currently examaning //The slot numbers from inventory are from 0-27 NOT 1-28!! //Meaning that if you are fishing for trout initalize the variable at 2 //Because the first two inventory slots are taken with the rod and feathers. //I implemented this by either running the method countLureCatches() in the paint, or creating a thread and run it. //place code inventorySlotIndex = 2 somewhere in your code after you bank or drop the fish. //This way the counter can start again public void countLureCatches(){ if((inventory.getItemInSlot(inventorySlotIndex) != null) || (inventorySlotIndex <= 28)){//Will only run if the //slot that we are currently at has something stored in it, or that our index value is less than 28 //meaning we don't have a full inventory if(inventory.getItemInSlot(inventorySlotIndex).getName().equals("Raw salmon")){//Checks to see what item is in //said inventory slot and checks to see if its salmon. //because .getItemInSlot(int) returns an Item object we must use .getName() to check it against a string. //We must use .equals() to compare strings because they are objects. numSalmonCaught++;//Increments our salmon inventorySlotIndex++;//Increments our inventory slot variable }else{//Only goes through this code if the if statement above is found to be false. if(inventory.getItemInSlot(inventorySlotIndex).getName().equals("Raw trout")){ numTroutCaught++; inventorySlotIndex++; } } } } So I was writing my own fishing script for Barbarian Village and couldn't help but be bothered by the lack of a way to calculate how many trout I caught and how many salmon I caught. Sure I could use onMessage() and have a total fish caught but I wanted a way to have a count that was distinct for both types of fish. So allow me to explain what my code does. First we initialize the variable inventorySlotIndex = 2 in the onStart(). This is because we have something in slot 0 and something in slot one (feathers and fishing rod). Keep in mind the slot numbers are from 0-27 NOT 1-28.We then find out what is in the slot number (trout or salmon) once we detect that something is there. Once we find out what is in that slot say we caught a salmon we then increment both the salmonCaught and the inventorySlotIndex, and do the same thing for the next slot. Once the inventory is full the inventorySlotIndex should be at 28 which is out of bounds for our inventory and cause the script to stop counting. Once we bank or drop the fish it is important that you have the inventorySlotIndex reset to 2. If you are fishing lobster then obviously you start at slot 1. If you are doing something where you have no slots taken with equipment then you'd set it to 0. Any questions suggestions or criticisms are welcomed. If you need help implementing this into your code I'm also willing to help.
×
×
  • Create New...