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
  • Would someone help tell me why this script only do once?


    hilarion4

    Recommended Posts

    Posted

    Im new and im trying to code some dreamt scripts. here's my code.

    Quote

     

     

     

    
    import org.dreambot.api.methods.item.GroundItems;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.utilities.Logger;
    import org.dreambot.api.utilities.Sleep;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
    import org.dreambot.api.script.Category;
    
    
    
    import org.dreambot.api.methods.interactive.NPCs;
    
    @ScriptManifest(name = "Chicken Killer", description = "My script description!", author = "Developer Name",
                    version = 1.0, category = Category.COMBAT, image = "")                             
    public class teste extends AbstractScript {
    	
    
    	GroundItem pena = GroundItems.closest("Feather");
    	NPC chicken = NPCs.closest("Chicken");
    	private int state = 0;
    	@Override
        public int onLoop() {
    		
    		if (state == 0) {
    		matar();
    		}
    		if (state != 0) {
    			coletar();
    		}
    		
    		return 0;
    
    }
    
    	private void matar() {
    		
    		if (chicken != null) {
    			chicken.interact("Attack");
    			Logger.log("Atacou");
    			Sleep.sleep(4000,5000);
    			state++;
    			}
    		}
    		
    	private void coletar() {
    				if (pena != null) 
    				{
    				pena.interact("Take");
    				Logger.log("Pegou");
    				state = 0;
    		}
    
    		
    			
    		}
    	
    		
    		
    	}
    	

     

    Posted

    Welcome!  Taking a quick look I would advise to search for the closest npc every time before attacking and null checking.  If you search once and that npc dies it is now null.  

    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.