May 28, 20178 yr Hey, I'm just getting into scripting having some java and other various programming background. From following the tutorials I've come up with a bit of a base for a simple cow fighter which I want to build off of, and I have what I think will give me a script which will attack cows, but whenever I run it nothing happens. Here's my onLoop() code. my onStart() code sets the current state to initialState. Any idea what I'm doing wrong? Also I might just be blind, but if anybody could link me to a good debugging tutorial I'd be very appreciative! public int onLoop() throws InterruptedException { objects.closest("Cow").interact("Attack"); switch (getCurrentState()){ //state transitions case initialState: setState(states.lookingForFight); break; case inCombat: if(!myPlayer().isUnderAttack()){ setState(states.lookingForFight); } break; case lookingForFight: if(myPlayer().isUnderAttack()){ setState(states.inCombat); } break; case lowHealth: setState(states.eating); break; case eating: if (!needToEat()){ if (myPlayer().isUnderAttack()){ setState(states.inCombat); } else{ setState(states.lookingForFight); } } break; case waiting: break; case finish: break; case bank: break; default: break; } switch (getCurrentState()){ //state actions case initialState: break; case inCombat: break; case lookingForFight: log("attempting to attack"); Entity cow = objects.closest("Cow"); if(cow != null ){ cow.interact("Attack"); } break; case lowHealth: break; case eating: getInventory().interact("Trout", "Eat"); break; case waiting: break; case finish: break; default: break; } return random(400, 1200); }
May 28, 20178 yr Cows aren't objects...theyre npcs. I'd suggest reading the api docs a bit. https://osbot.org/api/ Specifically introduce yourself to the different classes that implement Entity. Use the api the way its meant to be, methods return boolean for a reason..use it to control your script logic. objects = doors, gates, trees, fires, etc npcs = uhh...npcs groundItems = lootable items item = bank/equipment/inventory items
May 28, 20178 yr 9 minutes ago, Polymorphism said: npcs = uhh...npcs think you might be looking for "cows" right here
May 28, 20178 yr It seems unnecessary that you're switching getCurrentState() twice per loop. If you want to save which state you're currently executing, try something like this: // global variables: State currentState = State.INITIAL_STATE; // or whatever your 'initial' or 'unknown' state is // in your onloop: switch(currentState = getCurrentState()) { case BANK: getBank().depositAll(); ... break; case ...: ... break; ... }
May 28, 20178 yr 5 hours ago, Alek said: Time to fuck both of your lives: XTile[][] plane = map.getRegion().getTiles()[myPosition().getZ()]; for (int x = 0; x < plane.length; ++x) for (int y = 0; y < plane[x].length; ++y) for (XInteractableObject obj : plane[x][y].getObjects()) { if (obj != null) { InteractableObject obj2 = Wrapper.wrap(obj); if(obj2.isNPC() || obj2.isPlayer()) System.out.println(obj2.getName() + ", " + obj2.isNPC() + ", " +obj2.isPlayer()); } } InteractableObjects are part of the getAll() list from Objects, however they are put in a list of RS2Object which object slices them. It's one of the gray areas for me in OSBot, you'd have to ask Zach or MGI who know a lot more about the game than I do. Nice to see you are spending your time making algorithms to fuck with people rather than working on re-sizeable mode Edited May 28, 20178 yr by Tom
May 28, 20178 yr 9 hours ago, Polymorphism said: Cows aren't objects...theyre npcs. I'd suggest reading the api docs a bit. https://osbot.org/api/ Specifically introduce yourself to the different classes that implement Entity. Use the api the way its meant to be, methods return boolean for a reason..use it to control your script logic. objects = doors, gates, trees, fires, etc npcs = uhh...npcs groundItems = lootable items item = bank/equipment/inventory items I'm just here to say that NPC = Non-Player Charcter Any character that's not controlled by an actual person in real time is an NPC. so like a cow. or Bob of Bob's Axes in lumbridge.