• 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 Movement with action

Wix

Banned User
Joined
Jan 3, 2021
Messages
29
Solutions
1
Reaction score
14
Location
Krypton
Hello I was facing troubles with this script it was working in old distro but when I used it in 0.3.7 it didn't work can someone give a hint or correct something because it doesn't show any errors in console or anything basically this works as huskies dog sled when u step in this item it start to sledding you to reach this actionid in 9001 in one direction then it stops if u could also improve it putting the path it goes to go or some x,y,z postion to go i mean it walks in only one direction
Lua:
function addSled(params)
    local startpos = params.startpos
    local spawnDelay = params.spawnDelay
   
    local speed = 250 --The speed in miliseconds before the sled moves 1 tile
   
    local pos = params.pos
    local cid = params.cid
   
    -- Dont edit any of the following unless you know what your doing
    local groundpos = {x=pos.x, y=pos.y, z=pos.z, stackpos=0}
    local ground = getThingfromPos(groundpos)
       
    pos1 = {x=pos.x, y=pos.y, z=pos.z, stackpos=1}
    pos2 = {x=pos.x, y=pos.y+2, z=pos.z, stackpos=1}
    pos3 = {x=pos.x, y=pos.y+3, z=pos.z, stackpos=1}
    pos4 = {x=pos.x, y=pos.y+5, z=pos.z, stackpos=1}
    item1 = getThingfromPos(pos1)
    item2 = getThingfromPos(pos2)
    item3 = getThingfromPos(pos3)
    item4 = getThingfromPos(pos4)
   
    newpos = {x=pos.x, y=pos.y+1, z=pos.z}
   
    if ground.actionid == 9001 then
        spawnparams = {startpos = startpos, pos = pos}
        addEvent(spawnSled,spawnDelay*1000,spawnparams)
        setPlayerStorageValue(cid,9006,-1)
    else
        doRemoveItem(item1.uid,1)
        doRemoveItem(item2.uid,1)
        doRemoveItem(item3.uid,1)
        doRemoveItem(item4.uid,1)
       
        newpos1 = {x=newpos.x, y=newpos.y, z=newpos.z}
        newpos2 = {x=newpos.x, y=newpos.y+2, z=newpos.z}
        newpos3 = {x=newpos.x, y=newpos.y+3, z=newpos.z}
        newpos4 = {x=newpos.x, y=newpos.y+5, z=newpos.z}
        doCreateItem(7266,1,newpos1)
        doCreateItem(7268,1,newpos2)
        doCreateItem(7269,1,newpos3)
        doCreateItem(7270,1,newpos4)
       
        doTeleportThing(cid, newpos)
       
        newparams = {pos = newpos, cid = cid, startpos = startpos, spawnDelay = 10}
        addEvent(addSled,speed,newparams)
    end
end

function spawnSled(params)
    local startpos = params.startpos
    local pos = params.pos
    pos1 = {x=startpos.x, y=startpos.y, z=startpos.z}
    pos2 = {x=startpos.x, y=startpos.y+2, z=startpos.z}
    pos3 = {x=startpos.x, y=startpos.y+3, z=startpos.z}
    pos4 = {x=startpos.x, y=startpos.y+5, z=startpos.z}
    doCreateItem(7266,1,pos1)
    doCreateItem(7268,1,pos2)
    doCreateItem(7269,1,pos3)
    doCreateItem(7270,1,pos4)
   
    pos1 = {x=pos.x, y=pos.y, z=pos.z, stackpos=1}
    pos2 = {x=pos.x, y=pos.y+2, z=pos.z, stackpos=1}
    pos3 = {x=pos.x, y=pos.y+3, z=pos.z, stackpos=1}
    pos4 = {x=pos.x, y=pos.y+5, z=pos.z, stackpos=1}
    item1 = getThingfromPos(pos1)
    item2 = getThingfromPos(pos2)
    item3 = getThingfromPos(pos3)
    item4 = getThingfromPos(pos4)
    doRemoveItem(item1.uid,1)
    doRemoveItem(item2.uid,1)
    doRemoveItem(item3.uid,1)
    doRemoveItem(item4.uid,1)
   
    ppos1 = {x=startpos.x, y=startpos.y, z=startpos.z, stackpos=253}
    ppos2 = {x=startpos.x, y=startpos.y+2, z=startpos.z, stackpos=253}
    ppos3 = {x=startpos.x, y=startpos.y+3, z=startpos.z, stackpos=253}
    ppos4 = {x=startpos.x, y=startpos.y+5, z=startpos.z, stackpos=253}
    player1 = getThingfromPos(ppos1)
    player2 = getThingfromPos(ppos2)
    player3 = getThingfromPos(ppos3)
    player4 = getThingfromPos(ppos4)
   
    nppos1 = {x=startpos.x+1, y=startpos.y, z=startpos.z}
    nppos2 = {x=startpos.x+1, y=startpos.y+2, z=startpos.z}
    nppos3 = {x=startpos.x+1, y=startpos.y+3, z=startpos.z}
    nppos4 = {x=startpos.x+1, y=startpos.y+5, z=startpos.z}
    if player1.itemid > 0 then
        doTeleportThing(player1.uid, nppos1)
    end
    if player2.itemid > 0 then
        doTeleportThing(player2.uid, nppos2)
    end
    if player3.itemid > 0 then
        doTeleportThing(player3.uid, nppos3)
    end
    if player4.itemid > 0 then
        doTeleportThing(player4.uid, nppos4)
    end
