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

Why it ignores my max value (spell)

SixNine

Active Member
Joined
Dec 12, 2018
Messages
442
Reaction score
40
Hello so edited this code so that monsters could cast this spell but for some reason it ignores the maxsummons and it casts more then 1
Lua:
function onCastSpell(creature, var)

local player = Player(creature)

local summonName = "Rat LvL 10"
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
 
Last edited:
@SixNine

After you summon the monster, you don't assign it as a summon to its master. So when you check how many summons the master has, it will still be 0.

Add this line into your current for loop:
Lua:
    for i = 1, maxsummons - #summonsPlayer do
        local mid = Game.createMonster(summonName, creature:getPosition())
        if not mid then
            return
        end
        
        -- new line: assign mid to master (assuming u are using TFS 1.4)
        creature:addSummon(mid)
    end
 
@SixNine

After you summon the monster, you don't assign it as a summon to its master. So when you check how many summons the master has, it will still be 0.

Add this line into your current for loop:
Lua:
    for i = 1, maxsummons - #summonsPlayer do
        local mid = Game.createMonster(summonName, creature:getPosition())
        if not mid then
            return
        end
      
        -- new line: assign mid to master (assuming u are using TFS 1.4)
        creature:addSummon(mid)
    end
what if monster summons it and not the player?
Post automatically merged:
 
Last edited:
what if monster summons it and not the player?
Post automatically merged:

Add this check:
Lua:
function onCastSpell(creature, var)
    -- check to make sure creature isn't a summon already
    if creature:getMaster() then
        return false
    end
 
Back
Top