• 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.2 Looking for dash spell

SixNine

Active Member
Joined
Dec 12, 2018
Messages
452
Reaction score
41
Hello,
im looking for spell dash like in anime it think it would be pretty cool so basically it would close the distance

Rabbit_Hole2.gif
And it would have like 7 tiles range or something like that it would teleport in front of the enemy u targeted. But ofc probably it shouldnt allow to use it if player is in proteced zone, so people wont dash into someones house or depo and shouldnt allow to use it if that player is blocked by something lets say not passible stone or wall.
 
Solution
51fe940a5efa68a87e4e8d2ae4fae2b6.png
hmm, looks like setMovementBlocked might be a tfs 1.3 thing. Looks like it works fine without it though.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_USECHARGES, true)

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end...
I made this spell some time ago. It charges to your target. You need to have line of sight to your target (so can't go around walls) i believe.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_USECHARGES, true)

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local speed = 25
local range = 7

function charge_calculate_next_pos(direction, pos)
    if direction == 0 then
         return Position(pos.x, pos.y - 1, pos.z)

    elseif direction == 1 then
         return Position(pos.x + 1, pos.y, pos.z)

    elseif direction == 2 then
         return Position(pos.x, pos.y + 1, pos.z)

    elseif direction == 3 then
         return Position(pos.x - 1, pos.y, pos.z)

    elseif direction == 4 then
         return Position(pos.x - 1, pos.y + 1, pos.z)

    elseif direction == 5 then
            return Position(pos.x + 1, pos.y + 1, pos.z)

    elseif direction == 6 then
            return Position(pos.x - 1, pos.y - 1, pos.z)

    elseif direction == 7 then
            return Position(pos.x + 1, pos.y - 1, pos.z)
    end
end

function charge_move(cid, path, key, variant)
    local creature = Creature(cid)
    local player = Player(cid)
    
    if player == nil and creature == nil then
        return false
    end

    if key == 1 then
        creature:setMovementBlocked(true)
    end

    local newPos = creature:getPosition()
    local tempPos = newPos
    for i = 1, 4 do
        if key <= #path then
            newPos = charge_calculate_next_pos(path[key], newPos)

            local tile = Tile(newPos)
            if tile ~= nil and tile:getCreatureCount() > 0 then
                creature:teleportTo(tempPos, true)
                creature:setMovementBlocked(false)
                creature:setDirection(path[key])
                return true
            end

            tempPos = newPos
            key = key + 1
            newPos:sendMagicEffect(CONST_ME_GROUNDSHAKER)
        end
    end

    creature:teleportTo(newPos, false)

    if key <= #path then
        addEvent(charge_move, speed, cid, path, key, variant)
    else
        local target = creature:getTarget()
    
        if player and target then
            doChallengeCreature(player, target)
        end
        creature:setMovementBlocked(false)
        combat:execute(creature, variant)
    end
    return true
end

function charge(creature, variant)
    local target = creature:getTarget()
    local direction = creature:getDirection()
    local position = creature:getPosition()
    
    if target ~= nil then
        local path = creature:getPathTo(target:getPosition(), 0, 1, true, true, range)
        if path and #path > 0 then
            charge_move(creature:getId(), path, 1, variant)
        end
        return true
    end

    return RETURNVALUE_NOTPOSSIBLE
end

function onCastSpell(creature, variant)
    local oldPos = creature:getPosition()
    local returnValue = charge(creature, variant)
    local newPos = creature:getPosition()

    if returnValue == RETURNVALUE_NOTPOSSIBLE or oldPos == newPos then
        creature:sendCancelMessage(returnValue)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    return true
end
 
I made this spell some time ago. It charges to your target. You need to have line of sight to your target (so can't go around walls) i believe.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_USECHARGES, true)

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local speed = 25
local range = 7

function charge_calculate_next_pos(direction, pos)
    if direction == 0 then
         return Position(pos.x, pos.y - 1, pos.z)

    elseif direction == 1 then
         return Position(pos.x + 1, pos.y, pos.z)

    elseif direction == 2 then
         return Position(pos.x, pos.y + 1, pos.z)

    elseif direction == 3 then
         return Position(pos.x - 1, pos.y, pos.z)

    elseif direction == 4 then
         return Position(pos.x - 1, pos.y + 1, pos.z)

    elseif direction == 5 then
            return Position(pos.x + 1, pos.y + 1, pos.z)

    elseif direction == 6 then
            return Position(pos.x - 1, pos.y - 1, pos.z)

    elseif direction == 7 then
            return Position(pos.x + 1, pos.y - 1, pos.z)
    end
end

function charge_move(cid, path, key, variant)
    local creature = Creature(cid)
    local player = Player(cid)
   
    if player == nil and creature == nil then
        return false
    end

    if key == 1 then
        creature:setMovementBlocked(true)
    end

    local newPos = creature:getPosition()
    local tempPos = newPos
    for i = 1, 4 do
        if key <= #path then
            newPos = charge_calculate_next_pos(path[key], newPos)

            local tile = Tile(newPos)
            if tile ~= nil and tile:getCreatureCount() > 0 then
                creature:teleportTo(tempPos, true)
                creature:setMovementBlocked(false)
                creature:setDirection(path[key])
                return true
            end

            tempPos = newPos
            key = key + 1
            newPos:sendMagicEffect(CONST_ME_GROUNDSHAKER)
        end
    end

    creature:teleportTo(newPos, false)

    if key <= #path then
        addEvent(charge_move, speed, cid, path, key, variant)
    else
        local target = creature:getTarget()
   
        if player and target then
            doChallengeCreature(player, target)
        end
        creature:setMovementBlocked(false)
        combat:execute(creature, variant)
    end
    return true
end

function charge(creature, variant)
    local target = creature:getTarget()
    local direction = creature:getDirection()
    local position = creature:getPosition()
   
    if target ~= nil then
        local path = creature:getPathTo(target:getPosition(), 0, 1, true, true, range)
        if path and #path > 0 then
            charge_move(creature:getId(), path, 1, variant)
        end
        return true
    end

    return RETURNVALUE_NOTPOSSIBLE
end

function onCastSpell(creature, variant)
    local oldPos = creature:getPosition()
    local returnValue = charge(creature, variant)
    local newPos = creature:getPosition()

    if returnValue == RETURNVALUE_NOTPOSSIBLE or oldPos == newPos then
        creature:sendCancelMessage(returnValue)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    return true
end
51fe940a5efa68a87e4e8d2ae4fae2b6.png
 
hmm, looks like setMovementBlocked might be a tfs 1.3 thing. Looks like it works fine without it though.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_USECHARGES, true)

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local speed = 25
local range = 7

function charge_calculate_next_pos(direction, pos)
    if direction == 0 then
         return Position(pos.x, pos.y - 1, pos.z)

    elseif direction == 1 then
         return Position(pos.x + 1, pos.y, pos.z)

    elseif direction == 2 then
         return Position(pos.x, pos.y + 1, pos.z)

    elseif direction == 3 then
         return Position(pos.x - 1, pos.y, pos.z)

    elseif direction == 4 then
         return Position(pos.x - 1, pos.y + 1, pos.z)

    elseif direction == 5 then
            return Position(pos.x + 1, pos.y + 1, pos.z)

    elseif direction == 6 then
            return Position(pos.x - 1, pos.y - 1, pos.z)

    elseif direction == 7 then
            return Position(pos.x + 1, pos.y - 1, pos.z)
    end
end

function charge_move(cid, path, key, variant)
    local creature = Creature(cid)
    local player = Player(cid)
    
    if player == nil and creature == nil then
        return false
    end

    local newPos = creature:getPosition()
    local tempPos = newPos
    for i = 1, 4 do
        if key <= #path then
            newPos = charge_calculate_next_pos(path[key], newPos)

            local tile = Tile(newPos)
            if tile ~= nil and tile:getCreatureCount() > 0 then
                creature:teleportTo(tempPos, true)
                creature:setDirection(path[key])
                return true
            end

            tempPos = newPos
            key = key + 1
            newPos:sendMagicEffect(CONST_ME_GROUNDSHAKER)
        end
    end

    creature:teleportTo(newPos, false)

    if key <= #path then
        addEvent(charge_move, speed, cid, path, key, variant)
    else
        local target = creature:getTarget()
    
        if player and target then
            doChallengeCreature(player, target)
        end
        combat:execute(creature, variant)
    end
    return true
end

function charge(creature, variant)
    local target = creature:getTarget()
    local direction = creature:getDirection()
    local position = creature:getPosition()
    
    if target ~= nil then
        local path = creature:getPathTo(target:getPosition(), 0, 1, true, true, range)
        if path and #path > 0 then
            charge_move(creature:getId(), path, 1, variant)
        end
        return true
    end

    return RETURNVALUE_NOTPOSSIBLE
end

function onCastSpell(creature, variant)
    local oldPos = creature:getPosition()
    local returnValue = charge(creature, variant)
    local newPos = creature:getPosition()

    if returnValue == RETURNVALUE_NOTPOSSIBLE or oldPos == newPos then
        creature:sendCancelMessage(returnValue)
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    return true
end
 
Solution
Hello,
im looking for spell dash like in anime it think it would be pretty cool so basically it would close the distance

View attachment 64116
And it would have like 7 tiles range or something like that it would teleport in front of the enemy u targeted. But ofc probably it shouldnt allow to use it if player is in proteced zone, so people wont dash into someones house or depo and shouldnt allow to use it if that player is blocked by something lets say not passible stone or wall.
See if you like this one:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local unwanted_tilestates = { TILESTATE_PROTECTIONZONE, TILESTATE_HOUSE, TILESTATE_FLOORCHANGE, TILESTATE_TELEPORT, TILESTATE_BLOCKSOLID, TILESTATE_BLOCKPATH }

function onCastSpell(creature, variant)
    local target = creature:getTarget()
    local toPosition = false
    if target then
        toPosition = target:getPosition()
        toPosition:getNextPosition(target:getDirection(), 1)
    else
        toPosition = creature:getPosition()
        toPosition:getNextPosition(creature:getDirection(), 7)
    end

    local tile = toPosition and Tile(toPosition)
    if not tile then
        return false
    end

    for _, tilestate in pairs(unwanted_tilestates) do
        if tile:hasFlag(tilestate) then
            creature:sendCancelMessage("You cannot dash here.")
            return false
        end
    end

    creature:getPosition():sendMagicEffect(CONST_ME_POFF)
    creature:teleportTo(toPosition)
    toPosition:sendMagicEffect(CONST_ME_TELEPORT)

    return combat:execute(creature, variant)
end
 
Back
Top