• 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.2 Spell summons more than one

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
526
Reaction score
54
Hello it suppose to summon max only 1 monster but it summons unlimited number
Lua:
function onCastSpell(creature, var)

local player = Player(creature)

local summonName = "Priest Master"
local maxsummons = 1
local summonsPlayer = creature:getSummons()
local summon = true

if (#summonsPlayer >= 1) then
    for _, SummonID in ipairs(summonsPlayer) do
        if (string.lower(getCreatureName(SummonID)) == string.lower(summonName)) then
            nameSummon = getCreatureName(SummonID)
            summon = false
        end
    end
end

if (#summonsPlayer < maxsummons) and (summon == true) then
    for i = 1, maxsummons - #summonsPlayer do
    local mid = Game.createMonster(summonName, creature:getPosition())
        if not mid then
            return
        end
    end
    doCreatureSay(creature, "Go "..summonName.."!", TALKTYPE_ORANGE_1)
elseif (#summonsPlayer >= 1) and (nameSummon == summonName) then
    doPlayerSendCancel(creature, "You already have summoned "..summonName..".")
    summon = false
return doSendMagicEffect(getThingPos(player), 2) and false
end

return
end
and im monster.xml
Code:
<attack name="summon monster" interval="10000"/>
 
Your spell makes no sense, and you use 0.4 function liberally.. in tfs 1.0+

The compat folder is there as a crutch, so you can port over to tfs 1.0+.
After 6+ years, there's no reason why any of your scripts should continue to use the compat functions.

Lua:
local summonName = "Priest Master"
local maxSummons = 1

function onCastSpell(creature, var)

    local creatureSummons = creature:getSummons()
    local creaturePosition = creature:getPosition()
   
    if #creatureSummons >= maxSummons then
        if creature:isPlayer() then
            creature:sendCancelMessage("You are already at max summons.")
        end
        creaturePosition:sendMagicEffect(CONST_ME_LOSEENERGY)
        return false
    end
   
    local summon = Game.createMonster(summonName, creaturePosition)
   
    if not summon then
        if creature:isPlayer() then
            creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
        end
        creaturePosition:sendMagicEffect(CONST_ME_LOSEENERGY)
        return false
    end
   
    summon:setMaster(creature)
    summon:setDropLoot(false)
    creature:say("Go " .. summonName .. "!", TALKTYPE_MONSTER_SAY)   
    return true
end
 
Your spell makes no sense, and you use 0.4 function liberally.. in tfs 1.0+

The compat folder is there as a crutch, so you can port over to tfs 1.0+.
After 6+ years, there's no reason why any of your scripts should continue to use the compat functions.

Lua:
local summonName = "Priest Master"
local maxSummons = 1

function onCastSpell(creature, var)

    local creatureSummons = creature:getSummons()
    local creaturePosition = creature:getPosition()
   
    if #creatureSummons >= maxSummons then
        if creature:isPlayer() then
            creature:sendCancelMessage("You are already at max summons.")
        end
        creaturePosition:sendMagicEffect(CONST_ME_LOSEENERGY)
        return false
    end
   
    local summon = Game.createMonster(summonName, creaturePosition)
   
    if not summon then
        if creature:isPlayer() then
            creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
        end
        creaturePosition:sendMagicEffect(CONST_ME_LOSEENERGY)
        return false
    end
   
    creature:say("Go " .. summonName .. "!", TALKTYPE_MONSTER_SAY)   
    return true
end
Nop doesnt work. Code acts the same how it was before
 
hmm doesnt work for me idk why
Here's the same script again, with prints.
Show us what appears in console.
Lua:
local summonName = "Priest Master"
local maxSummons = 1

function onCastSpell(creature, var)
    
    local creatureSummons = creature:getSummons()
    local creaturePosition = creature:getPosition()
    
    print("# of summons = " .. #creatureSummons)
    print("Max summon allowed = " .. maxSummons)
    if #creatureSummons >= maxSummons then
        print("Creature is at max summons. Cancelling spell.")
        if creature:isPlayer() then
            creature:sendCancelMessage("You are already at max summons.")
        end
        creaturePosition:sendMagicEffect(CONST_ME_LOSEENERGY)
        return false
    end
    
    local summon = Game.createMonster(summonName, creaturePosition)
    
    if not summon then
        print("Unable to spawn summon. Cancelling spell.")
        if creature:isPlayer() then
            creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
        end
        creaturePosition:sendMagicEffect(CONST_ME_LOSEENERGY)
        return false
    end
    
    print("Summon successfully spawned.")
    summon:setMaster(creature)
    summon:setDropLoot(false)
    creature:say("Go " .. summonName .. "!", TALKTYPE_MONSTER_SAY)   
    return true
end
 
Back
Top