Magic API

The Magic API provides methods to interact with OSRS magic spells, spellbooks, and rune management.

API Reference

Basic Usage

-- Cast a spell using enum constants
magic:cast(magic.Spell.Modern.HIGH_ALCHEMY)
magic:cast(magic.Spell.Ancient.ICE_BARRAGE)

-- Check if you can cast a spell
if magic:can_cast(magic.Spell.Modern.HIGH_ALCHEMY) then
    magic:cast(magic.Spell.Modern.HIGH_ALCHEMY)
end

-- Get current spellbook
local book = magic:book()  -- Returns: "Modern", "Ancient", "Lunar", or "Arceuus"

-- Check for rune requirements
local level = magic:spell_level(magic.Spell.Modern.FIRE_SURGE)

Spell Enums

All spells are available as enum constants under magic.Spell:

-- Modern spellbook
magic.Spell.Modern.HIGH_ALCHEMY
magic.Spell.Modern.FIRE_SURGE
magic.Spell.Modern.LUMBRIDGE_TELEPORT

-- Ancient spellbook
magic.Spell.Ancient.ICE_BARRAGE
magic.Spell.Ancient.BLOOD_BLITZ

-- Lunar spellbook
magic.Spell.Lunar.VENGEANCE
magic.Spell.Lunar.MOONCLAN_TELEPORT

-- Arceuus spellbook
magic.Spell.Arceuus.BARROWS_TELEPORT
magic.Spell.Arceuus.RESURRECT_CROPS

Methods

magic:cast(spell_name)

Cast a spell by name.

Parameters:

ParameterTypeRequiredDescription
spell_namestringYesThe spell name from magic.Spell enum

Returns:

  • boolean: true if cast was successful

Example:

magic:cast(magic.Spell.Modern.HIGH_ALCHEMY)
magic:cast(magic.Spell.Ancient.ICE_BARRAGE)

magic:can_cast(spell_name)

Check if you can cast a spell (have required level and runes).

Parameters:

ParameterTypeRequiredDescription
spell_namestringYesThe spell name from magic.Spell enum

Returns:

  • boolean: true if spell can be cast

Example:

if magic:can_cast(magic.Spell.Lunar.VENGEANCE) then
    magic:cast(magic.Spell.Lunar.VENGEANCE)
end

magic:book()

Get the current spellbook name.

Returns:

  • string: "Modern", "Ancient", "Lunar", or "Arceuus"

Example:

local spellbook = magic:book()
if spellbook == "Ancient" then
    magic:cast("IceBarrage")
end

magic:has_rune_pouch()

Check if player has a rune pouch equipped or in inventory.

Returns:

  • boolean: true if rune pouch is available

magic:rune_pouch_contents()

Get the contents of the rune pouch.

Returns:

  • table: Array of rune entries with rune and quantity fields

Example:

local contents = magic:rune_pouch_contents()
for i, entry in ipairs(contents) do
    logger:info("Rune: " .. entry.rune .. ", Qty: " .. entry.quantity)
end

magic:has_runes(power_name, amount)

Check if player has runes for a rune power.

Parameters:

ParameterTypeRequiredDescription
power_namestringYesRune power name (e.g., "Fire", "Water", "Blood")
amountnumberNoAmount required (default: 1)

Returns:

  • boolean: true if player has the runes

Rune Powers:

  • Air, Water, Fire, Earth
  • Mind, Body, Cosmic, Chaos
  • Nature, Death, Astral, Law
  • Soul, Blood, Wrath

Example:

if magic:has_runes("Fire", 5) then
    -- Has at least 5 fire runes
end

magic:spell_level(spell_name)

Get the magic level requirement for a spell.

Parameters:

ParameterTypeRequiredDescription
spell_namestringYesThe spell name from magic.Spell enum

Returns:

  • number: Required magic level (0 if spell not found)

Example:

local level = magic:spell_level(magic.Spell.Ancient.ICE_BARRAGE)
logger:info("Ice Barrage requires level " .. level)

magic:spell_runes(spell_name)

Get the rune requirements for a spell.

Parameters:

ParameterTypeRequiredDescription
spell_namestringYesThe spell name from magic.Spell enum

Returns:

  • table: Array of rune requirement entries with rune and amount fields

Example:

