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

Monster transforms after some time

Count Dracula

New Member
Joined
Jul 30, 2013
Messages
36
Solutions
1
Reaction score
1
Hi guys. I'm trying to make the summons of one boss transforms themselves after sometime into stronger creatures if not killed fast.

I thought in doing a custom spell for the summons, like this:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_NONE)

function onCastSpell(creature, var)
    local spectators, spectator = Game.getSpectators(creature:getPosition(), false, false, 25, 25, 25, 25)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isMonster() and spectator:getName() == "master" then
            creature:remove()
            Game.createMonster("monster2", creature:getPosition())       
            return true
        end
    end
    return combat:execute(creature, var)
end

But I get this error on console:

Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/monster/monster.lua:onCastSpell
attempt to index a nil value
stack traceback:
    [C]: in ?
    [C]: in function 'createMonster'
    data/spells/scripts/monster/monster.lua:10: in function <data/spells/scripts/monster/monster.lua:4>

How can I make this work?

Tfs version 1.2
 
Hi guys. I'm trying to make the summons of one boss transforms themselves after sometime into stronger creatures if not killed fast.

I thought in doing a custom spell for the summons, like this:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_NONE)

function onCastSpell(creature, var)
    local spectators, spectator = Game.getSpectators(creature:getPosition(), false, false, 25, 25, 25, 25)
    for i = 1, #spectators do
        spectator = spectators[i]
        if spectator:isMonster() and spectator:getName() == "master" then
            creature:remove()
            Game.createMonster("monster2", creature:getPosition())     
            return true
        end
    end
    return combat:execute(creature, var)
end

But I get this error on console:

Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/monster/monster.lua:onCastSpell
attempt to index a nil value
stack traceback:
    [C]: in ?
    [C]: in function 'createMonster'
    data/spells/scripts/monster/monster.lua:10: in function <data/spells/scripts/monster/monster.lua:4>

How can I make this work?

Tfs version 1.2
You should modify the summon monster add an onCreatureAppear event and check if it is a summon and it's master is that other monster. If yes then use an addEvent to transform it to another creature (basically removing the summon and adding a new one in the same position with the same HP if you want it.)
 
Look at what you are doing in your script. First you remove the creature then use reference to it to get its position. try:
Lua:
if spectator:isMonster() and spectator:getName() == "master" then
            local creaturePos = creature:getPosition()
            creature:remove()
            Game.createMonster("monster2", creaturePos)    
            return true
        end
 
Look at what you are doing in your script. First you remove the creature then use reference to it to get its position. try:
Lua:
if spectator:isMonster() and spectator:getName() == "master" then
            local creaturePos = creature:getPosition()
            creature:remove()
            Game.createMonster("monster2", creaturePos) 
            return true
        end
I forgot I need to make the new creatures also summons of the "master"...


You should modify the summon monster add an onCreatureAppear event and check if it is a summon and it's master is that other monster. If yes then use an addEvent to transform it to another creature (basically removing the summon and adding a new one in the same position with the same HP if you want it.)
I tried to do as you said and created the spell for the monster "master":

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_NONE)

local area = createCombatArea(AREA_CIRCLE2X2)
combat:setArea(area)

local maxsummons = 2

function onCastSpell(creature, var)
    local summoncount = creature:getSummons()
    if #summoncount < 2 then
        for i = 1, maxsummons - #summoncount do
            local mid = Game.createMonster("Summon1", creature:getPosition())
                if not mid then
                    return
                end
            mid:setMaster(creature)
            addEvent(function(cid)
            mid:remove()
            local mid2 = Game.createMonster("Summon2", creature:getPosition())
                if not mid2 then
                    return
                end
            mid2:setMaster(creature)
            return true
        end, 6 * 1000, creature:getId())
        end
    end
    return combat:execute(creature, var)
end

But it doesn't work very well, because when the first summons are removed and transformed into the summon2, the monster "master" keeps creating the "summon1".

--EDIT--

How stupid of me, it was creating more summons then the expected because I had left the spell event in the summon monster.xml lol

It works now, but when I tried to kill the both summons then this error happened:

Code:
Segmentation fault (core dumped)

And the server crashed. What is it?
 
Last edited:
I forgot I need to make the new creatures also summons of the "master"...



I tried to do as you said and created the spell for the monster "master":

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_NONE)

local area = createCombatArea(AREA_CIRCLE2X2)
combat:setArea(area)

local maxsummons = 2

function onCastSpell(creature, var)
    local summoncount = creature:getSummons()
    if #summoncount < 2 then
        for i = 1, maxsummons - #summoncount do
            local mid = Game.createMonster("Summon1", creature:getPosition())
                if not mid then
                    return
                end
            mid:setMaster(creature)
            addEvent(function(cid)
            mid:remove()
            local mid2 = Game.createMonster("Summon2", creature:getPosition())
                if not mid2 then
                    return
                end
            mid2:setMaster(creature)
            return true
        end, 6 * 1000, creature:getId())
        end
    end
    return combat:execute(creature, var)
end

But it doesn't work very well, because when the first summons are removed and transformed into the summon2, the monster "master" keeps creating the "summon1".

--EDIT--

How stupid of me, it was creating more summons then the expected because I had left the spell event in the summon monster.xml lol

It works now, but when I tried to kill the both summons then this error happened:

Code:
Segmentation fault (core dumped)

And the server crashed. What is it?


You are not realy doing like I said, you shouldn't need any aditional spell for this. Only the "onCreatureAppear" in the summon should do it, as you want the summon to transform after some time not at random time when some spell is casted.

Never use userdata in functions for addEvent, they are not safe get the creatureId and then Creature(creatureId).
 
You are not realy doing like I said, you shouldn't need any aditional spell for this. Only the "onCreatureAppear" in the summon should do it, as you want the summon to transform after some time not at random time when some spell is casted.

Never use userdata in functions for addEvent, they are not safe get the creatureId and then Creature(creatureId).

Sorry, but I don't know how to use onCreatureAppear... Could you give me an example?
 
Back
Top Bottom