• 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!

TFS 1.X+ [otservBR] - how tf u register stuff in monster?

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
176
Location
Sweden
As topic goes, using otservbr, how do i register for example creaturescripts in monster files?

Here's a monster file: (without any errors, still it won't execute the called event/script)
Lua:
local mType = Game.createMonsterType("Zombie_Event")
local monster = {}

monster.description = "a zombie"
monster.experience = 0
monster.outfit = {
    lookType = 311,
    lookHead = 0,
    lookBody = 0,
    lookLegs = 0,
    lookFeet = 0,
    lookAddons = 0,
    lookMount = 0
}

monster.raceId = 512
monster.Bestiary = {
    class = "Undead",
    race = BESTY_RACE_UNDEAD,
    toKill = 1000,
    FirstUnlock = 50,
    SecondUnlock = 500,
    CharmsPoints = 25,
    Stars = 3,
    Occurrence = 0,
    Locations = "Zombie event."
    }

monster.health = 15000
monster.maxHealth = 15000
monster.race = "undead"
monster.corpse = 9875
monster.speed = 160
monster.manaCost = 0
monster.maxSummons = 0

monster.changeTarget = {
    interval = 4000,
    chance = 10
}

monster.strategiesTarget = {
    nearest = 80,
    health = 10,
    damage = 10,
}

monster.flags = {
    summonable = false,
    attackable = true,
    hostile = true,
    convinceable = false,
    pushable = false,
    rewardBoss = false,
    illusionable = false,
    canPushItems = true,
    canPushCreatures = true,
    staticAttackChance = 90,
    targetDistance = 1,
    runHealth = 0,
    healthHidden = false,
    isBlockable = false,
    canWalkOnEnergy = true,
    canWalkOnFire = false,
    canWalkOnPoison = true,
    pet = false
}

monster.light = {
    level = 0,
    color = 0
}

monster.voices = {
    interval = 5000,
    chance = 10,
    {text = "Mst.... klll....", yell = false},
    {text = "Whrrrr... ssss.... mmm.... grrrrl", yell = false},
    {text = "Dnnnt... cmmm... clsrrr....", yell = false},
    {text = "Httt.... hmnnsss...", yell = false}
}


monster.defenses = {
    defense = 15,
    armor = 15
}

monster.attacks = {
    {name ="melee", interval = 500, chance = 100, minDamage = -100000, maxDamage = -100000},
}

monster.immunities = {
    {type = "paralyze", condition = true},
    {type = "outfit", condition = false},
    {type = "invisible", condition = false},
    {type = "bleed", condition = false}
}
mType:register("ZombieOnDeath")
mType:register(monster)

Here's the creaturescript:
Lua:
local ZombieOnDeath = CreatureEvent("ZombieOnDeath")
function ZombieOnDeath.onDeath(monster, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    -- Send text and effect
    monster:say("I WILL BE BACK!", TALKTYPE_MONSTER_YELL)
    monster:getPosition():sendMagicEffect(CONST_ME_MORTAREA)

    -- Remove zombie count, when it dies
    Game.setStorageValue(ze_zombieCountGlobalStorage, getZombieEventZombieCount() - 1)

    -- Store player kills
    local killerId = killer:getId()
    if zombieKillCount[killerId] ~= nil then
        zombieKillCount[killerId] = zombieKillCount[killerId] + 1
    else
        zombieKillCount[killerId] = 1
    end

    return true
end


local ZombieOnPrepareDeath = CreatureEvent("ZombieOnPrepareDeath")
function ZombieOnPrepareDeath.onPrepareDeath(player, killer)
    -- Remove player from count
    local count = ze_joinCountGlobalStorage()
    Game.setStorageValue(ze_joinCountGlobalStorage, count - 1)

    -- Reset player after death
    player:teleportTo(player:getTown():getTemplePosition())
    player:addHealth(player:getMaxHealth())
    player:addMana(player:getMaxMana())
    player:unregisterEvent("ZombieOnPrepareDeath")

    -- Let's reward the 1 last player
    if count <= 1 then
        local playerName =  player:getName()

        local item = player:addItem(24850, 15)

        -- Store kill count and remove from table to avoid memory leak
        local playerId, killCount = player:getId(), 0
        if zombieKillCount[playerId] ~= nil then
            killCount = zombieKillCount[playerId]
            zombieKillCount[playerId] = nil
        end

        -- Broadcast
        Game.broadcastMessage(string.format("Place number %d goes to %s of Zombie Event versus %d Zombies slaining %d Zombies.", count, playerName, getZombieEventZombieCount(), killCount))

        -- The last player died, let's reset the event
        if count <= 1 then
            resetZombieEvent()
        end
    end

    return false
end
 
The Revscripts go in the folder data/scripts/
btw, WTF: mType:register("ZombieOnDeath") ?

[Edit] is: mType:registerEvent("ZombieOnDeath")
 
Last edited:
The Revscripts go in the folder data/scripts/
btw, WTF: mType:register("ZombieOnDeath") ?

is: monsterType:registerEvent(name)
Sorry I did some poor explaining. My creaturescript is in data/scripts, the issue I got is to register that creaturescript into the monster file. In normal tfs you use:
XML:
    <script>
        <event name="ZombieOnDeath"/>
    </script>

Using monsterType, throws this error:
Code:
...kg\otservbr-global\data\monster\undeads\zombie_event.lua:99: attempt to index global 'monsterType' (a nil value)
 
Sorry I did some poor explaining. My creaturescript is in data/scripts, the issue I got is to register that creaturescript into the monster file. In normal tfs you use:
XML:
    <script>
        <event name="ZombieOnDeath"/>
    </script>

Using monsterType, throws this error:
Code:
...kg\otservbr-global\data\monster\undeads\zombie_event.lua:99: attempt to index global 'monsterType' (a nil value)
please recheck my answer, I have edited it. I showed you an example but you did not know how to add it, you only did copy and paste
 
please recheck my answer, I have edited it. I showed you an example but you did not know how to add it, you only did copy and paste
I have so many questions. What was the example?, What did i not know how to add? What did i copy and paste?
The Revscripts go in the folder data/scripts/
^This i already knew. I linked this script to give so much details I could.
btw, WTF: mType:register("ZombieOnDeath") ?
^And this was the question I had, since I didn't knew. Where your first & second solution wasn't fixing.
mType:registerEvent("ZombieOnDeath")
^Aka this is not correct, kimokimo has already given the correct answer.

It did, but your script is not registered correctly

You're missing this at the end of each script.
Lua:
ZombieOnDeath:register()
Yeah, I added that, thats why it works (including your register) but it still sends error msg everytime i spawn one of the mobs, which is odd.
 
Back
Top