# Revscriptsys

### Script Structure

> **Constructor**:
>
> * *Game.createMonsterType(mTypeName)*
> * > mTypeName: Name for the monster type, equivalent to the `name` tag in monsters.xml.
>
> **Events**:
>
> * onThink(monster, interval)
> * onAppear(monster, creature)
> * onDisappear(monster, creature)
> * onMove(monster, creature, fromPosition, toPosition)
> * onSay(monster, creature, type, message)
>
> **Methods**:
>
> * register(): Finalizes the Monster Type definition and registers it.
> * name(newName):
> * > newName: Name shown above the monster when created in-game.
> * nameDescription(desc):
> * > desc: Name description for the monster (You see "***a demon"***).
> * health(hp):
> * > hp: Health the monster spawns at.
> * maxHealth(maxHp):
> * > maxHp: Maximum health the monster can have.
> * runHealth(runHp):
> * > runHp: Once the monster reaches the `runHp` threshold, it will run away from players.
> * experience(exp):
> * > exp: Base experience gained by players who kill it.
> * combatImmunities(immunity):
> * > immunity:
>   >
>   > > physical
>   > >
>   > > energy
>   > >
>   > > fire
>   > >
>   > > poison or earth
>   > >
>   > > drown
>   > >
>   > > ice
>   > >
>   > > holy
>   > >
>   > > death
>   > >
>   > > lifedrain
>   > >
>   > > manadrain
> * conditionImmunities(immunity):
> * > immunity:
>   >
>   > > physical
>   > >
>   > > energy
>   > >
>   > > fire
>   > >
>   > > poison or earth
>   > >
>   > > drown
>   > >
>   > > ice
>   > >
>   > > holy
>   > >
>   > > death
>   > >
>   > > paralyze
>   > >
>   > > outfit
>   > >
>   > > drunk
>   > >
>   > > invisible or invisibility
>   > >
>   > > bleed
> * addAttack(spell):
> * > spell: MonsterSpell userdata, see function documentation.
> * addDefense(spell):
> * > spell: MonsterSpell userdata, see function documentation.
> * addElement(type, percent):
> * > type: Element type (use the enums from [Here](https://github.com/otland/forgottenserver/blob/d342e499429ec3204edd2af2d621b8430576f276/src/enums.h#L183-L194))
>   >
>   > percent: Resistance percent.
> * addVoice(sentence, interval, chance, yell):
> * > sentence: Sentence (text) to say.
>   >
>   > interval: Milliseconds between each attempt to say the sentence.
>   >
>   > chance: Chance to say the sentence.
>   >
>   > yell: Boolean, true will make the sentence a yell, otherwise it won't.
> * addLoot(loot):
> * > loot: Loot userdata, see function documentation.
> * registerEvent(eventName):
> * > eventName: Event name from creaturescripts to register to the monster.
> * eventType(type):
> * > type: Event types found [Here](https://github.com/otland/forgottenserver/blob/d342e499429ec3204edd2af2d621b8430576f276/src/enums.h#L619-L624).
> * addSummon(name, interval, chance):
> * > name: Monster name to summon.
>   >
>   > interval: Milliseconds between each attempt to spawn the summon.
>   >
>   > chance: Chance to summon.
> * maxSummons(amount):
> * > amount: Amount of maximum summons the monster can spawn.
> * armor(arm):
> * > arm: Base monster armor.
> * defense(def):
> * > def: Base monster defense.
> * outfit(outfit):
> * > outfit: Table containing outfit data
>   >
>   > > lookMount
>   > >
>   > > lookAddons
>   > >
>   > > lookFeet
>   > >
>   > > lookLegs
>   > >
>   > > lookBody
>   > >
>   > > lookHead
>   > >
>   > > lookType
>   > >
>   > > lookTypeEx
> * race(race):
> * > race:
>   >
>   > > venom: Green damage numbers, green splash, CONST\_ME\_HITBYPOISON damage effect.
>   > >
>   > > blood: Red damage numbers, red splash, CONST\_ME\_DRAWBLOOD damage effect.
>   > >
>   > > undead: Grey damage numbers, CONST\_ME\_HITAREA damage effect.
>   > >
>   > > fire: Orange damage numbers, CONST\_ME\_DRAWBLOOD damage effect.
>   > >
>   > > energy: Purple damage numbers, CONST\_ME\_ENERGYHIT damage effect.
> * corpseId(id):
> * > id: Corpse item ID for when the monster dies.
> * manaCost(cost):
> * > cost: Mana cost to summon the monster via a spell such as `utevo res`.
> * baseSpeed(speed):
> * > speed: Base speed at which the monster runs at with no buffs or debuffs.
> * light(color, level):
> * > color: Color number.
>   >
>   > level: Level of intensity.
> * staticAttackChance(chance):
> * > chance: Chance to use a static / basic attack.
> * targetDistance(distance):
> * > distance: Distance in sqm that the monster will attempt to stay at between targets.
> * yellChance(chance):
> * > chance: Chance to yell at each interval.
> * yellSpeedTicks(rate):
> * > rate: Interval at which the monster tries to yell.
> * changeTargetChance(chance):
> * > chance: Chance to swap targets at each interval.
> * changeTargetSpeed(speed):
> * > speed: Interval at which the monster tries to change target.

### Examples

These examples use a table to mask the definition without having to manually call each method, which makes the registration much easier for things like loot and spells.

Default TFS example:

```lua
local mType = Game.createMonsterType("example")
local monster = {}
monster.description = "an example"
monster.experience = 1
monster.outfit = {
    lookType = 37
}

monster.health = 99200
monster.maxHealth = monster.health
monster.race = "fire"
monster.corpse = 5995
monster.speed = 280
monster.maxSummons = 2

monster.changeTarget = {
    interval = 4*1000,
    chance = 20
}

monster.flags = {
    summonable = false,
    attackable = true,
    hostile = true,
    convinceable = false,
    illusionable = false,
    canPushItems = true,
    canPushCreatures = true,
    targetDistance = 1,
    staticAttackChance = 70
}

monster.summons = {
    {name = "demon", chance = 10, interval = 2*1000}
}

monster.voices = {
    interval = 5000,
    chance = 10,
    {text = "I'm an example", yell = false},
    {text = "You shall bow", yell = false}
}

monster.loot = {
    {id = "gold coin", chance = 60000, maxCount = 100},
    {id = "bag", chance = 60000,
        child = {
            {id = "platinum coin", chance = 60000, maxCount = 100},
            {id = "crystal coin", chance = 60000, maxCount = 100}
        }
    }
}

monster.attacks = {
    {name = "melee", attack = 130, skill = 70, effect = CONST_ME_DRAWBLOOD, interval = 2*1000},
    {name = "energy strike", range = 1, chance = 10, interval = 2*1000, minDamage = -210, maxDamage = -300, target = true},
    {name = "combat", type = COMBAT_MANADRAIN, chance = 10, interval = 2*1000, minDamage = 0, maxDamage = -120, target = true, range = 7, effect = CONST_ME_MAGIC_BLUE},
    {name = "combat", type = COMBAT_FIREDAMAGE, chance = 20, interval = 2*1000, minDamage = -150, maxDamage = -250, radius = 1, target = true, effect = CONST_ME_FIREAREA, shootEffect = CONST_ANI_FIRE},
    {name = "speed", chance = 15, interval = 2*1000, speed = -700, radius = 1, target = true, duration = 30*1000, effect = CONST_ME_MAGIC_RED},
    {name = "firefield", chance = 10, interval = 2*1000, range = 7, radius = 1, target = true, shootEffect = CONST_ANI_FIRE},
    {name = "combat", type = COMBAT_LIFEDRAIN, chance = 10, interval = 2*1000, length = 8, spread = 0, minDamage = -300, maxDamage = -490, effect = CONST_ME_PURPLEENERGY}
}

monster.defenses = {
    defense = 55,
    armor = 55,
    {name = "combat", type = COMBAT_HEALING, chance = 15, interval = 2*1000, minDamage = 180, maxDamage = 250, effect = CONST_ME_MAGIC_BLUE},
    {name = "speed", chance = 15, interval = 2*1000, speed = 320, effect = CONST_ME_MAGIC_RED}
}

monster.elements = {
    {type = COMBAT_PHYSICALDAMAGE, percent = 30},
    {type = COMBAT_DEATHDAMAGE, percent = 30},
    {type = COMBAT_ENERGYDAMAGE, percent = 50},
    {type = COMBAT_EARTHDAMAGE, percent = 40},
    {type = COMBAT_ICEDAMAGE, percent = -10},
    {type = COMBAT_HOLYDAMAGE, percent = -10}
}

monster.immunities = {
    {type = "fire", combat = true, condition = true},
    {type = "drown", condition = true},
    {type = "lifedrain", combat = true},
    {type = "paralyze", condition = true},
    {type = "invisible", condition = true}
}

mType.onThink = function(monster, interval)
    print("I'm thinking")
end

mType.onAppear = function(monster, creature)
    if monster:getId() == creature:getId() then
        print(monster:getId(), creature:getId())
    end
end

mType.onDisappear = function(monster, creature)
    if monster:getId() == creature:getId() then
        print(monster:getId(), creature:getId())
    end
end

mType.onMove = function(monster, creature, fromPosition, toPosition)
    if monster:getId() == creature:getId() then
        print(monster:getId(), creature:getId(), fromPosition, toPosition)
    end
end

mType.onSay = function(monster, creature, type, message)
    print(monster:getId(), creature:getId(), type, message)
end

mType:register(monster)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://stigmax.gitbook.io/tfs-guide/interface-monster/monster-revscripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
