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

TFS 1.X+ Problem with table (including cid even with command to not do so)

oserc

Advanced OT User
Joined
Mar 5, 2022
Messages
148
Solutions
1
Reaction score
194
Location
Brazil
Hey boys and girls, all good?

I'm trying to create a custom spell for my server, it's a simple "arrow shower" (it shoots 2 bonus arrows on 2 different creatures that are near the main target, 1 sqm away max).

The script is written as follows:

Lua:
function onCastSpell(cid, var)
    local formula = {
    min = 10,
    max = 15,
    }
 
local player = Player(cid)
local playerpos = player:getPosition()
local target = player:getTarget()
local targetpos = target:getPosition()
local targets = {}
local x = 1

for x = targetpos.x - 1, targetpos.x + 1 do
    for y = targetpos.y - 1, targetpos.y + 1 do
        local v = getTopCreature({x=x, y=y, z=targetpos.z}).uid
        if isPlayer(v) or isMonster(v) and v ~= cid then
                    table.insert(targets, v)
    end
    end
end

for i = 1, #targets do
        if x <= 3 then
        doTargetCombatHealth(cid, targets[i], COMBAT_PHYSICALDAMAGE, - formula.min, - formula.max, CONST_ME_HITAREA)
        playerpos:sendDistanceEffect(getThingPos(targets[i]), CONST_ANI_ARROW)
        x = x+1
        end
    end
end

Problem is: if I get in range of 1 sqm from the target, my char will get included in the table, even if I specifically have written not to do so ("v ~= cid then"). What I am doing wrong? Searched all forum for an answer and couldn't find any issue regarging this situation.

Plus, i would like to necessarily include the "main" target in table. If I use a spell on a mob with +3 creatures, sometimes the main target won't get hitted.

Any help?

BTW, I'm using TFS 1.4.1 (10.98), with Otclient Redemption 1.0.
 
Last edited:
Solution
Use parenthesis
Lua:
if (isPlayer(v) or isMonster(v)) and v ~= cid then
still the same... =\
Post automatically merged:

Okay, changed "cid" for "player:getId()" and now it's working properly lol, like this: if isPlayer(v) or isMonster(v) and v ~= player:getId() then

but still couldn't manage to insert necessarily the main target in the table (depending on mob quantity, the spell targets other 3 targets, and the main on gets no damage).
Use parenthesis and cid is returning userdata
Lua:
if (isPlayer(v) or isMonster(v)) and v ~= cid:getId() then
 
Last edited:
Use parenthesis
Lua:
if (isPlayer(v) or isMonster(v)) and v ~= cid then
still the same... =\
Post automatically merged:

Okay, changed "cid" for "player:getId()" and now it's working properly lol, like this: if isPlayer(v) or isMonster(v) and v ~= player:getId() then

but still couldn't manage to insert necessarily the main target in the table (depending on mob quantity, the spell targets other 3 targets, and the main on gets no damage).
 
Last edited:
Solution
I never leave the thread after you quoted, didnt saw your "solution" in which you will ended up facing the same issue if you are surrounded by only players due missing parenthesis
 
Back
Top