end

function onStepIn(cid, item, pos)
    if isPlayer(cid) == 1 then
        isMoving = getPlayerStorageValue(cid,9006)
        if item.itemid == 7266 and isMoving == -1 then
            params = {cid = cid, pos = pos, startpos = pos, spawnDelay = 10}
            addEvent(addSled, 100, params)
            setPlayerStorageValue(cid,9006,1)
        end
    end
end
XML:
<movevent event="StepIn" itemid="7266" script="sled.lua" />
Capture.PNG
 
Solution
bump any ideas?
Add some prints and find where it's failing.

example

Lua:
function onStepIn(cid, item, pos)
    print("1")
    if isPlayer(cid) == 1 then
        print("2")
        isMoving = getPlayerStorageValue(cid,9006)
        if item.itemid == 7266 and isMoving == -1 then
            print("3")
            params = {cid = cid, pos = pos, startpos = pos, spawnDelay = 10}
            addEvent(addSled, 100, params)
            setPlayerStorageValue(cid,9006,1)
        end
    end
end

Then when you walk on the tile, if it prints 1, 2, 3
you know it's failing somewhere in the addEvent

If it only prints 1, then the isPlayer(cid) == 1 is failing
bump any ideas?
Add some prints and find where it's failing.

example

Lua:
function onStepIn(cid, item, pos)
    print("1")
    if isPlayer(cid) == 1 then
        print("2")
        isMoving = getPlayerStorageValue(cid,9006)
        if item.itemid == 7266 and isMoving == -1 then
            print("3")
            params = {cid = cid, pos = pos, startpos = pos, spawnDelay = 10}
            addEvent(addSled, 100, params)
            setPlayerStorageValue(cid,9006,1)
        end
    end
end

Then when you walk on the tile, if it prints 1, 2, 3
you know it's failing somewhere in the addEvent

If it only prints 1, then the isPlayer(cid) == 1 is failing
 
Solution
Add some prints and find where it's failing.

example

Lua:
function onStepIn(cid, item, pos)
    print("1")
    if isPlayer(cid) == 1 then
        print("2")
        isMoving = getPlayerStorageValue(cid,9006)
        if item.itemid == 7266 and isMoving == -1 then
            print("3")
            params = {cid = cid, pos = pos, startpos = pos, spawnDelay = 10}
            addEvent(addSled, 100, params)
            setPlayerStorageValue(cid,9006,1)
        end
    end
end

Then when you walk on the tile, if it prints 1, 2, 3
you know it's failing somewhere in the addEvent

If it only prints 1, then the isPlayer(cid) == 1 is failing
Thank u it worked it printed 1 then I removed
Code:
isPlayer(cid) == 1
but I got an issue if someone logged out while u sledding it gives this error
Lua:
[Error - MoveEvents Interface]
In a timer event called from:
data/movements/scripts/sled.lua:onStepIn
Description:
(LuaInterface::luaDoCreatureSetStorage) Creature not found
and it creates this item when it reach the end I mean doesn't remove like others Capture.PNG
 
Thank u it worked it printed 1 then I removed
Code:
isPlayer(cid) == 1
but I got an issue if someone logged out while u sledding it gives this error
Lua:
[Error - MoveEvents Interface]
In a timer event called from:
data/movements/scripts/sled.lua:onStepIn
Description:
(LuaInterface::luaDoCreatureSetStorage) Creature not found
and it creates this item when it reach the end I mean doesn't remove like others View attachment 58104
The first issue, you just need to confirm if the player is still alive if isPlayer(cid) then before you use cid for any function. (storage or teleport)

2nd issue is a bit more complicated.
The script is using getThingfromPos which just finds the top most thing on the tile.
Your final tile might've have an additional sprite on it, aside from the dogsled.. and it probably removed that.
 
Back
Top