• 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 spell error returning a nil value

shivaria

Active Member
Joined
Sep 2, 2009
Messages
158
Reaction score
36
can anyone help me with this? possibly converting to tfs 1.1 (10.77)

These are showing errors returning a nil value.
targetList = getSpectators(getCreaturePosition(target), 3, 3, false)
targets[1] = getNextTarget(p.target)

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -1, -1, -1, -10)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 12)

local targetList = {}
local targets = {}
local time_ = 300
local effect = {}

function secondShot(target1, target2, p)
    local var = positionToVariant(target2)
    doSendDistanceShoot(target1, target2, 33)
    doCombat(p.cid, combat, var)
end

function getNextTarget(target)
    [COLOR=#ff0000]targetList = getSpectators(getCreaturePosition(target), 3, 3, false)[/COLOR]
    return targetList[math.random(1, #targetList)]
end

function doBolt(p)
    if p.check ~= nil then
        doSendDistanceShoot(p.pos, p.targetPos, 33)
        local list = getSpectators(p.targetPos, 3, 3, false)
       [COLOR=#ff0000] targets[1] = getNextTarget(p.target)[/COLOR]
        if next(list) then
            for i = 1, #list do
                targets[i+1] = getNextTarget(targets[i])
                addEvent(secondShot, time_ * i, getCreaturePosition(targets[i]), getCreaturePosition(targets[i+1]), p)
            end
        end
    else
        p.check = 2
        if p.targetDir % 2 == 0 then -- 0 / 2 = 0, 2 / 2 = 0
            effect[1] = {x = p.pos.x -1, y = p.pos.y, z = p.pos.z} -- nwpos
            effect[2] = {x = p.pos.x +1, y = p.pos.y, z = p.pos.z} -- nepos
        else
            effect[1] = {x = p.pos.x, y = p.pos.y +1, z = p.pos.z} -- wnpos
            effect[2] = {x = p.pos.x, y = p.pos.y -1, z = p.pos.z} -- wspos
        end
        doSendDistanceShoot(p.pos, effect[1], 33)
        doSendDistanceShoot(p.pos, effect[2], 33)
        addEvent(doBolt, 100, p)
        addEvent(doBolt, 100, p)
    end
    return true
end

function onCastSpell(cid, var)
    local p = {}
    local player = Player(cid)
    p = {
        cid = cid,
        target = player:getTarget(),
        targetPos = player:getTarget():getPosition(),
        targetDir = player:getTarget():getDirection(),
        pos = player:getPosition()
    }
    doBolt(p)
    return true
end
[/code/>
 
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -1, -1, -1, -10)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_ENERGYHIT)

local targetList = {}
local targets = {}
local time_ = 300
local effect = {}
local shootEffect = CONST_ANI_FLASHARROW

local function secondShot(target1, target2, p)
    local var = positionToVariant(target2)
    doSendDistanceShoot(target1, target2, shootEffect)
    combat:execute(p.player, var)
end

local function getNextTarget(target)
    targetList = getSpectators(target:getPosition(), 3, 3, false)
    return targetList[math.random(1, #targetList)]
end

local function doBolt(p)
    if p.check ~= nil then
        doSendDistanceShoot(p.pos, p.targetPos, shootEffect)
        local list = getSpectators(p.targetPos, 3, 3, false)
        targets[1] = getNextTarget(p.target)
        if next(list) then
            for i = 1, #list do
                targets[i+1] = getNextTarget(targets[i])
                addEvent(secondShot, time_ * i, targets[i]:getPosition(), targets[i+1]:getPosition(), p)
            end
        end
    else
        p.check = 2
        if p.targetDir % 2 == 0 then -- 0 / 2 = 0, 2 / 2 = 0
            effect[1] = {x = p.pos.x -1, y = p.pos.y, z = p.pos.z} -- nwpos
            effect[2] = {x = p.pos.x +1, y = p.pos.y, z = p.pos.z} -- nepos
        else
            effect[1] = {x = p.pos.x, y = p.pos.y +1, z = p.pos.z} -- wnpos
            effect[2] = {x = p.pos.x, y = p.pos.y -1, z = p.pos.z} -- wspos
        end
        doSendDistanceShoot(p.pos, effect[1], shootEffect)
        doSendDistanceShoot(p.pos, effect[2], shootEffect)
        addEvent(doBolt, 100, p)
        addEvent(doBolt, 100, p)
    end
    return true
end

function onCastSpell(creature, var)
    local p = {}
    p = {
        player = creature,
        target = creature:getTarget(),
        targetPos = creature:getTarget():getPosition(),
        targetDir = creature:getTarget():getDirection(),
        pos = creature:getPosition()
    }
    return doBolt(p)
end
 
Last edited:
eamohu.png
This is what error I get from the new code.
 
2uysqqr.png
this is after I removed the :
It originally worked when I wrote it, sure it had some issues, but like all open source scripts, there is no implied support for them, so i highly recommend you learn the supporting language (LUA) so that you may find your own solution :)
 
These:
targetList = getSpectators(getCreaturePosition(target), 3, 3, false)
targets[1] = getNextTarget(p.target)
were returning a nil value causing an error in the server window, wouldnt it be easier to find a way to add a check and add something like return luanoerror etc

I been working with lua for over 10 years, if you cant fix this then theres no hope lol
 
These:
targetList = getSpectators(getCreaturePosition(target), 3, 3, false)
targets[1] = getNextTarget(p.target)
were returning a nil value causing an error in the server window, wouldnt it be easier to find a way to add a check and add something like return luanoerror etc

I been working with lua for over 10 years, if you cant fix this then theres no hope lol
My machine is a piece of shit, if I were at work I could run a server no problem and find a solution but I am not and it is a holiday weekend so for now I can't test or fix anything :(
 
Back
Top