local runes = magic:spell_runes(magic.Spell.Ancient.ICE_BARRAGE)
for i, req in ipairs(runes) do
    logger:info("Need " .. req.amount .. " " .. req.rune .. " runes")
end

Complete Spell List

Modern Spellbook

Combat Spells

  • HomeTeleport
  • WindStrike, WaterStrike, EarthStrike, FireStrike
  • WindBolt, WaterBolt, EarthBolt, FireBolt
  • WindBlast, WaterBlast, EarthBlast, FireBlast
  • WindWave, WaterWave, EarthWave, FireWave
  • WindSurge, WaterSurge, EarthSurge, FireSurge
  • CrumbleUndead
  • IbanBlast
  • MagicDart
  • SaradominStrike
  • ClawsOfGuthix
  • FlamesOfZamorak

Support Spells

  • Confuse, Weaken, Curse
  • Vulnerability, Enfeeble, Stun
  • Bind, Snare, Entangle
  • TeleBlock
  • Charge

Utility Spells

  • LowLevelAlchemy, HighAlchemy
  • TelekineticGrab
  • SuperheatItem
  • BonesToBananas, BonesToPeaches
  • EnchantCrossbowBolt
  • EnchantLevel1Jewellery, EnchantLevel2Jewellery, EnchantLevel3Jewellery
  • EnchantLevel4Jewellery, EnchantLevel5Jewellery, EnchantLevel6Jewellery
  • EnchantLevel7Jewellery
  • ChargeWaterOrb, ChargeEarthOrb, ChargeFireOrb, ChargeAirOrb

Teleport Spells

  • VarrockTeleport, LumbridgeTeleport, FaladorTeleport
  • CamelotTeleport, ArdougneTeleport
  • WatchtowerTeleport, TrollheimTeleport
  • TeleportToHouse
  • TeleportApeAtoll
  • KourendCastleTeleport
  • CivitasIllaFortisTeleport
  • TeleotherLumbridge, TeleotherFalador, TeleotherCamelot
  • TeleportToBountyTarget

Ancient Spellbook

Combat Spells

  • Rush Spells (52+): SmokeRush, ShadowRush, BloodRush, IceRush
  • Burst Spells (62+): SmokeBurst, ShadowBurst, BloodBurst, IceBurst
  • Blitz Spells (74+): SmokeBlitz, ShadowBlitz, BloodBlitz, IceBlitz
  • Barrage Spells (86+): SmokeBarrage, ShadowBarrage, BloodBarrage, IceBarrage

Teleport Spells

  • HomeTeleport
  • PadewwaTeleport (54)
  • SennistenTeleport (60)
  • KharyllTeleport (66)
  • LassarTeleport (72)
  • DareeyakTeleport (78)
  • CarrallangarTeleport (84)
  • AnnakarlTeleport (90)
  • GhorrockTeleport (96)
  • TeleportToBountyTarget

Lunar Spellbook

Support & Utility Spells

  • HomeTeleport
  • BakePie (65)
  • CurePlant (66)
  • MonsterExamine (66)
  • NpcContact (67)
  • CureOther (68)
  • Humidify (68)
  • CureMe (71)
  • HunterKit (71)
  • CureGroup (74)
  • StatSpy (75)
  • SuperglassMake (77)
  • TanLeather (78)
  • Dream (79)
  • StringJewellery (80)
  • StatRestorePotShare (81)
  • MagicImbue (82)
  • FertileSoil (83)
  • BoostPotionShare (84)
  • PlankMake (86)
  • RechargeDragonstone (89)
  • EnergyTransfer (91)
  • HealOther (92)
  • VengeanceOther (93)
  • Vengeance (94)
  • HealGroup (95)
  • SpellBookSwap (96)
  • Geomancy (97)
  • SpinFlax (97)

Teleport Spells

  • MoonclanTeleport (69)
  • TeleGroupMoonclan (70)
  • WaterbirthTeleport (72)
  • TeleGroupWaterbirth (73)
  • BarbarianTeleport (75)
  • TeleGroupBarbarian (76)
  • KhazardTeleport (78)
  • TeleGroupKhazard (79)
  • FishingGuildTeleport (85)
  • TeleGroupFishingGuild (86)
  • CatherbyTeleport (87)
  • TeleGroupCatherby (88)
  • IcePlateauTeleport (89)
  • TeleGroupIcePlateau (90)
  • OuraniaTeleport (71)

Arceuus Spellbook

