I started Scripting with DreamBot a little while ago... I hope i made some progress in learning the API. I have looked at many references. Can some please fact check my code.
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.filter.Filter;
import org.dreambot.api.methods.interactive.NPCs;
import org.dreambot.api.methods.interactive.Players;
import org.dreambot.api.methods.item.GroundItems;
import org.dreambot.api.methods.magic.Magic;
import org.dreambot.api.methods.magic.Normal;
import org.dreambot.api.methods.walking.impl.Walking;
import org.dreambot.api.script.AbstractScript;
import org.dreambot.api.script.Category;
import org.dreambot.api.script.ScriptManifest;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.map.Area;
import org.dreambot.api.methods.map.Tile;
import org.dreambot.api.script.AbstractScript;
import org.dreambot.api.script.Category;
import org.dreambot.api.script.ScriptManifest;
import org.dreambot.api.wrappers.interactive.NPC;
import org.dreambot.api.wrappers.interactive.Player;
import org.dreambot.api.wrappers.items.GroundItem;
import org.dreambot.api.wrappers.items.Item;
import java.util.Random;
import static org.dreambot.api.methods.magic.Normal.*;
@ScriptManifest(name = "MasterScript", description = "My 1st Script", author = "MasterSemtax",
version = 1.0, category = Category.MISC, image = "")
public class ZenithScript extends AbstractScript {
int STAGE = 0;
// Define Player as LocalPlayer
Player player = Players.getLocal();
// Define the Wizard's Tower area
Area wizardsTower = new Area(3106, 3935, 3115, 3940);
// Define the top Floor of the Wizards Tower
Area wizardsTowerTopFloor = new Area(3108, 3929, 3111, 3928, 2);
Tile TOP_FLOOR_DEMON_ROOM_A = new Tile(3109, 3928, 2);
Tile TOP_FLOOR_DEMON_ROOM_B = new Tile(3110, 3929, 2);
Tile TOP_FLOOR_DEMON_ROOM_C = new Tile(3111, 3928, 2);
Tile TOP_FLOOR_DEMON_ROOM_D = new Tile(3110, 3928, 2);
Random random = new Random();
int floor = 0;
public Tile returnRandomTile(){
STAGE = 1;
floor = random.nextInt(4);
if(floor == 0){ return TOP_FLOOR_DEMON_ROOM_A;
} else if (floor == 1) { return TOP_FLOOR_DEMON_ROOM_B;
} else if (floor == 2) { return TOP_FLOOR_DEMON_ROOM_C;
} else {
return TOP_FLOOR_DEMON_ROOM_D;
}
}
public void walkToWizardsTower(){
// Check if the player is already at the wizard's tower
if (wizardsTower.contains(player)) {
// Than walk to TOP Floor at a random Tile
STAGE = 3;
Walking.walk(returnRandomTile());
} else {
// Walk to the wizard's tower
STAGE = 2;
Walking.walk(wizardsTower);
}
}
public boolean isPlayerInRoom(){
if(wizardsTowerTopFloor.contains(player)){
STAGE = 4;
return true;
}
return false;
}
boolean hasAirStaff = false;
boolean hasMindRunes = false;
int equiped_tick = 0;
public boolean hasRequirements() {
log("Checking for Air Staff...");
for(Item item : player.getEquipment()){
if(item.getName().contains("Staff of air") || item.getID() == 1381){
STAGE = 5;
hasAirStaff = true;
break;
}
}
if(hasAirStaff){
equiped_tick++;
if(equiped_tick <= 3){
log("Staff of Air is equipped...");
}
}else {
log("Staff of Air is missing...");
}
if(Inventory.count(558) >= 1){
STAGE = 6;
log("Player holds [ " + Inventory.count(558) + " ]");
hasMindRunes = true;
}else {
log("Player holds zero mind runes");
hasMindRunes = false;
}
return hasAirStaff && Inventory.count(558) >= 1;
}
public void autoCastWindStrike(){
if(hasRequirements()){
NPC npc = NPCs.closest("lesser demon");
if (npc != null) {
Magic.castSpellOn(WIND_STRIKE, npc);
}
}
}
Area telegrabArea = new Area(3107, 3926, 3113, 3923,2);
public void autoCastTelegrab(){
// Check if the player is in the telegrab area
if (telegrabArea.contains(player)) {
// Find the closest ground item
GroundItem item = GroundItems.closest((Filter<GroundItem>) telegrabArea);
// Check if the item exists and is visible
if (item != null && item.isOnScreen()) {
// Cast telegrab on the item
Magic.castSpellOn(TELEKINETIC_GRAB, item);
}
}
}
@Override
public void onStart() {
log("Setting up Zenith Script...");
walkToWizardsTower();
}
@Override
public int onLoop() {
autoCastWindStrike();
//autoCastTelegrab();
return Calculations.random(542, 1340);
}
@Override
public void onExit() {
log("Stopping Zenith Script...");
}
}