Ir para conteúdo
Entre para seguir isso  
tigerx2

Dirigir carro

Recommended Posts

tigerx2    1
tigerx2
Nome: Dirigir carro

Autor: Doggynub // otland

Versão Testada: tfs 0.4 & 0.3.6

Informações Adicionais: o script fala por si mesmo.

[spoiler=Bug fixed]
Tirei o bug (eu, tigerx2) de que quando parava o carro com o comando !car stop o player nao podia se mover.

 

 

Como dirigir:

Pressione CTRL + seta (cima, baixo, esquerda e direita)
Comandos:
!car move : sumona o carro e inicia-se a movimentar com a velocidade padrão

!car speed : acelera o carro

!car slow : desacelera o carro

!car stop : para o carro

[TFS 0.4] Em talkactions/scripts crie um arquivo .lua chamado car e coloque isto dentro:

 
--<< Configurable >>--
local storages = { speed = 314622, status = 352993 } -- Empty storages

local cfg = {    min_speed = 400,                          -- better not increase than that [ the least speed for a car ]
                   max_speed = 50,                            -- better not decrease than this [ the maximum speed for a car ]
                   Increase_per_command = 60,                 -- The speed increase or decrease value per each command (!car speed // !car slow)
                   Car_Explode = true -- Keep it true , so your map isnt filled with cars
               }
-->> END <<--

--<< Functions >>--

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 getCarSpeed(cid) return getPlayerStorageValue(cid,storages.speed) end
function setCarSpeed(cid,value) return setPlayerStorageValue(cid,storages.speed, getPlayerStorageValue(cid,storages.speed) + value) end
function setCarStatus(cid,value) return setPlayerStorageValue(cid,storages.status,value) end
function carMove(cid) return getPlayerStorageValue(cid,storages.status) > 0 and true or false end

function move(cid,time)
   local dir = getCreatureLookDir(cid)
   local id = isInArray({1,3},getCreatureLookDir(cid)) and 7267 or 7266
   local place = getPositionByDirection(getThingPos(cid),dir,1)
   if isWalkable(place,true,true,true) then
       doRemoveItem( getTileItemById(getThingPos(cid),7267).uid > 0 and getTileItemById(getThingPos(cid),7267).uid or getTileItemById(getThingPos(cid),7266).uid )
       doTeleportThing(cid,place,false)
       addEvent(doSendMagicEffect,time+10,place,34)
       doCreateItem(id,1,place)
       if carMove(cid) then
           addEvent(move,time,cid,getCarSpeed(cid))
       else
           doRemoveCondition(cid,CONDITION_INFIGHT)
           doRemoveItem( getTileItemById(getThingPos(cid),7267).uid > 0 and getTileItemById(getThingPos(cid),7267).uid or getTileItemById(getThingPos(cid),7266).uid )
       end
   else
       doCreatureSetNoMove(cid, 0)
       doPlayerSendTextMessage(cid,27,"You have hit somthng.")
       setCarStatus(cid,0)
       doRemoveCondition(cid,CONDITION_INFIGHT)
       if cfg.Car_Explode then
           doRemoveItem( getTileItemById(getThingPos(cid),7267).uid > 0 and getTileItemById(getThingPos(cid),7267).uid or getTileItemById(getThingPos(cid),7266).uid )
           doSendAnimatedText(getThingPos(cid),"Crashed",TEXTCOLOR_RED)
           doSendMagicEffect(getThingPos(cid),31)
       end
   end
end

--<< Functions Ends <<--

local fight = createConditionObject(CONDITION_INFIGHT,-1)
function onSay(cid, words, param, channel)
   if param == "speed" then
       if carMove(cid) then
           if getCarSpeed(cid) > cfg.max_speed then
               setCarSpeed(cid,-(cfg.Increase_per_command))
               addEvent(doSendAnimatedText,10,getThingPos(cid),"Speeding",TEXTCOLOR_GREEN)
           else
               setCarSpeed(cid,cfg.max_speed)
               doPlayerSendCancel(cid,"The car is in its maximum speed.")
           end
       else
           doPlayerSendCancel(cid,"You should start moving first.")
       end
   elseif param == "slow" then
       if carMove(cid) then
           if getCarSpeed(cid) < cfg.min_speed then
               setCarSpeed(cid,cfg.Increase_per_command)
               addEvent(doSendAnimatedText,10,getThingPos(cid),"Slowing",TEXTCOLOR_GREEN)
           else
               setCarSpeed(cid,cfg.min_speed)
               doPlayerSendCancel(cid,"The car is in its minumium speed.")
           end
       else
           doPlayerSendCancel(cid,"You should start moving first.")
       end
   elseif param == "stop" then
       if carMove(cid) then
                       doCreatureSetNoMove(cid, 0)
           setCarStatus(cid,0)
           doSendAnimatedText(getThingPos(cid),"Stopped!",TEXTCOLOR_RED)

       else
           doPlayerSendCancel(cid,"Car is already stopped.")
       end
   elseif param == "move" then
           if not carMove(cid) then
               if getTileItemById(getThingPos(cid),7267).uid < 1 and  getTileItemById(getThingPos(cid),7266).uid < 1 then 
                   local item = isInArray({1,3},getCreatureLookDir(cid)) and 7267 or 7266
                   doCreateItem(item,1,getThingPos(cid))
               end
               setPlayerStorageValue(cid,storages.speed,cfg.min_speed)
               setCarStatus(cid,1)
               doCreatureSetNoMove(cid, 1)
               move(cid,getCarSpeed(cid))
               doAddCondition(cid,fight)
           else
               doPlayerSendCancel(cid,"Car is already moving.")
           end
   end

   return true
end

 

Em talkactions.xml adicione esta tag:

<talkaction words="!car" event="script" value="car.lua"/>

 

[spoiler=TFS 0.3.6][TFS 0.3.6]

--<< Configurable >>--
local storages = { speed = 314622, status = 352993 } -- Empty storages

local cfg = {    min_speed = 400,                          -- better not increase than that [ the least speed for a car ]
                   max_speed = 50,                            -- better not decrease than this [ the maximum speed for a car ]
                   Increase_per_command = 60,                 -- The speed increase or decrease value per each command (!car speed // !car slow)
                   Car_Explode = true -- Keep it true , so your map isnt filled with cars
               }
-->> END <<--

--<< Functions >>--

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 getCarSpeed(cid) return getPlayerStorageValue(cid,storages.speed) end
function setCarSpeed(cid,value) return setPlayerStorageValue(cid,storages.speed, getPlayerStorageValue(cid,storages.speed) + value) end
function setCarStatus(cid,value) return setPlayerStorageValue(cid,storages.status,value) end
function carMove(cid) return getPlayerStorageValue(cid,storages.status) > 0 and true or false end

function move(cid,time)
   local dir = getCreatureLookDir(cid)
   local id = isInArray({1,3},getCreatureLookDir(cid)) and 7267 or 7266
   local place = getPosByDir(getThingPos(cid),dir,1)
   if isWalkable(place,true,true,true) then
       doRemoveItem( getTileItemById(getThingPos(cid),7267).uid > 0 and getTileItemById(getThingPos(cid),7267).uid or getTileItemById(getThingPos(cid),7266).uid )
       doTeleportThing(cid,place,false)
       addEvent(doSendMagicEffect,time+10,place,34)
       doCreateItem(id,1,place)
       if carMove(cid) then
           addEvent(move,time,cid,getCarSpeed(cid))
       else
           doRemoveCondition(cid,CONDITION_INFIGHT)
           doRemoveItem( getTileItemById(getThingPos(cid),7267).uid > 0 and getTileItemById(getThingPos(cid),7267).uid or getTileItemById(getThingPos(cid),7266).uid )
       end
   else
       doCreatureSetNoMove(cid, 0)
       doPlayerSendTextMessage(cid,27,"You have hit somthng.")
       setCarStatus(cid,0)
       doRemoveCondition(cid,CONDITION_INFIGHT)
       if cfg.Car_Explode then
           doRemoveItem( getTileItemById(getThingPos(cid),7267).uid > 0 and getTileItemById(getThingPos(cid),7267).uid or getTileItemById(getThingPos(cid),7266).uid )
           doSendAnimatedText(getThingPos(cid),"Crashed",TEXTCOLOR_RED)
           doSendMagicEffect(getThingPos(cid),31)
       end
   end
end

--<< Functions Ends <<--

local fight = createConditionObject(CONDITION_INFIGHT,-1)
function onSay(cid, words, param, channel)
   if param == "speed" then
       if carMove(cid) then
           if getCarSpeed(cid) > cfg.max_speed then
               setCarSpeed(cid,-(cfg.Increase_per_command))
               addEvent(doSendAnimatedText,10,getThingPos(cid),"Speeding",TEXTCOLOR_GREEN)
           else
               setCarSpeed(cid,cfg.max_speed)
               doPlayerSendCancel(cid,"The car is in its maximum speed.")
           end
       else
           doPlayerSendCancel(cid,"You should start moving first.")
       end
   elseif param == "slow" then
       if carMove(cid) then
           if getCarSpeed(cid) < cfg.min_speed then
               setCarSpeed(cid,cfg.Increase_per_command)
               addEvent(doSendAnimatedText,10,getThingPos(cid),"Slowing",TEXTCOLOR_GREEN)
           else
               setCarSpeed(cid,cfg.min_speed)
               doPlayerSendCancel(cid,"The car is in its minumium speed.")
           end
       else
           doPlayerSendCancel(cid,"You should start moving first.")
       end
   elseif param == "stop" then
       if carMove(cid) then
           setCarStatus(cid,0)
                       doCreatureSetNoMove(cid, 0)
   doSendAnimatedText(getThingPos(cid),"Stopped!",TEXTCOLOR_RED)

       else
           doPlayerSendCancel(cid,"Car is already stopped.")
       end
   elseif param == "move" then
           if not carMove(cid) then
               if getTileItemById(getThingPos(cid),7267).uid < 1 and  getTileItemById(getThingPos(cid),7266).uid < 1 then 
                   local item = isInArray({1,3},getCreatureLookDir(cid)) and 7267 or 7266
                   doCreateItem(item,1,getThingPos(cid))
               end
               setPlayerStorageValue(cid,storages.speed,cfg.min_speed)
               setCarStatus(cid,1)
               doCreatureSetNoMove(cid, 1)
               move(cid,getCarSpeed(cid))
               doAddCondition(cid,fight)
           else
               doPlayerSendCancel(cid,"Car is already moving.")
           end
   end

   return true
end

 

 

Bug do forum: esta separando algumas palavras, entao ao rodar no console vai aparecer uns erros de sintaxe.

Editado por Black Ice

Compartilhar este post


Link para o post
Lwkass    1
Lwkass

o script é ótimo, eu até colocaria exclusivo se fosse feito por você,

 

Aprovado

Compartilhar este post


Link para o post
tigerx2    1
tigerx2

@up

Valeu por aprovar.

Cara, eu pensei jutamente nisso.

Achei o script tão foda que postei aqui pra galera :D

Compartilhar este post


Link para o post
SkyFail    0
SkyFail

parece com um d navio q eu fiz pra One Piece D:

Compartilhar este post


Link para o post
tigerx2    1
tigerx2

@up

Que massa ta fazendo ats de one piece ?

adoro o anime :D

sepah tamo ai no script xD

 

@offup

seu avatar eh massa :D

Compartilhar este post


Link para o post
evalan    0
evalan

aki nao foi sera que meu ot e 8.6??

Compartilhar este post


Link para o post
SkyFail    0
SkyFail

@off

vlw tiger XD

qem fez foi o cara la da lojinha :D

Compartilhar este post


Link para o post
leolui    0
leolui

[13/01/2011 13:05:51] [Error - TalkAction Interface]

[13/01/2011 13:05:51] data/talkactions/scripts/carro.lua:onSay

[13/01/2011 13:05:51] Description:

[13/01/2011 13:05:51] data/talkactions/scripts/carro.lua:38: attempt to call global 'getPositionByDirection' (a nil value)

[13/01/2011 13:05:51] stack traceback:

[13/01/2011 13:05:51] data/talkactions/scripts/carro.lua:38: in function 'move'

[13/01/2011 13:05:51] data/talkactions/scripts/carro.lua:109: in function <data/talkactions/scripts/carro.lua:66>

Editado por leolui

Compartilhar este post


Link para o post
manchinhaot    0
manchinhaot

Obg vou testar depois para por no update do meu servidor... estava pensando em fazer uma corrida na neve :D

Compartilhar este post


Link para o post
Slashers    0
Slashers

Bom script gostei demais

e bom para fazer eventos de corrida pra animar um server :D

Compartilhar este post


Link para o post
VittinhoO    0
VittinhoO

AUHSAUHS bem doido mais é irado!

Compartilhar este post


Link para o post
tigerx2    1
tigerx2

@leolui

Qual distro usada?

Compartilhar este post


Link para o post
XxjhonatanxX    0
XxjhonatanxX

Vlws msm Cara muito legal to fazendo evento de corrida aki asduasuduasuda

Compartilhar este post


Link para o post
Ithash151    0
Ithash151

posta um video queria ver, o meu n serve é alissow Ots 3.6 será q funfa?

Compartilhar este post


Link para o post
tigerx2    1
tigerx2

@up

Teste pra ver como eh e se funciona :)

Compartilhar este post


Link para o post
Billy Spoke    0
Billy Spoke

Muito bem criativo, estarei utilizando num servidor meu privado (apenas para convidados e amigos) que nele tem coisas que não se acha em OTserve high exp.

Compartilhar este post


Link para o post
Yutotay    0
Yutotay

Cara vlww msmo

vou fazer ums eventos dahora qui =D

Parabens pelo seu trabalho!!!

Compartilhar este post


Link para o post
Blackskull    0
Blackskull

muito bom, ja vi script parecidos mais para dirigir tinha que falar !car norte !car south ai era foda. parabens

Compartilhar este post


Link para o post
dj-toledo    0
dj-toledo

Entao cara, fico bom, mas quando o carro bate em algo, o player toma debug... Tem como implementa alguma coisa ai no script pra quando o carro bater, ele der car stop, n der debug :s

Compartilhar este post


Link para o post
viniciusadm    0
viniciusadm

tigerx2 aki em casa aparece esse erro, e o carro não anda pra nenhum lugar ='(

 

[16/11/2012 09:06:27] Lua Script Error: [TalkAction Interface]

[16/11/2012 09:06:27] data/talkactions/scripts/car.lua:onSay

 

 

[16/11/2012 09:06:27] data/talkactions/scripts/car.lua:39: attempt to call global 'getPositionByDirection' (a nil value)

[16/11/2012 09:06:27] stack traceback:

[16/11/2012 09:06:27] data/talkactions/scripts/car.lua:39: in function 'move'

[16/11/2012 09:06:27] data/talkactions/scripts/car.lua:110: in function <data/talkactions/scripts/car.lua:67>

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×