• 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.

pick opens path

Capaverde

New Member
Joined
Sep 30, 2007
Messages
107
Reaction score
4
Code:
local direc = {{0,-1},{1,0},{0,1},{-1,0},{-1,-1},{1,-1},{1,1},{-1,1}}

local CAVEBORDERS = {[0]=357,358,356,359,362,363,360,361,364,365,367,366}

local sltodir = {[356]=0,[358]=3,[359]=1,[357]=2}



function seilah(dir1,dir2)	--takes <=3, returns >=8
dir1,dir2 = math.min(dir1,dir2),math.max(dir1,dir2)
if dir1 == 0 and dir2 == 3 then
return 11
elseif dir1 == 0 and dir2 == 1 then
return 10
elseif dir1 == 1 and dir2 == 2 then
return 8
elseif dir1 == 2 and dir2 == 3 then
return 9
end
return false
end

function seilah2(dir1,dir2)	--takes >=4, returns <=3
dir1,dir2 = math.min(dir1,dir2),math.max(dir1,dir2)
if dir1 == 4 and dir2 == 5 then
return 0
elseif dir1 == 5 and dir2 == 6 then
return 1
elseif dir1 == 6 and dir2 == 7 then
return 2
elseif dir1 == 4 and dir2 == 7 then
return 3
end
return false
end

--[[function getlimits(dir)
local lx,ux,ly,uy
local delta = direc[dir+1]
if delta[1] == 0 then
	lx=-1
	ux=1
else
	lx = math.min(0,delta[1])
	ux=lx+1
end
if delta[2] == 0 then
	ly=-1
	uy=1
else
	ly = math.min(0,delta[2])
	uy=ly+1
end
return lx,ux,ly,uy
end]]

function checktile(item,pos)
local MYINDEX
local themgrounds1 = {}
local themgrounds2 = {}
for dir=0,7 do
local px = pos.x+direc[dir+1][1]
local py = pos.y+direc[dir+1][2]
local item3 = getThingfromPos({x=px,y=py,z=pos.z})
if item3.itemid == 351 or item3.itemid == 384 then
if dir>=4 then
	table.insert(themgrounds2,{dir=dir})
else
	table.insert(themgrounds1,{dir=dir})
end
end
end
if #themgrounds1 == 0 then if #themgrounds2 == 0 then return elseif #themgrounds2 == 1 then MYINDEX = themgrounds2[1].dir else MYINDEX = seilah2(themgrounds2[1].dir,themgrounds2[2].dir) end
elseif #themgrounds1 == 1 then MYINDEX = themgrounds1[1].dir
elseif #themgrounds1 == 2 then MYINDEX = seilah(themgrounds1[1].dir,themgrounds1[2].dir)
else doTransformItem(item.uid,351) return
end
if MYINDEX then
doTransformItem(item.uid,CAVEBORDERS[MYINDEX])
elseif MYINDEX == false then
doTransformItem(item.uid,351)
end
end

function getdirlist(dir)
return {(dir+1)%4,(dir+3)%4,(dir+1)%4+4,dir,dir+4}
end

function onUse(cid, item, frompos, item2, topos)
local oi = sltodir[item2.itemid]
if oi then
doTransformItem(item2.uid,351)
--local lx,ux,ly,uy = getlimits(oi)
local dirlist = getdirlist(oi)
for k,v in ipairs(dirlist) do
dx = direc[v+1][1]
dy = direc[v+1][2]
local pos = {x=topos.x+dx,y=topos.y+dy,z=topos.z}
local item0 = getThingfromPos(pos)
		checktile(item0,pos)
end
end
end

Code:
<action itemid="2553" script="pick.lua"  />


29425439.jpg
 
Last edited:
I tried tabbing it a bit. Also, Capaverde, fucking pro script. Nice work man ;)

Lua:
local direc = {{0, -1},{1, 0},{0, 1},{-1, 0},{-1, -1},{1, -1},{1, 1},{-1, 1}}
local CAVEBORDERS = {[0] = 357, 358, 356, 359, 362, 363, 360, 361, 364, 365, 367, 366}
local sltodir = {[356] = 0,[358] = 3,[359] = 1,[357] = 2}

function seilah(dir1, dir2)	-- takes <=3, returns >=8
	dir1,dir2 = math.min(dir1,dir2),math.max(dir1,dir2)
	if dir1 == 0 and dir2 == 3 then
		return 11
	elseif dir1 == 0 and dir2 == 1 then
		return 10
	elseif dir1 == 1 and dir2 == 2 then
		return 8
	elseif dir1 == 2 and dir2 == 3 then
		return 9
	end
	return false
end

function seilah2(dir1, dir2)	-- takes >=4, returns <=3
	dir1, dir2 = math.min(dir1,dir2), math.max(dir1,dir2)
	if dir1 == 4 and dir2 == 5 then
		return 0
	elseif dir1 == 5 and dir2 == 6 then
		return 1
	elseif dir1 == 6 and dir2 == 7 then
		return 2
	elseif dir1 == 4 and dir2 == 7 then
		return 3
	end
	return false
end

--[[
function getlimits(dir)
	local lx, ux, ly, uy
	local delta = direc[dir+1]
	if delta[1] == 0 then
		lx = -1
		ux = 1
	else
		lx = math.min(0, delta[1])
		ux = lx + 1
	end
	if delta[2] == 0 then
		ly = -1
		uy = 1
	else
		ly = math.min(0, delta[2])
		uy = ly +1
	end
	return lx, ux, ly, uy
end
]]--

function checktile(item,pos)
	local MYINDEX
	local themgrounds1 = {}
	local themgrounds2 = {}
	for dir=0, 7 do
	local px = pos.x + direc[dir+1][1]
	local py = pos.y + direc[dir+1][2]
	local item3 = getThingfromPos({x = px, y = py, z = pos.z})
	if item3.itemid == 351 or item3.itemid == 384 then
		if dir>=4 then
			table.insert(themgrounds2, {dir = dir})
		else
			table.insert(themgrounds1, {dir = dir})
		end
	end
end

	if #themgrounds1 == 0 then if #themgrounds2 == 0 then return elseif #themgrounds2 == 1 then MYINDEX = themgrounds2[1].dir else MYINDEX = seilah2(themgrounds2[1].dir, themgrounds2[2].dir) end
		elseif #themgrounds1 == 1 then MYINDEX = themgrounds1[1].dir
		elseif #themgrounds1 == 2 then MYINDEX = seilah(themgrounds1[1].dir,themgrounds1[2].dir)
		else doTransformItem(item.uid,351) return
	end
	if MYINDEX then
		doTransformItem(item.uid,CAVEBORDERS[MYINDEX])
	elseif MYINDEX == false then
		doTransformItem(item.uid,351)
	end
end

function getdirlist(dir)
	return {(dir+1)%4,(dir+3)%4,(dir+1)%4+4,dir,dir+4}
end

function onUse(cid, item, frompos, item2, topos)
	local oi = sltodir[item2.itemid]
	if oi then
		doTransformItem(item2.uid,351)
		--local lx,ux,ly,uy = getlimits(oi)
		local dirlist = getdirlist(oi)
		for k,v in ipairs(dirlist) do
			dx = direc[v+1][1]
			dy = direc[v+1][2]
			local pos = {x=topos.x+dx, y=topos.y+dy, z=topos.z}
			local item0 = getThingfromPos(pos)
			checktile(item0, pos)
		end
	end
end

Red
 
Back
Top