• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

TFS 1.2 Spell summons more than one

Tbol

Active Member
Joined
Apr 7, 2019
Messages
460
Reaction score
47
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"/>
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,245
Solutions
545
Reaction score
4,487
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
 
OP
OP
Tbol

Tbol

Active Member
Joined
Apr 7, 2019
Messages
460
Reaction score
47
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
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,245
Solutions
545
Reaction score
4,487
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
 
Top