• 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 Moving Boat Small edit, Pictures Attached

Saints Anathema

Old School Doleran
Joined
Feb 24, 2009
Messages
653
Reaction score
8
Location
BC,Canada
Hello, fiirst off credit to Limos amazing script
Action - Moving Boat


I was hoping i could get this to go down a waterfall, or -1 floor, we attempted it hoping it would just naturally go down, obviously didnt but we hoped!

6zaser12n


Any suggestions or attempts are greatly appreciated

Thanks again Limos, amazing script.
 
Solution
I'm don't use Lua very much so I'm sure someone else can probably do this cleaner, but I made some modifications and it seems to work.

Lua:
-- Moving Boat by Limos
local config = {
   endborders = {4644, 4646},
   speed = 300,
   ignorefirstborders = 1

}
local fight = createConditionObject(CONDITION_INFIGHT)
setConditionParam(fight, CONDITION_PARAM_TICKS, -1)
local function comparePos(poss, pos)
     return pos.x == poss.x and pos.y == poss.y
end
local n, s = 0, 0
local function getRightPos(poss, last)
     ps = {
         {x = poss.x, y = poss.y - 1, z = poss.z},
         {x = poss.x + 1, y = poss.y, z = poss.z},
         {x = poss.x, y = poss.y + 1, z = poss.z},
         {x = poss.x - 1, y = poss.y, z = poss.z}
     }

     for _...
Limos (original thread)
the waterfall part, same as it looks for ids of the water and borders ids, you can make it check if it finds an invisible stair hole, then change the pos to 1 floor lower so it continues down.

so we added itemid 459 the invisible hole at the first tile
 
I'm don't use Lua very much so I'm sure someone else can probably do this cleaner, but I made some modifications and it seems to work.

Lua:
-- Moving Boat by Limos
local config = {
   endborders = {4644, 4646},
   speed = 300,
   ignorefirstborders = 1

}
local fight = createConditionObject(CONDITION_INFIGHT)
setConditionParam(fight, CONDITION_PARAM_TICKS, -1)
local function comparePos(poss, pos)
     return pos.x == poss.x and pos.y == poss.y
end
local n, s = 0, 0
local function getRightPos(poss, last)
     ps = {
         {x = poss.x, y = poss.y - 1, z = poss.z},
         {x = poss.x + 1, y = poss.y, z = poss.z},
         {x = poss.x, y = poss.y + 1, z = poss.z},
         {x = poss.x - 1, y = poss.y, z = poss.z}
     }

     for _, pos in pairs(ps) do
         if getTileItemById(pos, 4820).uid > 0 then
             if not comparePos(last, pos) then
                 p = pos
                 return p
             end
         else
             if getTileItemById(pos, 3571).uid > 0 then
                print("I see the waterfall")
                p = {x = poss.x, y = poss.y + 1, z = poss.z + 1}
                return p
             end

             for b = 1, #config.endborders do
                 if getTileItemById(pos, config.endborders[b]).uid > 0 and s > config.ignorefirstborders then
                     n = n + 1
                     p = pos
                     return p
                 end
             end
         end
     end
