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

Lua Summon last for 30 seconds TFS 1.3 (summon by action)

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hello guys,

I would like to edit this action so that the skeleton last for 30 seconds.

Lua:
function onUse(creature, item, variant)
doRemoveItem(item.uid, 1)
    if creature:getSkull() == SKULL_BLACK then
        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    local monsterName = "Skeleton"
    local monsterType = MonsterType(monsterName)

    if not monsterType then
        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    if not creature:hasFlag(PlayerFlag_CanSummonAll) then
        if not monsterType:isSummonable() then
            creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end

        if #creature:getSummons() >= 8 then
            creature:sendCancelMessage("You cannot summon more creatures.")
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    local manaCost = monsterType:getManaCost()
    if creature:getMana() < manaCost and not creature:hasFlag(PlayerFlag_HasInfiniteMana) then
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local position = creature:getPosition()
    local summon = Game.createMonster("Skeleton", position, true)
    if not summon then
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
        position:sendMagicEffect(CONST_ME_POFF)
        return false
    end

    creature:addMana(-manaCost)
    creature:addManaSpent(manaCost)
    creature:addSummon(summon)
    position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    summon:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
 
Solution
try this

addEvent(function() summon:remove(1) end, 30000)

Lua:
function onUse(creature, item, variant)

doRemoveItem(item.uid, 1)

    if creature:getSkull() == SKULL_BLACK then

        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    local monsterName = "Skeleton"
    local monsterType = MonsterType(monsterName)

    if not monsterType then
        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    if not creature:hasFlag(PlayerFlag_CanSummonAll) then
        if not monsterType:isSummonable() then
            creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)...
try this

addEvent(function() summon:remove(1) end, 30000)

Lua:
function onUse(creature, item, variant)

doRemoveItem(item.uid, 1)

    if creature:getSkull() == SKULL_BLACK then

        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    local monsterName = "Skeleton"
    local monsterType = MonsterType(monsterName)

    if not monsterType then
        creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    if not creature:hasFlag(PlayerFlag_CanSummonAll) then
        if not monsterType:isSummonable() then
            creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end

        if #creature:getSummons() >= 8 then
            creature:sendCancelMessage("You cannot summon more creatures.")
            creature:getPosition():sendMagicEffect(CONST_ME_POFF)
            return false
        end
    end

    local manaCost = monsterType:getManaCost()
    if creature:getMana() < manaCost and not creature:hasFlag(PlayerFlag_HasInfiniteMana) then
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHMANA)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local position = creature:getPosition()
    local summon = Game.createMonster("Skeleton", position, true)
    
    if summon then
        addEvent(function() summon:remove(1) end, 30000)
    end

    if not summon then
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
        position:sendMagicEffect(CONST_ME_POFF)
        return false
    end
    creature:addMana(-manaCost)
    creature:addManaSpent(manaCost)
    creature:addSummon(summon)
    position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    summon:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
 
Last edited:
Solution
addEvent(function() summon:remove(1) end, 30000)
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/bonesummon.lua:2: attempt to index global 'summon' (a nil value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/bonesummon.lua:2: in function <data/actions/scripts/bonesummon.lua:2>
New error
 
I think you should check if summon still exists inside the addEvent, otherwise you'll be using creature:remove in a non-existant creature (maybe crash server? Null pointer)
 
Back
Top