roomIndex = {}
config =
{
room =
{
teleport = 1387,
ground = 406,
nortWestCorner = 1113,
southEastCorner = 1115,
wallFaceNorth = 1116,
wallFaceEast = 1114,
fire = 1484,
trainer = "Training Monk"
},
temple = {x = 3893, y = 3710, z = 6}, -- the position the player will get teleported to if he leaves the training room
startPos = {x = 100, y = 100, z = 6}, -- the top north west position from where we start to create the rooms from.
offset = 5, -- this is the space between each masterPos of the room (can't be lower then 5!)
gridX = 10, -- how much training rooms we create on one x axis
gridY = 10, -- how much training rooms we create on one y axis
gridZ = 3 -- how much layers we use therefor
-- this basicly means we can create in the grid example: 10*10*3 = 300 trainings room in this case.
}
function createTrainingRoom(pos)
local realPos = {x = pos.x - 2, y = pos.y - 2, z = pos.z}
for a = 0,4 do -- here we create the ground
for b = 0,4 do
doCreateItem(config.room.ground, 1, {x = realPos.x + a, y = realPos.y + b, z = realPos.z})
end
end
doCreateItem(config.room.nortWestCorner, 1, realPos) -- we create the north west corner wall
doCreateItem(config.room.southEastCorner, 1, {x = realPos.x + 4, y = realPos.y + 4, z = realPos.z}) -- we create the south east corner wall
for a = 1,4 do -- we create the left wall side which faces north
doCreateItem(config.room.wallFaceNorth, 1, {x = realPos.x, y = realPos.y + a, z = realPos.z})
end
for a = 1,3 do -- we create the right wall side which faces north
doCreateItem(config.room.wallFaceNorth, 1, {x = realPos.x + 4, y = realPos.y + a, z = realPos.z})
end
for a = 1,4 do -- we create the north wall side which faces east
doCreateItem(config.room.wallFaceEast, 1, {x = realPos.x + a, y = realPos.y, z = realPos.z})
end
for a = 1,3 do -- we create the south wall side which faces east
doCreateItem(config.room.wallFaceEast, 1, {x = realPos.x + a, y = realPos.y + 4, z = realPos.z})
end
doCreateItem(config.room.fire, 1, {x = realPos.x + 1, y = realPos.y + 2, z = realPos.z}) -- here we create the fire lights
doCreateItem(config.room.fire, 1, {x = realPos.x + 1, y = realPos.y + 3, z = realPos.z}) -- here we create the fire lights
doCreateItem(config.room.fire, 1, {x = realPos.x + 3, y = realPos.y + 2, z = realPos.z}) -- here we create the fire lights
doCreateItem(config.room.fire, 1, {x = realPos.x + 3, y = realPos.y + 3, z = realPos.z}) -- here we create the fire lights
doSummonCreature(config.room.trainer, {x = realPos.x + 3, y = realPos.y + 1, z = realPos.z}) -- here we create the training monsters
doSummonCreature(config.room.trainer, {x = realPos.x + 1, y = realPos.y + 1, z = realPos.z}) -- here we create the training monsters
local teleport = doCreateItem(config.room.teleport, 1, {x = realPos.x + 2, y = realPos.y + 1, z = realPos.z})
doItemSetAttribute(teleport, "aid", 8771) -- here we create the teleport to leave the room
end
function deleteTrainingRoom(pos)
local playerpos = pos
for x = playerpos.x-2, playerpos.x+2 do
for y = playerpos.y-1, playerpos.y+3 do
for z = playerpos.z, playerpos.z do
local pos = {x=x, y=y, z=z, stackpos = 253}
local thing = getThingfromPos(pos)
if thing.itemid > 0 then
doRemoveCreature(thing.uid)
end
local pos = {x=x, y=y, z=z, stackpos = 1}
local thing = getThingfromPos(pos)
if thing.itemid > 0 then
doRemoveItem(thing.uid)
end
local pos = {x=x, y=y, z=z}
local thing = getThingfromPos(pos)
if thing.itemid > 0 then
doRemoveItem(thing.uid)
end
end
end
end
return true
end
function getNextRoom()
if roomIndex[1] ~= nil then
for a = 1, #roomIndex do
if roomIndex[a] == false then
return a
elseif #roomIndex == a then
roomIndex[#roomIndex + 1] = false
return #roomIndex
end
end
else
return 1
end
end
function getRoomPosFromIndex(id)
local indicator = {x = 0, y = 0, z = 0}
if id > config.gridX * config.gridY then
repeat
id = id - config.gridX * config.gridY
indicator.z = indicator.z + 1
until id <= config.gridX * config.gridY
end
if id > config.gridX then
repeat
id = id - config.gridY
indicator.y = indicator.y + 1
until id <= config.gridY
end
indicator.x = id
local offset = {x = indicator.x * config.offset, y = indicator.y * config.offset, z = indicator.z}
return {x = config.startPos.x + offset.x, y = config.startPos.y + offset.y, z = config.startPos.z + offset.z}
end
function getRoomIndexFromPos(pos)
local x = (pos.x - config.startPos.x) / config.offset
local y = (pos.y - config.startPos.y) / config.offset * config.gridY
local z = (pos.z - config.startPos.z) * (config.gridX * config.gridY)
return (x + y + z)
end
function setRoomInUse(id)
roomIndex[id] = true
end
function setRoomUnused(id)
roomIndex[id] = false
end