• 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.5 one dies, another is born xD

Shoorkill

Member
Joined
Dec 17, 2018
Messages
126
Reaction score
21
well.. I need a script that does the following, when killing monster x it is reborn as monster y eg: a rat dies and at the same moment a rotworm is born on top of it... it seems simple, but I don't understand how to do it xd
 
well.. I need a script that does the following, when killing monster x it is reborn as monster y eg: a rat dies and at the same moment a rotworm is born on top of it... it seems simple, but I don't understand how to do it xd
You can try:
data/scripts/file.lua
Lua:
local config = {
    ["rat"] = {name = "Rotworm", count = 1, chance = 100},
    ["cave rat"] = {name = "Rotworm Queen", count = 1, chance = 100}
}

local born = CreatureEvent("BornExample")

function born.onDeath(monster)
    local bornConfig = config[monster:getName():lower()]
    if not bornConfig then return true end
    if bornConfig.count and bornConfig.count <= 0 then return true end
    local chance = bornConfig.chance or 100
    if math.random(100) > chance then return true end

    local pos = monster:getPosition()
    for i = 1, bornConfig.count do
        Game.createMonster(bornConfig.name, pos, true)
    end
    return true
end

born:register()

local event = EventCallback

function event.onSpawn(monster, position, startup, artificial)
    if config[monster:getName():lower()] then
        monster:registerEvent("BornExample")
    end
    return true
end

event:register()
No tested.
Remember set enable the following events: onSpawn in events.xml
 
Last edited:
example:

don't forget to add
XML:
    <script>
        <event name="ScarabDeath" />
    </script>

to xml monster file
it Works very well
Post automatically merged:

it didn't work, I already enabled OnSpawn, I would really like this rev ;d
You can try:
data/scripts/file.lua
Lua:
local config = {
    ["rat"] = {name = "Rotworm", count = 1, chance = 100},
    ["cave rat"] = {name = "Rotworm Queen", count = 1, chance = 100}
}

local born = CreatureEvent("BornExample")

function born.onDeath(monster)
    local bornConfig = config[monster:getName():lower()]
    if not bornConfig then return true end
    if bornConfig.count and bornConfig.count <= 0 then return true end
    local chance = bornConfig.chance or 100
    if math.random(100) > chance then return true end

    local pos = monster:getPosition()
    for i = 1, bornConfig.count do
        Game.createMonster(bornName, pos, true)
    end
    return true
end

born:register()

local event = EventCallback

function event.onSpawn(monster, position, startup, artificial)
    if config[monster:getName():lower()] then
        monster:registerEvent("BornExample")
    end
    return true
end

event:register()
No tested.
Remember set enable the following events: onSpawn in events.xml
it didn't work, I already enabled OnSpawn, I would really like this rev ;d
 
it Works very well
Post automatically merged:

it didn't work, I already enabled OnSpawn, I would really like this rev ;d

it didn't work, I already enabled OnSpawn, I would really like this rev ;d
change
Lua:
Game.createMonster(bornName, pos, true)
to:
Lua:
Game.createMonster(bornConfig.name, pos, true)
or declare bornName as bornConfig.name before the for loop, which is cleaner and more logical
 
it Works very well
Post automatically merged:

it didn't work, I already enabled OnSpawn, I would really like this rev ;d

it didn't work, I already enabled OnSpawn, I would really like this rev ;d
change
Lua:
Game.createMonster(bornName, pos, true)
to:
Lua:
Game.createMonster(bornConfig.name, pos, true)
or declare bornName as bornConfig.name before the for loop, which is cleaner and more logical
ready, and thanks @Boy67
 
Back
Top