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

Custom spell self nil error.

Ziore

New Member
Joined
Jul 8, 2021
Messages
1
Reaction score
0
Location
Netherlands
TFS 1.3 + OTC 8
I wanted to make a spell that has a chance to hit when it fires and when it returns it should hit everything in range, but for some reason i get a self nill error.

data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:26: attempt to index local 'self' (a nil value)
stack traceback:
[C]: in function '__index'
data/events/scripts/creature.lua:26: in function <data/events/scripts/creature.lua:22>
[C]: in function 'doCombat'
data/spells/scripts/ziore/pool_of_blood.lua:54: in function <data/spells/scripts/ziore/pool_of_blood.lua:53>

Lua:
local preRandomCombat, returningdmgCombat, combat = createCombatObject(), createCombatObject(), createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_BLOODYSTEPS)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(returningdmgCombat, COMBAT_PARAM_EFFECT, CONST_ME_DRAWBLOOD)
setCombatParam(returningdmgCombat, COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
local arr1 = {
    -- size
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
}
setCombatArea(preRandomCombat, createCombatArea(arr1))
setCombatArea(returningdmgCombat, createCombatArea(arr1))
function onTargetTileRandom(cid, pos)
    return math.random(2) == 1 and doCombat(cid, combat, positionToVariant(pos))
end
function onTargetTileReal(cid, pos)
    if math.random() == 0 then
        return false
    end
    local player = Player(cid)
    if not player then
        return false
    end
    local playerID = player:getId()
    player:getPosition():sendDistanceEffect(pos, CONST_ANI_EXPLOSION)
    addEvent(returnBlood, 1300, playerID, pos)
    return math.random(2) == 1 and doCombat(cid, combat, positionToVariant(pos))
end
function returnBlood(cid, pos)
    local player = Player(cid)
    pos:sendDistanceEffect(player:getPosition(), CONST_ANI_EXPLOSION)
end
function doReturningDamage(c, cid, var)
    doCombat(cid, c, var)
end
function onGetFormulaValues(player, skill, attack, factor)
    return (10) * -1, (20) * -1
end
setCombatCallback(preRandomCombat, CALLBACK_PARAM_TARGETTILE, 'onTargetTileRandom')
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, 'onTargetTileReal')
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, 'onGetFormulaValues')
setCombatCallback(returningdmgCombat, CALLBACK_PARAM_SKILLVALUE, 'onGetFormulaValues')
function onCastSpell(cid, var)
    local player = Player(cid)
    if not player then
        return false
    end
    local playerID = player.getId()
    doCombat(cid, preRandomCombat, var)
    addEvent(doReturningDamage, 1000, returningdmgCombat, playerID, var)
    return true
end

Any ideas how to fix this would be lovely.
Regards, Ziore
 
Last edited:
Back
Top