• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

MoveEvent Updated Car System

Jano

oturhaN
Joined
Feb 21, 2008
Messages
876
Solutions
1
Reaction score
68
Location
Chile
reScripted and tested using latest TFS (0.3.4)

movemenst / scripts

car.lua

Lua:
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

movements.xml


PHP:
<movevent type="StepIn" itemid="7266" event="script" value="car.lua"/>
<movevent type="StepIn" itemid="7267" event="script" value="car.lua"/>

talkactions / scripts

car.lua

Lua:
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

talkactions.xml

PHP:
<talkaction words="car" script="car.lua"/>
 
thanks for this script, good job, nice release.
 
cant u make one without talking? please..

im just searching for this one,..
 
this release made my laugh !! LMAO! I will add this to my fun-high exped ot for usre :D tytyty
 
This is a great script and is fun to play with so thanks a lot for the release, On a side note a bit of a bug I have with it. If you try to walk around while driving the car it will dupe it and make a big mess etc. Any chance on that getting fixed up? I'll probably fix my own but for the release I would not wanna mess with your work. Thanks again and rep for ya.
 
Back
Top