• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Where to put <script> in monster.lua?

walltimer

Active Member
Joined
Aug 5, 2020
Messages
170
Reaction score
26
Iv gort this revscript from Xikini, unfornatly i have otservb, which is using onlnny revscripts, no XML Monster.

Put this into any monster you want the script to activate for.
XML:
<script>
<event name="onDeath_open_passageway" />
</script>


data\scripts\ onDeath_open_passageway.lua
Lua:
local config = {
positionCheck = {north_west = Position(99, 99, 7), south_east = Position(101, 101, 7)},
item = {Position(103, 100, 7), 1285}, -- {item_position, itemid}
timer = 20, -- timer is how long until the 'stone' aka: item, is replaced.
discoveryText = "A passageway has opened nearby!\nQuickly, get inside!"
}

local toggle = 0
local function changePassageway()
local item = Tile(config.item[1]):getItemById(config.item[2])
if item then
item:remove()
return true
end
config.item[1]:sendMagicEffect(CONST_ME_BIGPLANTS)
Game.createItem(config.item[2], 1, config.item[1])
toggle = 0
end

local creatureevent = CreatureEvent("onDeath_open_passageway")

function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
if toggle == 1 then
return true
end
local deathPosition = creature:getPosition()
if not deathPosition:isInRange(config.positionCheck.north_west, config.positionCheck.south_east) then
return true
end
toggle = 1
config.item[1]:sendMagicEffect(CONST_ME_POFF)
changePassageway()
addEvent(changePassageway, config.timer * 1000)
creature:say(config.discoveryText, TALKTYPE_MONSTER_SAY, false, nil, deathPosition)
return true
end

creatureevent:register()
 
Try adding this before creature:register()
Lua:
monsterType:registerEvent("onDeath_open_passageway")

I suppose it wont work. monsterType is undefined.

Try this:
Code:
MonsterType("Demon"):registerEvent("onDeath_open_passageway")
 
Last edited:
I suppose it wont work. monsterType is undefined.

Code:
MonsterType("Demon"):registerEvent("onDeath_open_passageway")

Undefined? 🤔
Skärmavbild 2021-03-31 kl. 15.32.09.png

MonsterType:

Monster:

Lua:
function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    print(creature:getName() .. " died. big OOF!")
    return true
end

Lua:
local mType = Game.createMonsterType("demon")
local monster = {}
monster.description = "a demorflap"
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 = 1987, chance = 60000, -- bag
        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:registerEvent("testEvent") -- here
mType:register(monster)
 
Undefined? 🤔
View attachment 57146

MonsterType:

Monster:

Lua:
function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    print(creature:getName() .. " died. big OOF!")
    return true
end

Lua:
local mType = Game.createMonsterType("demon")
local monster = {}
monster.description = "a demorflap"
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 = 1987, chance = 60000, -- bag
        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:registerEvent("testEvent") -- here
mType:register(monster)

Yes, but first you need an object to call it on.

In this script, there is no monsterType variable ever registered.

If you meant in monster script, then yes, this variable should be there, but you said in this script :p.

#edit

oh, now i get. thought you meant before creatureevent:register() not creature:register()
 
Back
Top