Lava Titan
Developer
Hey, any idea on how can I check for all tiles with certain aid between 2 distances?
function getEmptyTileBetween(fromPos, toPos, actionId, exitPos)
for x = fromPos.x, toPos.x do for y = fromPos.y, toPos.y do
local tempPos = Position(x, y, fromPos.z)
local tile = Tile(tempPos)
if tile then
local ground = tile:getGround()
if ground and ground:getActionId() == actionId then
if...
Hey, any idea on how can I check for all tiles with certain aid between 2 distances?
local config = {
actionid = 12345
}
----[ HORIZONTAL LINE ]----
local posA = Position(1000, 1000, 7)
local posB = Position(1005, 1000, 7)
for x = posA.x, posB.x do
local tile = Tile(x, posA.y, posA.z)
if not tile then return end
local ground = tile:getGround()
if ground:getActionId() == config.actionid then
-- do something
end
end
----[ VERTICAL LINE ]----
local posA = Position(1000, 1000, 7)
local posB = Position(1000, 1005, 7)
for y = posA.y, posB.y do
local tile = Tile(posA.x, y, posA.z)
if not tile then return end
local ground = tile:getGround()
if ground:getActionId() == config.actionid then
-- do something
end
end
----[ AREA ]----
local z = posA.z
for x = posA.x, posB.x do
for y = posA.y, posB.y do
local tile = Tile(x, y, z)
if not tile then return end
local ground = tile:getGround()
if ground:getActionId() == config.actionid then
-- do something
end
end
end
Lua:local config = { actionid = 12345 } ----[ AREA ]---- local z = posA.z for x = posA.x, posB.x do for y = posA.y, posB.y do local tile = Tile(x, y, z) if not tile then return end local ground = tile:getGround() if ground:getActionId() == config.actionid then -- do something end end end
local p = player
if not p then
return p:teleportTo(fromPosition)
end
----[ AREA ]----
local posA = Position(3375, 1983, 14)
local posB = Position(3736, 2163, 14)
local z = posA.z
for x = posA.x, posB.x do
for y = posA.y, posB.y do
local tile = Tile(x, y, z)
--print(#tile) -- trying to print how many tiles in this area have aid 3333
end
end
if item:getActionId() == 1111 then -- temple teleport action id
local ground = tile:getGround()
if ground:getActionId() == 3333 then -- tile where player is supposed to be teleported to
p:teleportTo(Position(ground:getPosition())) -- teleport to any free tile in this area with aid 3333
end
end
function getEmptyTileBetween(pos1, pos2, actionId) -- getEmptyTileBetween(config.firstPos, config.lastPos)
local posA = pos1
local posB = pos2
local returnPos = Position(1000, 1000, 6) -- temple pos
local z = posA.z
for x = posA.x, posB.x do
for y = posA.y, posB.y do
local tile = Tile(x, y, z)
if not tile then return end
local ground = tile:getGround()
local var = ground:getPosition()
local spectators = Game.getSpectators(var, false, true, 5, 5, 5, 5)
if ground:getActionId() == actionId then
if #spectators == 0 then
print(#spectators)
return Position(x, y, z)
else
print(#spectators)
return returnPos
end
end
end
end
end
----------------------------------------------------------------------------------------------------------------
-- This is some kind of advanced lazy training room script, but I find this easier for big amounts of training rooms
-- The script should check for an empty room based on an area where all rooms have one tile with XXXX aid,
-- instead of adding all rooms positions it should just find them by checking the spectators in the area
----------------------------------------------------------------------------------------------------------------
local config = {
firstPos = Position(3143, 1984, 14), -- first north west pos
lastPos = Position(3623, 2488, 14), -- last south east pos
templePos = Position(1000, 1000, 6), -- temple pos
stepInAid = 11111, -- this is a teleport in temple
stepOutAid = 22222, -- this is the teleport in all training rooms that teleports them out
checkForAid = 33333, -- this is the aid of the tile that should be empty in the training room
trainingStorage = 12345
}
local stepInTrainingRoom = MoveEvent()
stepInTrainingRoom:type("stepin")
function stepInTrainingRoom.onStepIn(player, item, position, fromPosition)
local p = player
if not p then
return p:teleportTo(fromPosition)
end
local teleportPos = getEmptyTileBetween(config.firstPos, config.lastPos, config.checkForAid)
p:teleportTo(teleportPos)
player:setStorageValue(12345, 1) -- training storage
return true
end
stepInTrainingRoom:aid(11111)
stepInTrainingRoom:register()
------------------------------------------------------------
local stepOutTraining = MoveEvent()
stepOutTraining:type("stepOut")
function stepOutTraining.onStepIn(player, item, position, fromPosition)
local p = player
if not p then
return p:teleportTo(fromPosition)
end
if item:getActionId() == config.stepOutAid then
player:setStorageValue(12345, 0) -- training storage
p:teleportTo(config.templePos)
end
return true
end
stepOutTraining:aid(22222)
stepOutTraining:register()
This might be what you're looking for.updated last post xd
kinda, yeah, this will work thank you very muchThis might be what you're looking for.
Lua - Xikini's Free Scripting Service TFS 1.3
Please request actions / creatureevents / globalevents / npcs / movements / talkactions Do not request spells / weapons / monsters / source editing / database queries My goal of this thread is to learn TFS 1.3 scripting. ------------------------------------ Support If you have an issue with...otland.net
You just copy-paste the training rooms, and the script will find all the training rooms automatically, within the designated area you tell it to look.
function getEmptyTileBetween(pos1, pos2, aid) -- getEmptyTileBetween(config.firstPos, config.lastPos)
local posA = pos1
local posB = pos2
local returnPos = Position(1000, 1000, 6)
local z = posA.z
for x = posA.x, posB.x do
for y = posA.y, posB.y do
local tile = Tile(x, y, z)
if not tile then return end
local ground = tile:getGround()
local var = ground:getPosition()
local spectators = Game.getSpectators(var, false, true, 5, 5, 5, 5)
if ground:getActionId() == actionId then
if #spectators == 0 then
print(#spectators)
return Position(x, y, z)
else
print(#spectators)
return returnPos
end
end
end
end
end
kinda, yeah, this will work thank you very much
even tho I wanted to fix this function so I could use it in other scripts in the future
if possible xD
Lua:function getEmptyTileBetween(pos1, pos2, aid) -- getEmptyTileBetween(config.firstPos, config.lastPos) local posA = pos1 local posB = pos2 local returnPos = Position(1000, 1000, 6) local z = posA.z for x = posA.x, posB.x do for y = posA.y, posB.y do local tile = Tile(x, y, z) if not tile then return end local ground = tile:getGround() local var = ground:getPosition() local spectators = Game.getSpectators(var, false, true, 5, 5, 5, 5) if ground:getActionId() == actionId then if #spectators == 0 then print(#spectators) return Position(x, y, z) else print(#spectators) return returnPos end end end end end
function getEmptyTileBetween(fromPos, toPos)
local x, y = math.floor((toPos.x - fromPos.x)/2), math.floor((toPos.y - fromPos.y)/2)
local tempPos = Position(x, y, fromPos.z)
local spectators = Game.getSpectators(tempPos, false, true, x, x, y, y)
return #spectators == 0 and tempPos or Position(3191, 1809, 7)
end
damn Sarah, you shortned it so much xDLua:function getEmptyTileBetween(fromPos, toPos) local x, y = math.floor((toPos.x - fromPos.x)/2), math.floor((toPos.y - fromPos.y)/2) local tempPos = Position(x, y, fromPos.z) local spectators = Game.getSpectators(tempPos, false, true, x, x, y, y) return #spectators == 0 and tempPos or Position(3191, 1809, 7) end
local teleportPos = getEmptyTileBetween(Position(3143, 1984, 14), Position(3623, 2488, 14), 33333, Position(1000, 1000, 6))
p:teleportTo(teleportPos)
function getEmptyTileBetween(fromPos, toPos, actionId, exitPos)
local x, y = math.floor((toPos.x - fromPos.x)/2), math.floor((toPos.y - fromPos.y)/2)
local tempPos = Position(x, y, fromPos.z)
local spectators = Game.getSpectators(tempPos, false, true, x, x, y, y)
local tile = Tile(tempPos):getGround()
if tile:getActionId() == actionId and #spectators == 0 then
return tempPos
else
return exitPos
end
end
function getEmptyTileBetween(fromPos, toPos, actionId, exitPos)
for x = fromPos.x, toPos.x do for y = fromPos.y, toPos.y do
local tempPos = Position(x, y, fromPos.z)
local tile = Tile(tempPos)
if tile then
local ground = tile:getGround()
if ground and ground:getActionId() == actionId then
if #Game.getSpectators(tempPos, false, true, 5, 5, 5, 5) == 0 then
return tempPos
end
end
end
end end
return exitPos
end