Someone requested it here
http://otland.net/f48/lua-help-puzzle-system-not-pillow-puzzle-158515/#post1563110
Now you have to define all in movements, give tile special actionId that triggers this code etc I hope you can do that. In case you dont:
I there are errors try to understand this code and fix that. Now usage:
http://otland.net/f48/lua-help-puzzle-system-not-pillow-puzzle-158515/#post1563110
Lua:
PuzzleBoard = {}
function PuzzleBoard:new(startPos)
local obj = {}
self.solutionTable = {{}}
startPos.x = startPox.x + 1
startPos.y = startPox.y + 1
self.startPosition = startPos
self.__index = self
setmetatable(obj,self)
return obj
end
function PuzzleBoard:solutionTable(solutionIdstable)
self.solutionTable = solutionIdstable
end
function PuzzleBoard::onAddItem(moveItem,tileItem,position,cid)
if self:isSolved() then
--if puzzles are solved then do something
print("puzzles are solved!!!")
self:shufflePuzzles()
else
print("Do nothing probably, since you want it to do action when its solved")
end
end
function PuzzleBoard:getPositions()
local ret = {}
for k, v in pairs(self.solutionTable)
for j,m in pairs(v)
local pos = self.startPos
local pozzlePos = {x = pos.x + k, y = pos.y + j, z = pos.z stackpos = 254}
table.insert(ret,puzzlePos)
end
end
end
function PuzzleBoard:sufflePuzzles()
local ret = self:getPositions()
local neworder = {}
for k, v in pairs(self.solutionTable)
for j,m in pairs(v)
local pos = self.startPos
local pozzlePos = {x = pos.x + k, y = pos.y + j, z = pos.z stackpos = 254}
local item = getTileItemById(puzzlePos, m)
local newPos = ret[math.random(1,table.maxv(ret))]
if item == nil or item.uid <= 0 then
return error("No puzzle found on tile")
end
table.insert(neworder,{uid = item.uid, pos = newPos})
end
end
if table.maxv(ret) ~= table.maxv(neworder) then
-- to make sure that we moved as many puzzles as were at the begining
return error("Entry puzzle amount is not equal to output amount")
end
for k, v in pairs(neworder) do
doTeleportThing(v.uid, v.pos)
end
end
function PuzzleBoard:isSolved()
local ret = true
for k, v in pairs(self.solutionTable)
for j,m in pairs(v)
local pos = self.startPos
local pozzlePos = {x = pos.x + k, y = pos.y + j, z = pos.z stackpos = 254}
local item = getTileItemById(puzzlePos, m)
if item == nil or item.uid <= 0 then
return false
end
end
end
return ret
end
Lua:
<movevent type="AddItem" tileitem="1" actionid="2605" event="script" value="script.lua"/>
I there are errors try to understand this code and fix that. Now usage:
Lua:
local board = PuzzleBoard:new(left-topcorner pos here)
local solutionIds = {{ id1, id2, id3},
{id4, id5, id6},
{id7,id8,id9}}
board:solutionTable(solutionIds)
function onAddItem(moveItem, tileItem, position, cid)
print("Called onAddItem event")
board:onAddItem(moveItem,tileItem,position,cid)
end