Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Dealing with other players (combat script)


    supadupap00p

    Recommended Posts

    Posted

    Hey guys,
    This references my previous post, I'm generally okay with dealing with other players using the following line:

    NPC cow = NPCs.closest(c -> c != null && c.getName().contains(target) && !c.isHealthBarVisible() && !c.isInCombat() && c.getInteractingCharacter() == null && !c.isInteractedWith());

    I know its overkill now but I kept having this issue where my player would attack a cow that was in combat with someone else. On closer inspection however this seemed to only be happening with players who were using ranged/magic and seemed to only happen when the bot and the other player clicked the cow at roughly the same time.

    When this happens the bot will just stop doing anything until the cow that the other player is attacking is dead, then it will resume normal behaviour.

    I was wondering is there a way to detect say after the bot has clicked and the message shows up that "Someone else is fighting that." that the bot should immediately look for another target?

    Again any pointers would be much appreciated. 

    Posted

    Implement ChatListener and utilize the onGameMessage function.

    Edit: Do not perform the action within that thread though. You should only interact through your onLoop

    Posted

    You can do an animation check, if(Client.getLocalPlayer().isAnimating()){} after it attacks the cow> then sleepUntil the cow is dead; otherwise just try to find another target using your filter, if that makes sense.

    I would go about doing this like this:

    NPC cow = NPCs.closest(c -> c != null && c.getName().contains(target) && !c.isHealthBarVisible() && !c.isInCombat() && c.getInteractingCharacter() == null && !c.isInteractedWith());
    
    if(cow != null){
    
    	if(cow.interact()){
    
    		methodProvider.sleepUntil(()-> Client.getLocalPlayer().isAnimating(),Calculations.random(5000,7000));
    
    		if(Client.getLocalPlayer().isAnimating()){
    
    			// logic goes here; if the player isn't animating, it'll find another suitable target basically
    
    		}
    
    	}
    }
    MethodProvider.sleep(Calculations.random(200,400));

    And you can take it step further by sleeping until the player stops moving, and then see if they're animating or not

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.