• 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+ How to declare an summons counter for my spells?

Travisani

New Member
Joined
Jul 19, 2023
Messages
4
Reaction score
1
I tryied to do a script for make a random summon.
But i got this error:

[error] Lua script error:
error... boss_summon.lua:14: attempt to compare nil with number stack traceback:
[C]: in function '__lt'
...boss_summon.lua:14: in function boss_summon.lua:10

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

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

local spell = Spell("instant")
function spell.onCastSpell(creature, var)
    local creatures = { "Rat", "Sibang", "Tarantula" }
    local monster = creatures[math.random(#creatures)]

    if minorsummon < 5 then
        Game.createMonster(monster, { x = creature:getPosition().x + math.random(-1, 1), y = creature:getPosition().y + math.random(-1, 1), z = creature:getPosition().z }, false, true)
        minorsummon = minorsummon + 1
    end
    return combat:execute(creature, var)
end

spell:name("minorsummon")
spell:words("###1246")
spell:blockWalls(true)
spell:needLearn(true)
spell:register()

Someone know how to declare this variable?
 
Solution
This should work fine:

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

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

local creatures = {"Rat", "Sibang", "Tarantula"}
local maxSummons = 5

local spell = Spell("instant")

function spell.onCastSpell(creature, var)
    local monster = creatures[math.random(#creatures)]
    local mySummons = creature:getSummons()
    if #mySummons >= maxSummons then return false end
    local summon = Game.createMonster(monster, {
        x = creature:getPosition().x + math.random(-1, 1),
        y = creature:getPosition().y + math.random(-1, 1),
        z = creature:getPosition().z
    }, false...
Lua:
    if minorsummon < 5 then
        Game.createMonster(monster, { x = creature:getPosition().x + math.random(-1, 1), y = creature:getPosition().y + math.random(-1, 1), z = creature:getPosition().z }, false, true)
        minorsummon = minorsummon + 1
    end

'minorsummon' doesnt exists.. what's supposed to be?
 
TRY..
Lua:
local minorsummon = 0

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_NONE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_NONE)

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

local spell = Spell("instant")
function spell.onCastSpell(creature, var)
    local creatures = { "Rat", "Sibang", "Tarantula" }
    local monster = creatures[math.random(#creatures)]

    if minorsummon < 5 then
        Game.createMonster(monster, { x = creature:getPosition().x + math.random(-1, 1), y = creature:getPosition().y + math.random(-1, 1), z = creature:getPosition().z }, false, true)
        minorsummon = minorsummon + 1
    end
    return combat:execute(creature, var)
end

spell:name("minorsummon")
spell:words("###1246")
spell:blockWalls(true)
spell:needLearn(true)
spell:register()
 
TRY..
Lua:
local minorsummon = 0

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_NONE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_NONE)

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

local spell = Spell("instant")
function spell.onCastSpell(creature, var)
    local creatures = { "Rat", "Sibang", "Tarantula" }
    local monster = creatures[math.random(#creatures)]

    if minorsummon < 5 then
        Game.createMonster(monster, { x = creature:getPosition().x + math.random(-1, 1), y = creature:getPosition().y + math.random(-1, 1), z = creature:getPosition().z }, false, true)
        minorsummon = minorsummon + 1
    end
    return combat:execute(creature, var)
end

spell:name("minorsummon")
spell:words("###1246")
spell:blockWalls(true)
spell:needLearn(true)
spell:register()

It will work but problem is if one monster die the script still think its 5 summons and in that case it won't work anymore
Maybe he want it like that, no clue
 
This should work fine:

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

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

local creatures = {"Rat", "Sibang", "Tarantula"}
local maxSummons = 5

local spell = Spell("instant")

function spell.onCastSpell(creature, var)
    local monster = creatures[math.random(#creatures)]
    local mySummons = creature:getSummons()
    if #mySummons >= maxSummons then return false end
    local summon = Game.createMonster(monster, {
        x = creature:getPosition().x + math.random(-1, 1),
        y = creature:getPosition().y + math.random(-1, 1),
        z = creature:getPosition().z
    }, false, true)
    if not summon then return false end
    creature:addSummon(summon)
    return combat:execute(creature, var)
end

spell:name("minorsummon")
spell:words("###1246")
spell:blockWalls(true)
spell:needLearn(true)
spell:register()
 
Solution
This should work fine:

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

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

local creatures = {"Rat", "Sibang", "Tarantula"}
local maxSummons = 5

local spell = Spell("instant")

function spell.onCastSpell(creature, var)
    local monster = creatures[math.random(#creatures)]
    local mySummons = creature:getSummons()
    if #mySummons >= maxSummons then return false end
    local summon = Game.createMonster(monster, {
        x = creature:getPosition().x + math.random(-1, 1),
        y = creature:getPosition().y + math.random(-1, 1),
        z = creature:getPosition().z
    }, false, true)
    if not summon then return false end
    creature:addSummon(summon)
    return combat:execute(creature, var)
end

spell:name("minorsummon")
spell:words("###1246")
spell:blockWalls(true)
spell:needLearn(true)
spell:register()
It's perfect, tested and works well, wow..
 
This should work fine:

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

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

local creatures = {"Rat", "Sibang", "Tarantula"}
local maxSummons = 5

local spell = Spell("instant")

function spell.onCastSpell(creature, var)
    local monster = creatures[math.random(#creatures)]
    local mySummons = creature:getSummons()
    if #mySummons >= maxSummons then return false end
    local summon = Game.createMonster(monster, {
        x = creature:getPosition().x + math.random(-1, 1),
        y = creature:getPosition().y + math.random(-1, 1),
        z = creature:getPosition().z
    }, false, true)
    if not summon then return false end
    creature:addSummon(summon)
    return combat:execute(creature, var)
end

spell:name("minorsummon")
spell:words("###1246")
spell:blockWalls(true)
spell:needLearn(true)
spell:register()
i've adapted this in my src and works fine! Thank you!
 
Back
Top