• 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 Dash Spell with error tfs 0.4

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
I have one spell (dash spell), when use a spell your person "rum" 15 sqms, they can`t enter in pzone (ok) cant enter in house (ok), but have one bug,
the player can step on a non-existent tile, such as the photo:

The red square is not walkable tile, and player and the player can step with this spell, How should I solve it?
The red square red getTileInfo == 0
IMG: https://imageshack.com/a/img923/4163/Krt1DB.png

SCRIPT, I USE TFS 0.4:
Code:
local damage = 20 -- dano que toma qnd bate em algum obstáculo
local speed = 910 -- velocidade do player ao usar o dash (vai de 0 a mil)
local pzprotect = true -- nao deixa entrar em pz com a spell
local distance = 15 -- quantos sqms anda
local function isWalkable(pos, creature, proj, pz)-- by Nord
    if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
    if getTopCreature(pos).uid > 0 and creature then return false end
    if getTileInfo(pos).protection and pz then return false, true end
    local n = not proj and 3 or 2
    for i = 0, 255 do
        pos.stackpos = i
        local tile = getTileThingByPos(pos)
        if tile.itemid ~= 0 and not isCreature(tile.uid) then
            if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                return false
            end
        end
    end
    return true
end
function onWalk(cid)
    if isCreature(cid) then
        local poslook = getCreatureLookPosition(cid)
        poslook.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
        if isWalkable(poslook, false, false, pzprotect) then
            if not isCreature(getThingfromPos(poslook).uid) then
                doMoveCreature(cid, getPlayerLookDirection(cid))
                doSendMagicEffect(getPlayerPosition(cid), 14)
            else
                doCreatureAddHealth(cid, -damage)
                doSendMagicEffect(getPlayerPosition(cid), 31)
                doSendAnimatedText(getPlayerPosition(cid), "-"..damage , 180)
            end
        else   
            doCreatureAddHealth(cid, -damage)
            doSendMagicEffect(getPlayerPosition(cid), 31)
            doSendAnimatedText(getPlayerPosition(cid), "-"..damage , 180)
        end
    end
return true
end
function onCastSpell(cid, var) 
    for i = 0, distance do
        addEvent(onWalk, (1001- math.min(speed, 1000)) *i, cid)
    end
return true
end
 
Solution
giphy.gif


Lua:
local damage = 20 -- dano que toma qnd bate em algum obstáculo
local speed = 910 -- velocidade do player ao usar o dash (vai de 0 a mil)
local pzprotect = true -- nao deixa entrar em pz com a spell
local distance = 15 -- quantos sqms anda
local function nextPositionByLookDirection(cid, pos)
    local r = {}
    local data =
        {
            [NORTH] = {x = 0, y = -1, z = 0},
            [EAST] = {x = 1, y = 0, z = 0},
            [SOUTH] = {x = 0, y = 1, z = 0},
            [WEST] = {x = -1, y = 0, z = 0}
        }
    for dir, tpos in pairs(data) do
        if getCreatureLookDirection(cid) == dir then
            r = {x = pos.x + tpos.x, y = pos.y + tpos.y, z = pos.z + tpos.z}...
The problem is most likely that it's counting the grass border as a "walkable", can't think of an optimal solution right now though.
 
The problem is most likely that it's counting the grass border as a "walkable", can't think of an optimal solution right now though.

I have tested this function:

local pos = {x=931,y=1091,z=6,stackpos=1}
if getTileThingByPos(pos).uid ~= 0 then
print ("a")
else
print("b")
end

When i put local pos = walkable tile, it print a
When i put local pos = a grass border, it print b....
but I'm not able to implement this formula in the spell script above, would you know to help me?
@Xikini do u know?
 
Last edited:
Hello, to the function "isWalkable" you can add more conditions "IF" hasProperty(uid, prop)
Lua:
CONST_PROP_BLOCKSOLID     
         CONST_PROP_HASHEIGHT     
         CONST_PROP_BLOCKPROJECTILE     
         CONST_PROP_BLOCKPATH     
         CONST_PROP_ISVERTICAL     
         CONST_PROP_ISHORIZONTAL     
         CONST_PROP_MOVEABLE     
         CONST_PROP_IMMOVABLEBLOCKSOLID     
         CONST_PROP_IMMOVABLEBLOCKPATH     
         CONST_PROP_IMMOVABLENOFIELDBLOCKPATH     
         CONST_PROP_NOFIELDBLOCKPATH     
         CONST_PROP_SUPPORTHANGABLE
 
giphy.gif


Lua:
local damage = 20 -- dano que toma qnd bate em algum obstáculo
local speed = 910 -- velocidade do player ao usar o dash (vai de 0 a mil)
local pzprotect = true -- nao deixa entrar em pz com a spell
local distance = 15 -- quantos sqms anda
local function nextPositionByLookDirection(cid, pos)
    local r = {}
    local data =
        {
            [NORTH] = {x = 0, y = -1, z = 0},
            [EAST] = {x = 1, y = 0, z = 0},
            [SOUTH] = {x = 0, y = 1, z = 0},
            [WEST] = {x = -1, y = 0, z = 0}
        }
    for dir, tpos in pairs(data) do
        if getCreatureLookDirection(cid) == dir then
            r = {x = pos.x + tpos.x, y = pos.y + tpos.y, z = pos.z + tpos.z}
            break
        end
    end
    return r
end
local function isWalkable(cid, pos, creature, proj, pz)-- by Nord
    if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
    if getTileThingByPos(nextPositionByLookDirection(cid, pos)).itemid == 0 then return false end
    if getTopCreature(pos).uid > 0 and creature then return false end
    if getTileInfo(pos).protection and pz then return false, true end
    local n = not proj and 3 or 2
    for i = 0, 255 do
        pos.stackpos = i
        local tile = getTileThingByPos(pos)
        if tile.itemid ~= 0 and not isCreature(tile.uid) then
            if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                return false
            end
        end
    end
    return true
end
function onWalk(cid)
    if isCreature(cid) then
        local poslook = getCreatureLookPosition(cid)
        poslook.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
        if isWalkable(cid, poslook, false, false, pzprotect) then
            if not isCreature(getThingfromPos(poslook).uid) then
                doMoveCreature(cid, getPlayerLookDirection(cid))
                doSendMagicEffect(getPlayerPosition(cid), 14)
            else
                doCreatureAddHealth(cid, -damage)
                doSendMagicEffect(getPlayerPosition(cid), 31)
                doSendAnimatedText(getPlayerPosition(cid), "-"..damage , 180)
            end
        else 
            doCreatureAddHealth(cid, -damage)
            doSendMagicEffect(getPlayerPosition(cid), 31)
            doSendAnimatedText(getPlayerPosition(cid), "-"..damage , 180)
        end
    end
return true
end
function onCastSpell(cid, var)
    for i = 0, distance do
        addEvent(onWalk, (1001- math.min(speed, 1000)) *i, cid)
    end
return true
end
 
Solution
giphy.gif


Lua:
local damage = 20 -- dano que toma qnd bate em algum obstáculo
local speed = 910 -- velocidade do player ao usar o dash (vai de 0 a mil)
local pzprotect = true -- nao deixa entrar em pz com a spell
local distance = 15 -- quantos sqms anda
local function nextPositionByLookDirection(cid, pos)
    local r = {}
    local data =
        {
            [NORTH] = {x = 0, y = -1, z = 0},
            [EAST] = {x = 1, y = 0, z = 0},
            [SOUTH] = {x = 0, y = 1, z = 0},
            [WEST] = {x = -1, y = 0, z = 0}
        }
    for dir, tpos in pairs(data) do
        if getCreatureLookDirection(cid) == dir then
            r = {x = pos.x + tpos.x, y = pos.y + tpos.y, z = pos.z + tpos.z}
            break
        end
    end
    return r
end
local function isWalkable(cid, pos, creature, proj, pz)-- by Nord
    if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
    if getTileThingByPos(nextPositionByLookDirection(cid, pos)).itemid == 0 then return false end
    if getTopCreature(pos).uid > 0 and creature then return false end
    if getTileInfo(pos).protection and pz then return false, true end
    local n = not proj and 3 or 2
    for i = 0, 255 do
        pos.stackpos = i
        local tile = getTileThingByPos(pos)
        if tile.itemid ~= 0 and not isCreature(tile.uid) then
            if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                return false
            end
        end
    end
    return true
end
function onWalk(cid)
    if isCreature(cid) then
        local poslook = getCreatureLookPosition(cid)
        poslook.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
        if isWalkable(cid, poslook, false, false, pzprotect) then
            if not isCreature(getThingfromPos(poslook).uid) then
                doMoveCreature(cid, getPlayerLookDirection(cid))
                doSendMagicEffect(getPlayerPosition(cid), 14)
            else
                doCreatureAddHealth(cid, -damage)
                doSendMagicEffect(getPlayerPosition(cid), 31)
                doSendAnimatedText(getPlayerPosition(cid), "-"..damage , 180)
            end
        else
            doCreatureAddHealth(cid, -damage)
            doSendMagicEffect(getPlayerPosition(cid), 31)
            doSendAnimatedText(getPlayerPosition(cid), "-"..damage , 180)
        end
    end
return true
end
function onCastSpell(cid, var)
    for i = 0, distance do
        addEvent(onWalk, (1001- math.min(speed, 1000)) *i, cid)
    end
return true
end

Nice!
 
Lua:
local damage = 20 -- dano que toma qnd bate em algum obstáculo
local speed = 910 -- velocidade do player ao usar o dash (vai de 0 a mil)
local pzprotect = true -- nao deixa entrar em pz com a spell
local distance = 15 -- quantos sqms anda
local function nextPositionByLookDirection(cid, pos)
    local r = {}
    local data =
        {
            [NORTH] = {x = 0, y = -1, z = 0},
            [EAST] = {x = 1, y = 0, z = 0},
            [SOUTH] = {x = 0, y = 1, z = 0},
            [WEST] = {x = -1, y = 0, z = 0}
        }
    for dir, tpos in pairs(data) do
        if getCreatureLookDirection(cid) == dir then
            r = {x = pos.x + tpos.x, y = pos.y + tpos.y, z = pos.z + tpos.z}
            break
        end
    end
    return r
end
local function isWalkable(cid, pos, creature, proj, pz)-- by Nord
    if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
    if getTileThingByPos(nextPositionByLookDirection(cid, pos)).itemid == 0 then return false end
    if getTopCreature(pos).uid > 0 and creature then return false end
    if getTileInfo(pos).protection and pz then return false, true end
    local n = not proj and 3 or 2
    for i = 0, 255 do
        pos.stackpos = i
        local tile = getTileThingByPos(pos)
        if tile.itemid ~= 0 and not isCreature(tile.uid) then
            if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                return false
            end
        end
    end
    return true
end
function onWalk(cid)
    if isCreature(cid) then
        local poslook = getCreatureLookPosition(cid)
        poslook.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
        if isWalkable(cid, poslook, false, false, pzprotect) then
            if not isCreature(getThingfromPos(poslook).uid) then
                doMoveCreature(cid, getPlayerLookDirection(cid))
                doSendMagicEffect(getPlayerPosition(cid), 14)
            else
                doCreatureAddHealth(cid, -damage)
                doSendMagicEffect(getPlayerPosition(cid), 31)
                doSendAnimatedText(getPlayerPosition(cid), "-"..damage , 180)
            end
        else
            doCreatureAddHealth(cid, -damage)
            doSendMagicEffect(getPlayerPosition(cid), 31)
            doSendAnimatedText(getPlayerPosition(cid), "-"..damage , 180)
        end
    end
return true
end
function onCastSpell(cid, var)
    for i = 0, distance do
        addEvent(onWalk, (1001- math.min(speed, 1000)) *i, cid)
    end
return true
end
thank you my friend, I have tested it and it is 100% correct!
 
Back
Top