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

AddEvent issue

Zazeros

Member
Joined
Feb 13, 2012
Messages
64
Reaction score
17
0.4

Hello everyone, I'm doing some custom spells for my monsters, and one particular spell is: It begins to 'charge' and then hit the player (one target), but, if the player disappears (logout or die), it will return this error:
[2/4/2022 13:41:48] [Error - Spell Interface]
[2/4/2022 13:41:48] In a timer event called from:
[2/4/2022 13:41:48] data/spells/scripts/monsters/throw rock.lua: onCastSpell
[2/4/2022 13:41:48] Description:
[2/4/2022 13:41:48] (luaGetThingPosition) Thing not found

[2/4/2022 13:41:49] [Error - Spell Interface]
[2/4/2022 13:41:49] In a timer event called from:
[2/4/2022 13:41:49] data/spells/scripts/monsters/throw rock.lua: onCastSpell
[2/4/2022 13:41:49] Description:
[2/4/2022 13:41:49] attempt to index a function value
[2/4/2022 13:41:49] stack traceback:
[2/4/2022 13:41:49] [C]: in function 'doSendDistanceShoot'
[2/4/2022 13:41:49] data/spells/scripts/monsters/throw rock.lua:28: in function <data/spells/scripts/monsters/throw rock.lua:23>

It is this part (inside onCastSpell):

C++:
addEvent(function()
               if isCreature(cid) then
               if getCreatureTarget(cid) == isMonster or isCreature then
               doSendDistanceShoot(getThingPos, getCreaturePosition(target), 11)  
 return doTargetCombatHealth(cid, getCreatureTarget(cid), COMBAT_PHYSICALDAMAGE, -75, -95, 9)
                end
                end
          end, 2000)
end

As you can see, I tried to use a "check", to see if the player exist, but no luck
 
Solution
@Xikini View attachment 66686
Post automatically merged:

Only in BLUE returned error
Ah I see. I wasn't even looking at the other function.

