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

[help] addEvent to remove Summons

enemyy

Member
Joined
Aug 11, 2017
Messages
28
Reaction score
5
hello my friends,

i'm working in a summon action script
and I want to remove the summon after x time, and put exhaustion (y time) on this script .. i have tryed make this with "addEvent" but i dont know how to make it correctly...

TFS 1.3, 10.98 version
i'm using this script as a base:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)


    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local position = player:getPosition()
    local monster = Game.createMonster("Barbarian Bloodwalker", position)
    if monster then
        player:addSummon(monster)
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        monster:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
        addEvent(doRemoveCreature, 3000, monster) -- <-- i've put it to remove the summon after 3 seconds(but error, cause unsafe)

    else
        player:sendCancelMessage("There is not enough room.")
        position:sendMagicEffect(CONST_ME_POFF)
    end
    return false
end

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/summonsign.lua:onUse
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/actions/scripts/other/summonsign.lua:19: in function <data/actions/scripts/other/summonsign.lua:2>

could you help me?
 
Last edited:
Solution
You need to get the monster through its creature id again so you can know that it exists before you do anything with it.
Lua:
local function removeMonster(cid)
    local monster = Monster(cid)
    if monster then
        monster:remove()
    end
end

Then replace your current addEvent with addEvent(removeMonster, 3000, monster:getId())
Don't need to make another function, doRemoveCreature already check if monster exist, if not then return false.

Code:
function doRemoveCreature(cid) local c = Creature(cid) return c and c:remove() or false end
You need to get the monster through its creature id again so you can know that it exists before you do anything with it.
Lua:
local function removeMonster(cid)
    local monster = Monster(cid)
    if monster then
        monster:remove()
    end
end

Then replace your current addEvent with addEvent(removeMonster, 3000, monster:getId())
 
hello my friends,

i'm working in a summon action script
and I want to remove the summon after x time, and put exhaustion (y time) on this script .. i have tryed make this with "addEvent" but i dont know how to make it correctly...

TFS 1.3, 10.98 version
i'm using this script as a base:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)


    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local position = player:getPosition()
    local monster = Game.createMonster("Barbarian Bloodwalker", position)
    if monster then
        player:addSummon(monster)
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        monster:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
        addEvent(doRemoveCreature, 3000, monster) -- <-- i've put it to remove the summon after 3 seconds(but error, cause unsafe)

    else
        player:sendCancelMessage("There is not enough room.")
        position:sendMagicEffect(CONST_ME_POFF)
    end
    return false
end

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/summonsign.lua:onUse
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/actions/scripts/other/summonsign.lua:19: in function <data/actions/scripts/other/summonsign.lua:2>

could you help me?

It's because tfs 1.3 have warnings about unsafe scripts parameters, i.e if you will pass not exist monster [removed or killed before event execute] there can be a problem. You can disable warnings in config.lua or protect your scripts.
To avoid this warning you can pass monster as id like this:

Code:
addEvent(doRemoveCreature, 3000, monster:getId())
 
You need to get the monster through its creature id again so you can know that it exists before you do anything with it.
Lua:
local function removeMonster(cid)
    local monster = Monster(cid)
    if monster then
        monster:remove()
    end
end

Then replace your current addEvent with addEvent(removeMonster, 3000, monster:getId())
Don't need to make another function, doRemoveCreature already check if monster exist, if not then return false.

Code:
function doRemoveCreature(cid) local c = Creature(cid) return c and c:remove() or false end
 
Solution
works perfectly!

I plan to take advantage of this new function to add some exhaust to this summon system
 
Last edited:
Back
Top