📓
TFS Guide
  • Preface
  • Progress
  • Unique TFS Concepts
  • Interface - Actions
    • Registration
    • Scripting
    • Revscriptsys
  • Interface - Chatchannels
    • Registration
    • Scripting
  • Interface - Creaturescripts
    • Registration
    • Scripting
    • Revscriptsys
  • Interface - Events
    • Registration
    • Scripting
  • Interface - Globalevents
    • Registration
    • Scripting
    • Revscriptsys
  • Interface - Monster
    • Registration
    • Scripting
    • Revscriptsys
  • Interface - Movements
    • Registration
    • Scripting
    • Revscriptsys
  • Interface - NPC
    • Registration
    • Scripting
  • Interface - Spells
    • Registration
    • Scripting
  • Interface - Talkactions
    • Registration
    • Scripting
  • Interface - Weapons
    • Registration
    • Scripting
  • Source Editing
    • Creating new events
    • Creating new Lua functions
  • Function Documentation
    • Game
Powered by GitBook
On this page
  • Script Structure
  • Examples

Was this helpful?

  1. Interface - Creaturescripts

Revscriptsys

Script Structure

Constructor:

  • CreatureEvent(eventName)

  • eventName: equivalent to the name tag in XML.

Events:

  • onLogin(player)

  • onLogout(player)

  • onThink(creature, interval)

  • onPrepareDeath(creature, killer)

  • onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)

  • onKill(creature, target)

  • onAdvance(player, skill, oldLevel, newLevel)

  • onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

  • onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

  • onTextEdit(player, item, text)

  • onModalWindow(player, modalWindowId, buttonId, choiceId)

  • onExtendedOpcode(player, opcode, buffer)

Methods:

  • creatureEvent:register(): Finalizes the creatureEvent's definition and registers it.

  • creatureEvent:type(eventType):

  • eventType: Equivalent to the type tag in XML.

Examples

local loginEvent = CreatureEvent("newLoginEvent")
loginEvent:type("login")

function loginEvent.onLogin(player)
    print(player:getName() .. " has logged in!")
    return true
end

loginEvent:register()
local function damageMitigator(primaryDamage, secondaryDamage, mul)
    primaryDamage = primaryDamage - (primaryDamage * mul)
    secondaryDamage = secondaryDamage - (secondaryDamage * mul)
    return primaryDamage, secondaryDamage
end

local healthChange = CreatureEvent("healthChangeMitigate")
healthChange:type("healthchange")

function healthChange.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType)
    -- Reduce health damage by 50%
    primaryDamage, secondaryDamage = damageMitigator(primaryDamage, secondaryDamage, 0.5)
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

healthChange:register()

local manaChange = CreatureEvent("manaChangeMitigate")
manaChange:type("manachange")

function manaChange.onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType)
    -- Reduce mana damage by 75%
    primaryDamage, secondaryDamage = damageMitigator(primaryDamage, secondaryDamage, 0.75)
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

manaChange:register()

local loginEvent = CreatureEvent("mitigatorRegistration")
loginEvent:type("login")

function loginEvent.onLogin(player)
    -- Register both health/mana change mitigators to every single player who logs in
    player:registerEvent("healthChangeMitigate")
    player:registerEvent("manaChangeMitigate")
    return true
end

loginEvent:register()
PreviousScriptingNextRegistration

Last updated 5 years ago

Was this helpful?