Just need to add a check for cid..
Lua:
local function spellCast(cid, target, wave)
    print("spellCast..")
    if wave == 1 then
        print("wave 1")
        if isCreature(cid) then
            print("cid exists.. continuing to wave 2..")
            doSendAnimatedText(getCreaturePos(cid), "1", 215)
            addEvent(spellCast, 1000, cid, target, wave + 1)
        end
    end
    if wave == 2 then
        print("wave 2")
        if isCreature(cid) and isCreature(target) then
            print("cid and target both exist.")
            doSendDistanceShoot(getCreaturePos(cid), getCreaturePos(target)...
0.4

Hello everyone, I'm doing some custom spells for my monsters, and one particular spell is: It begins to 'charge' and then hit the player (one target), but, if the player disappears (logout or die), it will return this error:


It is this part (inside onCastSpell):

C++:
addEvent(function()
               if isCreature(cid) then
               if getCreatureTarget(cid) == isMonster or isCreature then
               doSendDistanceShoot(getThingPos, getCreaturePosition(target), 11) 
 return doTargetCombatHealth(cid, getCreatureTarget(cid), COMBAT_PHYSICALDAMAGE, -75, -95, 9)
                end
                end
          end, 2000)
end

As you can see, I tried to use a "check", to see if the player exist, but no luck
You're using an anonymous function, but forgot to input cid as a parameter

change
Lua:
addEvent(function()
to
Lua:
addEvent(function(cid)
 
@Xikini Lol, that simple. Completely forgot about cid
Thank you.
Post automatically merged:

Actually, @Xikini I was testing only removing the target when the spell was casting, but now, letting the spell be completed, it does not send any shoot effect to the target and does not hit it's health. What can it be?
 
Last edited:
@Xikini Lol, that simple. Completely forgot about cid
Thank you.
Post automatically merged:

Actually, @Xikini I was testing only removing the target when the spell was casting, but now, letting the spell be completed, it does not send any shoot effect to the target and does not hit it's health. What can it be?
Post the entire script.

I see a lot of functions that aren't completed.. but idk if that's a copy-paste error, or something else.. so need to see the full script
 
@Xikini

C++:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)


function onCastSpell(cid, var)
doCombat(cid, combat, var)
doSendAnimatedText(getCreaturePos(cid), "2", 215)

 addEvent(function()
if isCreature(cid) then
doSendAnimatedText(getCreaturePos(cid), "1", 215)
end
 end, 1000)
 
addEvent(function()
               if isCreature(cid) then
               if getCreatureTarget(cid) == isMonster or isCreature then
               local tar = getCreatureTarget(cid)
               doSendDistanceShoot(getThingPos(cid), getCreaturePosition(tar), 11) 
 return doTargetCombatHealth(cid, getCreatureTarget(cid), COMBAT_PHYSICALDAMAGE, -75, -95, 9)
                end
                end
          end, 2000)
end
 
@Xikini

C++:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)


function onCastSpell(cid, var)
doCombat(cid, combat, var)
doSendAnimatedText(getCreaturePos(cid), "2", 215)

 addEvent(function()
if isCreature(cid) then
doSendAnimatedText(getCreaturePos(cid), "1", 215)
end
 end, 1000)
 
addEvent(function()
               if isCreature(cid) then
               if getCreatureTarget(cid) == isMonster or isCreature then
               local tar = getCreatureTarget(cid)
               doSendDistanceShoot(getThingPos(cid), getCreaturePosition(tar), 11)
 return doTargetCombatHealth(cid, getCreatureTarget(cid), COMBAT_PHYSICALDAMAGE, -75, -95, 9)
                end
                end
          end, 2000)
end
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onCastSpell(cid, var)
    doCombat(cid, combat, var)
    doSendAnimatedText(getCreaturePos(cid), "2", 215)
   
    addEvent(function(cid)
        if isCreature(cid) then
            doSendAnimatedText(getCreaturePos(cid), "1", 215)
        end
    end, 1000)
   
    addEvent(function(cid)
        if isCreature(cid) then
            local tar = getCreatureTarget(cid)
            if isCreature(tar) then
                doSendDistanceShoot(getThingPos(cid), getCreaturePosition(tar), 11)
                doTargetCombatHealth(cid, tar, COMBAT_PHYSICALDAMAGE, -75, -95, 9)
            end
        end
    end, 2000)
    return true
end
 
@Xikini Didn't work. Only send "2", and then nothing more. I don't think the (cid) is doing something positive
Try this.. and check console.

Lua:
local function spellCast(cid, target, wave)
    print("spellCast..")
    if wave == 1 then
        print("wave 1")
        doSendAnimatedText(getCreaturePos(cid), "1", 215)
        addEvent(spellCast, 1000, cid, target, wave + 1)
    end
    if wave == 2 then
        print("wave 2")
        if isCreature(cid) and isCreature(target) then
            print("cid and target both exist.")
            doSendDistanceShoot(getCreaturePos(cid), getCreaturePos(target), 11) 
            doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -75, -95, 9)
        end
    end
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onCastSpell(cid, var)
    print("spellCast..")
    print("wave 0")
    local target = getCreatureTarget(cid)
    addEvent(spellCast, 1000, cid, target, 1)
    doSendAnimatedText(getCreaturePos(cid), "2", 215)
    doCombat(cid, combat, var)
    return true
end
 
@Xikini View attachment 66686
Post automatically merged:

Only in BLUE returned error
Ah I see. I wasn't even looking at the other function.

Just need to add a check for cid..
Lua:
local function spellCast(cid, target, wave)
    print("spellCast..")
    if wave == 1 then
        print("wave 1")
        if isCreature(cid) then
            print("cid exists.. continuing to wave 2..")
            doSendAnimatedText(getCreaturePos(cid), "1", 215)
            addEvent(spellCast, 1000, cid, target, wave + 1)
        end
    end
    if wave == 2 then
        print("wave 2")
        if isCreature(cid) and isCreature(target) then
            print("cid and target both exist.")
            doSendDistanceShoot(getCreaturePos(cid), getCreaturePos(target), 11) 
            doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -75, -95, 9)
        end
    end
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onCastSpell(cid, var)
    print("spellCast..")
    print("wave 0")
    local target = getCreatureTarget(cid)
    addEvent(spellCast, 1000, cid, target, 1)
    doSendAnimatedText(getCreaturePos(cid), "2", 215)
    doCombat(cid, combat, var)
    return true
end
 
Solution
Back
Top