local storages = {
isMoving = 12550,
direction = 12551,
speed = 12552
}
function CarMoveLeft(x)
cpos = x.Cpos
Car = getThingfromPos(cpos)
newpos = {x=x.pos.x-1, y=x.pos.y, z=x.pos.z}
doCreateItem(3592,1,newpos)
doTeleportThing(x.cid, newpos)
doRemoveItem(Car.uid,1)
end
function CarMoveRight(x)
cpos = x.Cpos
Car = getThingfromPos(cpos)
newpos = {x=x.pos.x+1, y=x.pos.y, z=x.pos.z}
doCreateItem(3596,1,newpos)
doTeleportThing(x.cid, newpos)
doRemoveItem(Car.uid,1)
end
function CarMoveUp(x)
cpos = x.Cpos
Car = getThingfromPos(cpos)
newpos = {x=x.pos.x, y=x.pos.y-1, z=x.pos.z}
doCreateItem(3587,1,newpos)
doTeleportThing(x.cid, newpos)
doRemoveItem(Car.uid,1)
end
function CarMoveDown(x)
cpos = x.Cpos
Car = getThingfromPos(cpos)
newpos = {x=x.pos.x, y=x.pos.y+1, z=x.pos.z}
doCreateItem(3591,1,newpos)
doTeleportThing(x.cid, newpos)
doRemoveItem(Car.uid,1)
end
function onStepIn(cid, item, pos)
if isPlayer(cid) == 1 then
local status = {
isMoving = getPlayerStorageValue(cid, storages.isMoving),
direction = getPlayerStorageValue(cid, storages.direction),
speed = getPlayerStorageValue(cid, storages.speed)
}
if status.speed <= 0 then
setPlayerStorageValue(cid, storages.speed, 500)
status.speed = 800
elseif status.speed >= 2500 then
setPlayerStorageValue(cid, storages.speed, 500)
status.speed = 800
end
CarPos = getThingPos(item.uid)
if status.isMoving == 1 then
if status.direction == 1 then
CheckLeft = getThingfromPos({x = pos.x-1, y = pos.y, z = pos.z, stackpos = 1})
if isWall(CheckLeft.itemid) == 1 or isCreature(CheckLeft.uid) == 1 then
setPlayerStorageValue(cid, storages.direction, 2)
x = {cid = cid, pos = pos, Cpos = CarPos}
addEvent(CarMoveRight, status.speed, x)
else
x = {cid = cid, pos = pos, Cpos = CarPos}
addEvent(CarMoveLeft, status.speed, x)
end
elseif status.direction == 2 then
CheckRight = getThingfromPos({x = pos.x+1, y = pos.y, z = pos.z, stackpos = 1})
if isWall(CheckRight.itemid) == 1 or isCreature(CheckRight.uid) == 1 then
setPlayerStorageValue(cid, storages.direction, 1)
x = {cid = cid, pos = pos, Cpos = CarPos}
addEvent(CarMoveLeft, status.speed, x)
else
x = {cid = cid, pos = pos, Cpos = CarPos}
addEvent(CarMoveRight, status.speed, x)
end
elseif status.direction == 3 then
CheckUp = getThingfromPos({x = pos.x, y = pos.y-1, z = pos.z, stackpos = 1})
if isWall(CheckUp.itemid) == 1 or isCreature(CheckUp.uid) == 1 then
setPlayerStorageValue(cid, storages.direction, 4)
x = {cid = cid, pos = pos, Cpos = CarPos}
addEvent(CarMoveDown, status.speed, x)
else
x = {cid = cid, pos = pos, Cpos = CarPos}
addEvent(CarMoveUp, status.speed, x)
end
elseif status.direction == 4 then
CheckDown = getThingfromPos({x = pos.x, y = pos.y+1, z = pos.z, stackpos = 1})
if isWall(CheckDown.itemid) == 1 or isCreature(CheckDown.uid) == 1 then
setPlayerStorageValue(cid, storages.direction, 3)
x = {cid = cid, pos = pos, Cpos = CarPos}
addEvent(CarMoveUp, status.speed, x)
else
x = {cid = cid, pos = pos, Cpos = CarPos}
addEvent(CarMoveDown, status.speed, x)
end
end
elseif status.isMoving == -1 then
setPlayerStorageValue(cid, storages.isMoving, 1)
end
end
end