Introduction
FogBot scripts run inside the bot as C# code and communicate with the game through the FogBot.Objects API. This documentation contains all public methods and properties intended for script authors.
public class ExternalScript { ... }
Script Lifecycle
The Main method is called once. For continuous operation, use a while (true) loop with Thread.Sleep(...).
Quick Examples
using System;
using System.Threading;
using FogBot.Objects;
public class ExternalScript {
public static void Main(Client client) {
Random rand = new Random();
while (true) {
Thread.Sleep(rand.Next(800, 1600));
if (!client.Player.Connected) continue;
if (client.Player.HealthPercent <= 70 && client.Player.Mana >= 40) {
client.Packets.Say("exura gran");
Thread.Sleep(rand.Next(600, 900));
}
}
}
}
using System;
using System.Linq;
using System.Threading;
using FogBot.Objects;
public class ExternalScript {
public static void Main(Client client) {
ushort goldId = 3031;
while (true) {
Thread.Sleep(100);
if (!client.Player.Connected) continue;
var lootBag = client.Inventory.GetContainers()
.FirstOrDefault(c => c.IsOpen && !c.IsFull);
if (lootBag == null) continue;
var tiles = client.Map.GetTilesOnScreen();
foreach (var t in tiles.GetTiles()) {
if (!t.ContainsObject(goldId)) continue;
var item = t.GetTopMoveItem();
if (item == null) continue;
var slot = lootBag.GetBestSlot(item.ToItemLocation());
if (slot == null) continue;
item.Move(slot);
item.WaitForInteraction(500);
}
}
}
}
using System;
using System.Linq;
using System.Threading;
using FogBot.Objects;
public class ExternalScript {
public static void Main(Client client) {
Random rand = new Random();
ushort[] waterIDs = new ushort[] { 4597, 4598, 4599, 4600 };
while (true) {
Thread.Sleep(rand.Next(600, 1200));
if (!client.Player.Connected || client.Player.Cap <= 7) continue;
Item rod = client.Inventory.GetItem(client.ItemList.Tools.FishingRod);
if (rod == null) continue;
var fishyTiles = client.Map.GetTilesWithObjects(waterIDs).GetTiles().ToList();
if (fishyTiles.Count == 0) continue;
var tile = fishyTiles[rand.Next(fishyTiles.Count)];
rod.UseOnLocation(tile.WorldLocation);
Thread.Sleep(rand.Next(250, 500));
}
}
}
FogBot.Objects.Client
Main entry point to the API. Provides access to player, map, inventory, packets, modules, and helpers.
Properties
Methods
FogBot.Objects.Player
Represents your player. Properties reflect in-game values and can be read/set.
Properties
Methods
// Set attack target
client.Player.Target = creatureID;
// Start walking
client.Player.GoTo = new Location(100, 200, 7);
// Make UH runes until mana > 30% max
client.Player.MakeRune("adura vita", 100, true, (ushort)(client.Player.ManaMax * 0.3));
// Set light hack (bright yellow light)
if (client.Player.Light < 8) {
client.Player.Light = 20;
client.Player.LightColor = 215;
}
Client.PacketCollection (client.Packets)
Wrappers for sending packets to the game. Use with caution and delays!
Communication methods
Action methods
if (client.Player.Target != 0) {
Item sd = client.Inventory.GetItem(client.ItemList.Runes.SuddenDeath);
if (sd != null) {
Creature target = client.Player.TargetCreature;
client.Packets.UseItemOnBattleList(sd.ToItemLocation(), target);
Thread.Sleep(500);
}
}
Client.ModuleCollection (client.Modules)
Access to bot modules: Cavebot, Healer, ScriptManager, etc.
Available modules
ScriptManager - Global variables
Use client.Modules.ScriptManager.Variables to store data between script runs.
// Read or set 0
object obj = client.Modules.ScriptManager.Variables.GetValue("MyIndex");
int index = obj != null ? (int)obj : 0;
// Use...
index++;
// Save
client.Modules.ScriptManager.Variables.SetValue("MyIndex", index);
Cavebot
if (client.Modules.Cavebot.IsRunning && client.Player.Target != 0) {
Creature target = client.Player.TargetCreature;
if (target != null) {
foreach (var t in client.Modules.Cavebot.GetTargets()) {
if (t.Name.ToLower() == target.Name.ToLower()) {
var setting = t.GetSettingByIndex(t.CurrentSettingIndex);
if (setting != null && setting.UseThisSetting) {
ushort runeID = setting.GetRuneID();
if (runeID != 0) {
// Target requires runes!
}
}
}
}
}
}
// Jump to waypoint with label "start"
if (client.Player.Mana < 100) {
if (client.Modules.Cavebot.GotoLabel("start")) {
client.Window.StatusBar.SetText("Jumped to start waypoint!", 3);
} else {
client.Window.StatusBar.SetText("Waypoint 'start' not found!", 3);
}
}
// Get current waypoint index
int currentIndex = client.Modules.Cavebot.CurrentWaypointIndex;
client.Window.StatusBar.SetText("Current waypoint: " + currentIndex, 2);
// Start/Stop cavebot
if (client.Modules.Cavebot.IsRunning) {
client.Modules.Cavebot.Stop();
} else {
client.Modules.Cavebot.Start();
}
BattleList & Creature
BattleList provides quick access to nearby creatures and players.
BattleList - Methods
Creature - Properties
Creature - Methods
List<string> whiteList = new List<string>() { "Friend1", "Friend2" };
while (true) {
Thread.Sleep(1000);
if (!client.Player.Connected || client.Player.Target != 0) continue;
foreach (Creature c in client.BattleList.GetPlayers()) {
if (whiteList.Contains(c.Name) || client.Player.Name == c.Name) continue;
if (client.Player.SafeMode != Enums.SafeMode.Disabled)
client.Player.SafeMode = Enums.SafeMode.Disabled;
c.Attack();
break;
}
}
Map & Tile
Access to visible tiles and map queries.
Map - Methods
Tile - Properties
Tile - Methods
TileCollection - Methods
Inventory, Container & Item
Access to player containers and items.
Inventory - Methods
Container - Properties & Methods
Item - Methods
ushort goldId = 3031;
var containers = client.Inventory.GetContainers().ToList();
if (containers.Count == 0) return;
var mainBp = containers[0];
var tiles = client.Map.GetTilesOnScreen();
foreach (var tile in tiles.GetTiles()) {
if (!tile.ContainsObject(goldId)) continue;
var gold = tile.GetTopMoveItem();
if (gold == null) continue;
var slot = mainBp.GetBestSlot(gold.ToItemLocation());
if (slot == null) break; // BP pełny
gold.Move(slot);
gold.WaitForInteraction(500);
Thread.Sleep(100);
}
ItemList (client.ItemList)
Catalog of common item IDs grouped by categories. You can change them in scripts!
Categories
Food (client.ItemList.Food)
Tools (client.ItemList.Tools)
Runes (client.ItemList.Runes)
Rings (client.ItemList.Rings)
Amulets (client.ItemList.Amulets)
Valuables (client.ItemList.Valuables)
public static void Main(Client client) {
// Change IDs for your server
client.ItemList.Food.Ham = 3582;
client.ItemList.Food.Fish = 3578;
client.ItemList.Tools.FishingRod = 3483;
client.ItemList.Runes.UltimateHealing = 3160;
client.ItemList.Runes.Blank = 3147;
client.ItemList.Rings.Life = 3052;
// Now you can use
Item rod = client.Inventory.GetItem(client.ItemList.Tools.FishingRod);
}
Location
3D position in world (X, Y, Z) with helpers.
Constructors
Location(ushort x, ushort y, byte z)
Properties
Methods
Location playerLoc = client.Player.Location;
Location targetLoc = new Location(100, 200, 7);
// Check distance
double dist = playerLoc.DistanceTo(targetLoc);
if (dist > 10) {
client.Player.GoTo = targetLoc;
}
// Use tool on tile next to player (north)
Location north = playerLoc.Offset(0, -1, 0);
Item rope = client.Inventory.GetItem(client.ItemList.Tools.Rope);
if (rope != null) {
rope.UseOnLocation(north);
}
Window & StatusBar
Access to game window and StatusBar.
Window - Properties
Window - Methods
StatusBar - Methods
GameWindow - Methods
Message - Properties
client.Window.StatusBar.SetText("Fishing started!", 5);
Thread.Sleep(5000);
client.Window.StatusBar.SetText("Collecting loot...", 3);
// Check for GM messages
foreach (var msg in client.Window.GameWindow.GetMessages()) {
if (msg.Type == GameWindow.Message.Types.WhiteMessage &&
msg.Text.ToLower().Contains("gamemaster")) {
// GM message detected!
client.Window.StatusBar.SetText("GM message: " + msg.Text, 5);
break;
}
}
// Check for PMs
foreach (var msg in client.Window.GameWindow.GetMessages()) {
if (msg.Type == GameWindow.Message.Types.PrivateMessage) {
client.Window.StatusBar.SetText("PM from " + msg.Sender + ": " + msg.Text, 5);
break;
}
}
// Get window size
var windowSize = client.Window.GetWindowSize();
client.Window.StatusBar.SetText("Window: " + windowSize.Width + "x" + windowSize.Height, 3);
PathFinder & LocalPathFinder
Pathfinding systems. Usually used internally, but available for scripts.
PathFinder (Global)
LocalPathFinder (Local - visible tiles)
Tip: Usually easier to set client.Player.GoTo = targetLocation than manually using PathFinder.
MiniMap
Access to automap. Advanced usage for large maps.
Methods
Note: MiniMap is mainly used by PathFinder. Most scripts don't need direct access.
AreaEffects
Predefined AoE patterns for spells and runes.
Available effects
AreaEffect - Methods
Usage: Mainly for Cavebot and advanced scripts checking AoE coverage.
Enums & Constants
Common enumerators used in API.
Enums.FightStance
Enums.FightMode
Enums.SafeMode
Enums.Direction
Enums.EquipmentSlots
Enums.ObjectPropertiesFlags
// Set fight settings
client.Packets.FightSettings(
Enums.FightMode.Attack,
Enums.FightStance.Offensive,
Enums.SafeMode.Disabled
);
// Check if item is container
if (item.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) {
var container = item.TryOpen();
}
// Turn south
client.Packets.Turn(Enums.Direction.Down);
Full script examples
using System;
using System.Linq;
using System.Threading;
using FogBot.Objects;
public class Test {
public static void Main(Client client) {
string spellName = "adura vita";
ushort spellMana = 100;
Random rand = new Random();
while (true) {
Thread.Sleep(rand.Next(10000, 15000));
if (client.Player.IsWalking) continue;
if (client.Player.Mana >= spellMana && client.Player.ManaPercent >= 80) {
client.Player.MakeRune(spellName, spellMana, true,
(ushort)(client.Player.ManaMax * 0.3));
Thread.Sleep(rand.Next(2000, 5000));
}
// Eat food
foreach (ushort id in client.ItemList.Food.All) {
Item food = client.Inventory.GetItem(id);
if (food != null) {
food.Use();
Thread.Sleep(rand.Next(2000, 6000));
break;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using FogBot.Objects;
public class ExternalScript {
public static void Main(Client client) {
// List of items to collect (ID)
ushort[] lootIDs = new ushort[] { 3031, 2689, 3007 }; // gold, bread, bag
// Open main BP (first)
var containers = client.Inventory.GetContainers().ToList();
if (containers.Count == 0) {
client.Window.StatusBar.SetText("Open a backpack first!", 3);
return;
}
var mainBP = containers[0];
Random rand = new Random();
while (true) {
Thread.Sleep(rand.Next(300, 600));
if (!client.Player.Connected) continue;
if (client.Player.Cap <= 10) break; // End when no cap
var tiles = client.Map.GetTilesOnScreen();
bool foundLoot = false;
foreach (var tile in tiles.GetTiles()) {
bool hasLoot = false;
foreach (ushort lootID in lootIDs) {
if (tile.ContainsObject(lootID)) {
hasLoot = true;
break;
}
}
if (!hasLoot) continue;
var item = tile.GetTopMoveItem();
if (item == null) continue;
var slot = mainBP.GetBestSlot(item.ToItemLocation());
if (slot == null) break; // BP full
item.Move(slot);
item.WaitForInteraction(500);
foundLoot = true;
break;
}
if (!foundLoot) break; // No more loot
}
client.Window.StatusBar.SetText("Loot grabber finished!", 3);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using FogBot.Objects;
public class DepoFish {
public static void Main(Client client) {
const ushort ROD = 3483;
const int MIN_CAP = 50;
ushort[] waterIDs = new ushort[] { 4597, 4598, 4599, 4600, 4601, 4602 };
// Waypoint path
var path = new List<Location>() {
new Location(100, 100, 7),
new Location(105, 100, 7),
new Location(105, 105, 7),
new Location(110, 105, 7)
};
int i = 0;
client.Player.GoTo = path[i];
Random rand = new Random();
while (true) {
Thread.Sleep(300);
if (!client.Player.Connected) continue;
var me = client.Player.Location;
var tgt = path[i];
// Check if we reached waypoint
if (me.IsOnScreen(tgt) && me.DistanceTo(tgt) <= 1) {
i = Math.Min(i + 1, path.Count - 1);
client.Player.GoTo = path[i];
}
// If low cap - continue without fishing
if (client.Player.Cap <= MIN_CAP) continue;
// Fish
var rod = client.Inventory.GetItem(ROD);
if (rod == null) continue;
var waters = client.Map.GetTilesWithObjects(waterIDs).GetTiles().ToList();
foreach (var w in waters) {
if (!me.IsOnScreen(w.WorldLocation)) continue;
rod.UseOnLocation(w.WorldLocation);
Thread.Sleep(rand.Next(800, 1500));
break;
}
}
}
}
using FogBot.Objects;
using System;
public class ComboNow {
public static void Main(Client client) {
var id = client.Player.Target;
if (id == 0) return;
// Broadcast to all clients through Combobot server
client.Modules.CombobotServer.Combo(id);
}
}
using System;
using System.Threading;
using FogBot.Objects;
public class ExternalScript {
public static void Main(Client client) {
ushort lifeRingID = client.ItemList.Rings.Life;
int switchHP = 300; // Change when HP < 300
Random rand = new Random();
while (true) {
Thread.Sleep(rand.Next(500, 1000));
if (!client.Player.Connected) continue;
if (client.Player.Health < switchHP) {
// Check if we already have ring
var currentRing = client.Inventory.GetItemInSlot(Enums.EquipmentSlots.Ring);
if (currentRing != null && currentRing.ID == lifeRingID) continue;
// Find life ring in BP
var lifeRing = client.Inventory.GetItem(lifeRingID);
if (lifeRing == null) continue;
// Move to ring slot
lifeRing.Move(new Location(0, 0, 9).ToItemLocation()); // 9 = Ring slot
lifeRing.WaitForInteraction(800);
client.Window.StatusBar.SetText("Life ring equipped!", 2);
}
}
}
}
using System;
using System.Threading;
using FogBot.Objects;
public class ExternalScript {
public static void Main(Client client) {
Random rand = new Random();
while (true) {
Thread.Sleep(rand.Next(500, 1000));
if (!client.Player.Connected) continue;
// If low mana, jump to start waypoint
if (client.Player.Mana < 100) {
if (client.Modules.Cavebot.GotoLabel("start")) {
client.Window.StatusBar.SetText("Low mana - jumped to start!", 3);
}
continue;
}
// If low health, jump to safe waypoint
if (client.Player.HealthPercent < 30) {
if (client.Modules.Cavebot.GotoLabel("safe")) {
client.Window.StatusBar.SetText("Low HP - jumped to safe spot!", 3);
}
continue;
}
// If low cap, jump to depot waypoint
if (client.Player.Cap < 50) {
if (client.Modules.Cavebot.GotoLabel("depot")) {
client.Window.StatusBar.SetText("Low cap - going to depot!", 3);
}
continue;
}
}
}
}