- YerenixAportador
- Mensajes : 98
Car System para su Ot
Sáb Sep 24, 2011 6:51 pm
Primero vamos a data/movements/scripts creamos un archivo.lua nombre: car.lua
y Esto a Dentro
Esto en Movements.xml
Ahora talkactions/scripts crean otro:
"car.lua" y esto adentro
y Esto en Talkations.xml
Aki les dejo un Videito para ver como funciona
y Esto a Dentro
- Código:
local storages = {isMoving = 12550, direction = 12551, speed = 12552}
local SpeedMeter = {Default = 800, Max = 0, Min = 2500}
function tileChecker(pos, type_)
local myTable = {}
if (type(pos) == 'table') then
for i = 1, 5 do
pos.stackpos = i
local Thing = getThingFromPos(pos)
local thisID, thisUID = Thing.itemid, Thing.uid
if thisID > 1 then
if type_ == "itemID" then
table.insert(myTable, thisID)
elseif type_ == "itemUID" then
table.insert(myTable, thisUID)
end
end
end
end
return #myTable > 0 and myTable or nil
end
local function findItem(pos, t)
if (type(pos) == 'table' and type(t) == 'table') then
for _i, i in ipairs(tileChecker(pos, "itemID")) do
if isInArray(t, i) then
pos.stackpos = _i
ret = getThingFromPos(pos).uid
break
end
end
end
return ret
end
function moveCar(x)
if x.Dir ~= -1 then
doCreateItem(isInArray({1, 2}, x.Dir) == TRUE and 7267 or 7266, 1, x.nPos)
doTeleportThing(x.cid, x.nPos, FALSE)
doRemoveItem(findItem(x.pos, {7266, 7267}))
end
end
function onStepIn(cid, item, position, fromPosition)
if isPlayer(cid) == TRUE then
local status =
{
isMoving = getPlayerStorageValue(cid, storages.isMoving),
direction = getPlayerStorageValue(cid, storages.direction),
speed = getPlayerStorageValue(cid, storages.speed)
}
if status.speed <= SpeedMeter.Max then
setPlayerStorageValue(cid, storages.speed, SpeedMeter.Default)
status.speed = SpeedMeter.Default
elseif status.speed >= SpeedMeter.Min then
setPlayerStorageValue(cid, storages.speed, SpeedMeter.Default)
status.speed = SpeedMeter.Default
end
if status.isMoving == 1 then
local Movements =
{
[1] = {x = position.x - 1, y = position.y, z = position.z},
[2] = {x = position.x + 1, y = position.y, z = position.z},
[3] = {x = position.x, y = position.y - 1, z = position.z},
[4] = {x = position.x, y = position.y + 1, z = position.z}
}
if not Movements[status.direction] then setPlayerStorageValue(cid, status.direction, 1) end
local Stor = status.direction
local newPos = Movements[Stor]
local Check = tileChecker(newPos, "itemUID")
if Check ~= nil then
for _, i in ipairs(Check) do
if (hasProperty(i, CONST_PROP_BLOCKSOLID) == TRUE or isCreature(i) or getTilePzInfo(newPos)) then
Stor = isInArray({1, 2}, Stor) == TRUE and (Stor == 1 and 2 or 1) or isInArray({3, 4}, Stor) and (Stor == 3 and 4 or 3) or nil
newPos = Movements[Stor]
setPlayerStorageValue(cid, storages.direction, Stor)
break
end
end
end
addEvent(moveCar, status.speed, {cid = cid, pos = position, nPos = newPos, Dir = Stor})
elseif status.isMoving == -1 then
setPlayerStorageValue(cid, storages.isMoving, 1)
end
end
return TRUE
end
Esto en Movements.xml
- Código:
<movevent type="StepIn" itemid="7266" event="script" value="car.lua"/>
<movevent type="StepIn" itemid="7267" event="script" value="car.lua"/>
Ahora talkactions/scripts crean otro:
"car.lua" y esto adentro
- Código:
local storages = {isMoving = 12550, direction = 12551, speed = 12552}
function onSay(cid, words, param)
local status =
{
isMoving = getPlayerStorageValue(cid, storages.isMoving),
direction = getPlayerStorageValue(cid, storages.direction),
speed = getPlayerStorageValue(cid, storages.speed)
}
local controls =
{
["up"] = {storage = storages.direction, new = 3, txt = "up"},
["down"] = {storage = storages.direction, new = 4, txt = "down"},
["left"] = {storage = storages.direction, new = 1, txt = "left"},
["right"] = {storage = storages.direction, new = 2, txt = "right"},
["speedup"] = {storage = storages.speed, new = status.speed - 50, txt = "fast"},
["speeddown"] = {storage = storages.speed, new = status.speed + 50, txt = "slow"},
["stop"] = {storage = storages.direction, new = -1, txt = "stop"}
}
if status.isMoving == 1 then
local ctrl = controls[param]
if ctrl then
setPlayerStorageValue(cid, ctrl.storage, ctrl.new)
doCreatureSay(cid, ctrl.txt, TALKTYPE_SAY)
else
doSendMagicEffect(getPlayerPosition(cid), 2)
doPlayerSendCancel(cid, "Invalid operation.")
end
else
doPlayerSendCancel(cid, "You are not in a car.")
end
return TRUE
end
y Esto en Talkations.xml
- Código:
<talkaction words="car" script="car.lua"/>
Aki les dejo un Videito para ver como funciona
Permisos de este foro:
No puedes responder a temas en este foro.