• 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 doMoveCreature(cid, direction) (DUDE)

beenii

Well-Known Member
Joined
Jul 26, 2010
Messages
586
Solutions
1
Reaction score
58
how walk creatures?

i use movement this:

function onStepIn(cid, item, position, fromPosition)
doMoveCreature(cid, 0)
return true
end

but is very fast, want normal speed on creatures to move. any have idea?
 
Don't know if such a function exists, especially in lower versions of TFS. But you could script a teleport script that uses a timer to move the creature in order to achieve a wanted speed.

local function moveLeft(cid)
local p = getThingPos(cid)
local newp = {x = p.x-1, y= p.y, z = p.z}
doTeleportThing(cid, newp, true)
end

Then in your main function, use:

addEvent(moveLeft, 0, cid)
addEvent(moveLeft, 200, cid)
addEvent(moveLeft, 400, cid)

etc.

Some things worth mentioning:
  • You'd need to make functions like moveLeft for every direction you want available (left, right, down, up, maybe even diagonal ones)
  • You'd need to make the player/monster unable to move with regular controls while the script takes action
  • You could make a 'for' loop for the addEvents to avoid cramping the script with a ton of addEvent lines
  • Speed of pushing the creature to a tile is determined by the delays between addEvents and every time they are pushed, they will walk with their regular movement speed
This is not the most efficient way to do this, but just putting it out there. Best way would be to make a function for this (with all rules included) in source with the help of pathfinding algorithms.
 
I optimized your code @Shadowsong :)
Code:
function move(cid)
    local n = getCreatureLookDirection(cid)
    local p = getThingPos(cid)

    local np = {
        f = function(n)
                if (n == 0) then
                    return {x = p.x, y = p.y + 1, z = p.z}
                elseif (n == 1) then
                    return {x = p.x + 1, y = p.y, z = p.z}
                elseif (n == 2) then
                    return {x = p.x, y = p.y - 1, z = p.z}
                elseif (n == 3) then
                    return {x = p.x - 1, y = p.y, z = p.z}
                end
            end
        }
    doTeleportThing(cid, np.f(n), true)
    --print(unpack(np.f(n))) -- for testing purposes
end

now you can call it
Code:
addEvent(move, 0, cid)
addEvent(move, 200, cid)
addEvent(move, 400, cid)
 
Last edited:
I optimized your code @Shadowsong :)
Code:
function move(cid)
    local n = getCreatureLookDirection(cid)
    local p = getThingPos(cid)

    local np = {
        f = function(n)
                if (n == 0) then
                    return {x = p.x, y = p.y + 1, z = p.z}
                elseif (n == 1) then
                    return {x = p.x + 1, y = p.y, z = p.z}
                elseif (n == 2) then
                    return {x = p.x, y = p.y - 1, z = p.z}
                elseif (n == 3) then
                    return {x = p.x - 1, y = p.y, z = p.z}
                end
            end
        }
    doTeleportThing(cid, np.f(n), true)
    --print(unpack(np.f(n))) -- for testing purposes
end

now you can call it
Code:
addEvent(move, 0, cid)
addEvent(move, 200, cid)
addEvent(move, 400, cid)

Please when you post things; use variables that are linked to the thing you are indexing (in this case direction, position).
Also use the constants to avoid users running into problems in the future.
 
I was going to say something to you WibbenZ but your in your own little world.
Minor correction to the code :p
Code:
function move(cid)
    local n = getCreatureLookDirection(cid)
    local p = getThingPos(cid)

    local np = {
        f = function(n)
                if (n == 0) then
                    return {p.x, p.y + 1, p.z}
                elseif (n == 1) then
                    return {p.x + 1, p.y, p.z}
                elseif (n == 2) then
                    return {p.x, p.y - 1, p.z}
                elseif (n == 3) then
                    return {p.x - 1, p.y, p.z}
                end
            end
    }
    doTeleportThing(cid, np.f(n), true)
    --print(unpack(np.f(n))) -- for testing purposes
end
 
Last edited:
im really need, player or npc or monster walk of poit A to Point B.

example: walk getcreatureposition to cordenate 100, 100, 7.

at moment i use:

local pos = {x = 102, y = 91, z = 3}
doSteerCreature(cid, pos)

only no work large distance and dont move monsters x) ty for yours coments :D
I appreciate
 
Back
Top