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

Quite an advanced spell checking valid target.

sestorme

Member
Joined
Dec 9, 2011
Messages
272
Reaction score
6
Location
Birmingham, UK
Okay, some time ago I made my own spellbook system with quite a few nice spells, like a custom fireball spell which is launched to the desired location, but explodes on the first valid target. My old hdd decided to follow it's own path that lead it to the drawer as it's likely not to ever work again and I had a break from coding and/or scripting for a while.

Tibia Ots Spellbook system - Sorcerer presentation - YouTube

Look at the spell 4:18+. Fireball is launched to the location but instead of going there it explodes on the first valid target. Believe it or not, I've forgot how I made it. It definitely checks checks quite a few squares between location of caster and location of target and divides it by 6 or 7. Anyone want to give it a go and remake it?
 
You got me, had to try it out. This is what I came up with :D
Just tried some fun shit :)

LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
setAttackFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 5, 5, 1.4, 2.8, 40, 70)

local area = createCombatArea(AREA_SQUARE1X1)
setCombatArea(combat, area)

function onCastSpell(cid, var)
    local checkPos = {}
    local toPosition, pos = variantToPosition(var), getThingPos(cid)
    local diffX, diffY = (math.max(pos.x, toPosition.x) - math.min(pos.x, toPosition.x)), (math.max(pos.y, toPosition.y) - math.min(pos.y, toPosition.y))
    for x = math.min(pos.x, toPosition.x), math.max(pos.x, toPosition.x) do
        for y = math.min(pos.y, toPosition.y), math.max(pos.y, toPosition.y) do
            local cx, cy = x - math.min(pos.x, toPosition.x), y - math.min(pos.y, toPosition.y)
            if diffX > diffY then
                local d = diffY / diffX
                if d * cx < 1 + cy and d * cx >= cy - 1 then
                    table.insert(checkPos, {x = x, y = y, z = toPosition.z, stackpos = 253})
                end
            else
                local d = diffX / diffY
                if d * cy < 1 + cx and d * cy >= cx - 1 then
                    table.insert(checkPos, {x = x, y = y, z = toPosition.z, stackpos = 253})
                end
            end
        end
    end
    
    if diffX == 0 or diffY == 0 then
        for i = (diffX == 0 and math.min(pos.y, toPosition.y) or math.min(pos.x, toPosition.x)), (diffX == 0 and math.max(pos.y, toPosition.y) or math.max(pos.x, toPosition.x)) do
            table.insert(checkPos, {x = (diffX == 0 and pos.x or i), y = (diffY == 0 and pos.y or i), z = toPosition.z, stackpos = 253})
        end
    end
    
    table.sort(checkPos, function(a, b) return getDistanceBetween(a, pos) < getDistanceBetween(b, pos) end)
    
    for _, cpos in pairs(checkPos) do
        local thing = getThingFromPos(cpos) 
        if thing.uid > 0 and isCreature(thing.uid) and thing.uid ~= cid then
            return doCombat(cid, combat, positionToVariant(cpos))
        end
    end
    
    return doCombat(cid, combat, var)
end
 
Last edited:
Thing is, that this is custom damage system and I use doTargetCombatHealth and a custom area;

local pos = {
[1] = {x=cpos.x-1, y=cpos.y, z=cpos.z, stackpos=253},
[2] = {x=cpos.x-1, y=cpos.y-1, z=cpos.z, stackpos=253},
[3] = {x=cpos.x, y=cpos.y-1, z=cpos.z, stackpos=253},
[4] = {x=cpos.x+1, y=cpos.y, z=cpos.z, stackpos=253},
[5] = {x=cpos.x+1, y=cpos.y+1, z=cpos.z, stackpos=253},
[6] = {x=cpos.x, y=cpos.y+1, z=cpos.z, stackpos=253},
[7] = {x=cpos.x-1, y=cpos.y+1, z=cpos.z, stackpos=253},
[8] = {x=cpos.x+1, y=cpos.y-1, z=cpos.z, stackpos=253}
}
local thing = 0
for i = 1,#pos do

Do you want to try to change it?
 
Back
Top