end
local function doTravel(cid, poss, last)
     getRightPos(poss, last)

     if p.z > poss.z then
        print(p.z .. " :: " .. poss.z)
     end

     travel = p.x > poss.x and "east" or (p.y < poss.y and "north" or (p.y > poss.y and "south" or (p.x < poss.x and "west" or "false")))

     if n > 1 then
        print("N = " .. n)
         p = poss
     end

     if travel == "false" then
        if getCreatureCondition(cid, CONDITION_INFIGHT) then
             doRemoveCondition(cid, CONDITION_INFIGHT)
         end
         n = 0
         s = 0

         print("Travel was false")
         return false
     else
        if p.z > poss.z then
            print("Travel :" .. travel)
        end
     end
     local des = {
         ["north"] = {cPos = {{x = p.x, y = p.y - 1, z = p.z}, p, {x = p.x, y = p.y + 1, z = p.z}}, dir = 0, boat = {3587, 3589, 3591}},
         ["east"] = {cPos = {{x = p.x + 1, y = p.y, z = p.z}, p, {x = p.x - 1, y = p.y, z = p.z}}, dir = 1, boat = {3596, 3594, 3592}},
         ["south"] = {cPos = {{x = p.x, y = p.y + 1, z = p.z}, p, {x = p.x, y = p.y - 1, z = p.z}}, dir = 2, boat = {3591, 3589, 3587}},
         ["west"] = {cPos = {{x = p.x - 1, y = p.y, z = p.z}, p, {x = p.x + 1, y = p.y, z = p.z}}, dir = 3, boat = {3592, 3594, 3596}}
     }

     local x = des[travel]

     if not x then
        print("X not set.")
     end

     if p.z > poss.z and (travel == "south") then
        print("Going down the waterfall!")

        --x = last
        for x = p.x - 2, p.x + 2 do
             for y = p.y - 2, p.y + 2 do
                 pos = {x = x, y = y, z = p.z - 1}
                 for id = 3587, 3596 do
                     if getTileItemById(pos, id).uid > 0 then
                         print("Removing item id " .. id .. " in :" .. pos.x .. "," .. pos.y .. "," .. pos.z)
                         doRemoveItem(getTileItemById(pos, id).uid, 1)
                     else
                        --print("Item " .. id .. " not found in :" .. pos.x .. "," .. pos.y .. "," .. pos.z)
                     end
                 end
             end
         end

        newLocation = {
            cPos = {
                {x = x.cPos[1].x, y = x.cPos[1].y + 2, z = x.cPos[1].z },
                {x = x.cPos[2].x, y = x.cPos[2].y + 2, z = x.cPos[2].z },
                {x = x.cPos[3].x, y = x.cPos[3].y + 2, z = x.cPos[3].z }
            },
            dir = 2,
            boat = {3591, 3589, 3587}
        }
        doTeleportThing(cid, newLocation.cPos[2], false)
        doCreatureSetLookDir(newLocation.dir)
        doCreateItem(newLocation.boat[1], 1, newLocation.cPos[1])
        its = doCreateItem(newLocation.boat[2], 1, newLocation.cPos[2])
        if n > 0 then
            doSetItemActionId(its, 6901)
        end
        doCreateItem(newLocation.boat[3], 1, newLocation.cPos[3])

        return addEvent(doTravel, config.speed, cid, p, poss)
     else
        print("Moving")
     end

     if x then
         for x = p.x - 2, p.x + 2 do
             for y = p.y - 2, p.y + 2 do
                 pos = {x = x, y = y, z = p.z}
                 for id = 3587, 3596 do
                     if getTileItemById(pos, id).uid > 0 then
                         doRemoveItem(getTileItemById(pos, id).uid, 1)
                     end
                 end
             end
         end
         for c = 1, #x.boat do
             its = doCreateItem(x.boat[c], 1, x.cPos[c])
             if n > 0 and c == 2 then
                 doSetItemActionId(its, 6901)
             end
         end
         doTeleportThing(cid, x.cPos[2], false)
         doCreatureSetLookDir(cid, x.dir)
         if n > 1 then
             if getCreatureCondition(cid, CONDITION_INFIGHT) then
                 doRemoveCondition(cid, CONDITION_INFIGHT)
             end
             n = 0
             s = 0
             return false
         end
         s = s + 1
     end
     return addEvent(doTravel, config.speed, cid, p, poss)
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
     if getCreatureCondition(cid, CONDITION_INFIGHT) then
         return doPlayerSendCancel(cid, "You can't travel when you're in a fight.")
     end
     doTeleportThing(cid, toPosition)
     doAddCondition(cid, fight)
     doTravel(cid, getPlayerPosition(cid), getPlayerPosition(cid))
     return true
end
 
Solution
Back
Top