Jump to content

combat checks... ive tried everything.


booya

Recommended Posts

Doing a quest script, currently need to kill a rat for meat to burn it.

i just want it to sleep until it sees meat on floor then pick it. but currently, it is returning true on everything ive tried for when on combat in rat, it seems to be if the rats far away.....

I have tried every combo you can think of but it skips and comes back to "AT RATS" ive tried || and &&................. anoyying.

Quote
if (!players.myPlayer().isMoving() && RATS.contains(myPosition())) {
    log("AT RATS");
    sleep(random(500, 1250));
    if (!players.myPlayer().isAnimating() && !players.myPlayer().isMoving() && npcs.closest("Giant rat") != null && RATS.contains(myPosition())) {
        npcs.closest("Giant rat").interact("Attack");
        log("ATTACKING RAT");
        sleep(random(500,1200));
        mouse.moveOutsideScreen();
        log("MOVE MOUSE OF SCREEN & SLEEPING");
        new ConditionalSleep(120000, 500) {
            @Override
            public boolean condition() {

                log("INCOMBAT3");

                return !getPlayers().myPlayer().isMoving() || !getPlayers().myPlayer().isInteracting(getNpcs().closest("Giant Rat")) || !getCombat().isFighting();
            }
        }.sleep();
    }
    if (groundItems.closest("Raw rat meat") != null) {
        log("RAW MEAT IS ON FLOOR");
        groundItems.closestThatContains("Raw rat meat").interact("Take");
        sleep(random(200, 800));
        new ConditionalSleep(6000) {
            @Override
            public boolean condition() throws InterruptedException {

                return inventory.contains("Raw rat meat");
            }
        }.sleep();
    }
    if (getInventory().contains("Raw rat meat")) {
        sleep(random(500, 1250));
        Onion();
    } else {
        sleep(random(200, 800));
        Meat();

 

Link to comment
Share on other sites

  • 1 month later...
On 4/13/2024 at 11:47 AM, booya said:

Doing a quest script, currently need to kill a rat for meat to burn it.

i just want it to sleep until it sees meat on floor then pick it. but currently, it is returning true on everything ive tried for when on combat in rat, it seems to be if the rats far away.....

I have tried every combo you can think of but it skips and comes back to "AT RATS" ive tried || and &&................. anoyying.

 

Here's a quick example on how you could refactor your code to make it a little more readable and predicatable.

First declare an enum class that specifies the current state that your bot should be in.

Spoiler
public enum BotState {
    WALK_TO_FIGHT_AREA,
    PICKUP_LOOT,
    ATTACK_TARGET,
    IDLE
}

Then create a method to determine the state that the bot should be in.

Spoiler
public BotState calculateBotState() {
    if (getNpcs().closest("Giant rat") == null && myPlayer().getInteracting() == null)
        return BotState.WALK_TO_FIGHT_AREA;
    else if (getGroundItems().closest("Raw rat meat") != null && myPlayer().getInteracting() == null && !getInventory().isFull())
        return BotState.PICKUP_LOOT;
    else if (getNpcs().closest("Giant rat") != null && myPlayer().getInteracting() == null)
        return BotState.ATTACK_TARGET;

    return BotState.IDLE;
}

Then create methods for each of those states.

Spoiler
public boolean walkToFightArea(Area fightArea) {
    return getWalking().webWalk(fightArea);
}

public boolean pickupLoot() {
    GroundItem loot = getGroundItems().closest(item -> item.getName().equals("Raw rat meat"));
    int oldEmptyInventorySlotCount = getInventory().getEmptySlots();
    if (loot != null && loot.interact("Take")) {
        ConditionalSleep2.sleep(10000, () -> getInventory().getEmptySlots() < oldEmptyInventorySlotCount || !loot.exists());
        return getInventory().getEmptySlots() < oldEmptyInventorySlotCount;
    }
    return false;
}

public boolean attackTarget() {
    NPC target = getNpcs().closest(npc -> npc.getName().equals("Giant rat") && npc.isAttackable());
    if (target != null && target.interact("Attack")) {
        ConditionalSleep2.sleep(10000, () -> myPlayer().getInteracting() != null);
        return myPlayer().getInteracting() == target;
    }
    return false;
}

public void idle() {
    getMouse().moveOutsideScreen();
    ConditionalSleep2.sleep(15000, () -> myPlayer().getInteracting() == null);
}

Once you have all of that completed, create a variable that will hold the current bot state.

Spoiler
private BotState botState;

Lastly, you just have to setup the main loop of your script. First set that variable using the calculateBotState method.

Spoiler
@Override
public int onLoop() throws InterruptedException {
    botState = calculateBotState();
    
    return random(300, 2500);
}

Then implement a switch statement that will call the methods when the bot is in its various states.

Spoiler
@Override
public int onLoop() throws InterruptedException {
    botState = calculateBotState();

    switch (botState) {
        case WALK_TO_FIGHT_AREA:
            walkToFightArea(ratsArea);
            break;
        case PICKUP_LOOT:
            pickupLoot();
            break;
        case ATTACK_TARGET:
            attackTarget();
            break;
        case IDLE:
            idle();
            break;
    }
    
    return random(300, 2500);
}

Hopefully this helps you out in your scripting adventures!

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