Combat Spells

  • HomeTeleport
  • GhostlyGrasp (35)
  • InferiorDemonbane (44)
  • SkeletalGrasp (56)
  • SuperiorDemonbane (62)
  • LesserCorruption (64)
  • UndeadGrasp (79)
  • DarkDemonbane (82)
  • GreaterCorruption (85)

Reanimation Spells

  • BasicReanimation (16)
  • AdeptReanimation (41)
  • ExpertReanimation (72)
  • MasterReanimation (90)

Resurrection Spells

  • ResurrectLesserGhost, ResurrectLesserSkeleton, ResurrectLesserZombie (38)
  • ResurrectSuperiorGhost, ResurrectSuperiorSkeleton, ResurrectSuperiorZombie (57)
  • ResurrectGreaterGhost, ResurrectGreaterSkeleton, ResurrectGreaterZombie (76)

Utility Spells

  • ShadowVeil (47)
  • DarkLure (50)
  • MarkOfDarkness (59)
  • VileVigour (66)
  • Degrime (70)
  • ResurrectCrops (78)
  • DeathCharge (80)
  • DemonicOffering (84)
  • SinisterOffering (92)
  • WardOfArceuus (73)

Teleport Spells

  • ArceuusLibraryTeleport (6)
  • DraynorManorTeleport (17)
  • BattlefrontTeleport (23)
  • MindAltarTeleport (28)
  • RespawnTeleport (34)
  • SalveGraveyardTeleport (40)
  • FenkenstainCastleTeleport (48)
  • WestArdougneTeleport (61)
  • HarmonyIslandTeleport (65)
  • CemeteryTeleport (71)
  • BarrowsTeleport (83)
  • ApeAtollTeleport (90)

Common Patterns

High Alchemy Loop

local HIGH_ALCH = magic.Spell.Modern.HIGH_ALCHEMY

while true do
    if magic:can_cast(HIGH_ALCH) then
        local item = inventory:find_first({name = "Rune platebody"})
        if item then
            magic:cast(HIGH_ALCH)
            sleep(1800)  -- Wait for spell cooldown
        else
            break
        end
    else
        logger:warn("Out of runes")
        break
    end
end

Combat Spell with Rune Check

local ICE_BARRAGE = magic.Spell.Ancient.ICE_BARRAGE

function attack_with_magic()
    if not magic:can_cast(ICE_BARRAGE) then
        logger:warn("Cannot cast Ice Barrage")
        return false
    end

    local target = npcs:find_first({name = "Greater demon"})
    if target then
        magic:cast(ICE_BARRAGE)
        target:click()
        return true
    end

    return false
end

Teleport with Spellbook Check

function teleport_home()
    local book = magic:book()

    if book == "Modern" then
        magic:cast(magic.Spell.Modern.LUMBRIDGE_TELEPORT)
    elseif book == "Ancient" then
        -- Ancient has no home city teleports
        magic:cast(magic.Spell.Ancient.HOME_TELEPORT)
    elseif book == "Lunar" then
        magic:cast(magic.Spell.Lunar.MOONCLAN_TELEPORT)
    elseif book == "Arceuus" then
        magic:cast(magic.Spell.Arceuus.ARCEUUS_LIBRARY_TELEPORT)
    end
end

Check Spell Requirements

local VENGEANCE = magic.Spell.Lunar.VENGEANCE

function can_use_vengeance()
    local required_level = magic:spell_level(VENGEANCE)
    local my_level = skills:current_level("magic")

    if my_level < required_level then
        logger:error("Need level " .. required_level .. " magic")
        return false
    end

    local runes = magic:spell_runes(VENGEANCE)
    for _, req in ipairs(runes) do
        if not magic:has_runes(req.rune, req.amount) then
            logger:error("Missing " .. req.amount .. " " .. req.rune .. " runes")
            return false
        end
    end

    return true
end

Notes

  • Always use the magic.Spell enum constants for type safety and autocomplete support
  • All spells are automatically verified against your current magic level and available runes
  • The API automatically checks for runes in both inventory and rune pouch
  • Spell cooldowns are handled by the game engine, not the API
  • Use magic:can_cast() before casting to prevent wasted actions
  • Store frequently used spell enums in local variables for cleaner code

See Also

  • Inventory API - Managing inventory and items
  • Combat API - Combat-related functions
  • Skills API - Skill levels and experience