Ir para conteúdo

Canoa movel


Mudrock

Posts Recomendados

Bom para quem não sabe,este é um script que faz o character andar em conjunto com a canoa.(você pode configurar a rota)

[Testado em TFS 0.3.6 e TFS 0.2.14]

ieqwn7evTflfc.gif

Como criar :

  • Adicione a actionid 6901 no meio da canoa.

    Onde a canoa deve ir você coloca o itemid 4820.

    Você tem que usar as bordas com o mesmo ID que está nas configurações endborders.

     

    Como criar :

    Adicione a actionid 6901 no meio da canoa.

    Onde a canoa deve ir você coloca o itemid 4820.

    Você tem que usar as bordas com o mesmo ID que está nas configurações endborders.

     

    ZZwopm.png

     

    "data/actions/actions.xml" :

  • (TFS 0.3/0.4)

<action actionid="6901" event="script" value="other/movingboat.lua"/>

  • (TFS 0.2/1.0)
<action actionid="6901" script="other/movingboat.lua"/>
  • "data/actions/scripts/movingboat.lua" :
local config = {
   endborders = {4644, 4646},
   speed = 300,
   ignorefirstborders = 3
}

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
             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 and n
                 end
             end
         end
     end
end

local function doTravel(cid, poss, last)

     getRightPos(poss, last)
     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
         p = poss
     end
     if(travel == "false") then
        if(getCreatureCondition(cid, CONDITION_INFIGHT)) then
             doRemoveCondition(cid, CONDITION_INFIGHT)
         end
         n = 0
         s = 0
         return false
     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(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
  • "data/movements/movements.xml" :

(TFS 0.3/0.4)

<movevent type="StepIn" itemid="4820" event="script" value="water.lua"/>
  • (TFS 0.2/1.0)
<movevent event="StepIn" itemid="4820" script="water.lua"/>
  • "data/movements/scripts/water.lua" :
local boatids = {3589, 3594}

function onStepIn(cid, item, position, fromPosition)

for _, id in pairs(boatids) do
if(getTileItemById(fromPosition, id).uid > 0) then
return doTeleportThing(cid, fromPosition)
end
end
return true
end
  • Se você usa TFS 0.3/0.4, adicione isto em "data/lib/050-function.lua" (se você ja não tiver).
function doSetItemActionId(uid, actionid)
return doItemSetAttribute(uid, "aid", actionid)
end

Créditos

Limos

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...