Joriku
Working in the mines, need something?
Hi, trying to write a simple for loop that takes each player on position tiles and sends them to new positions, inside the config.
However, my lua is rusty.
Ideas?
Code is fixed, added. Edited main code.
added:
function isPositionEqual(pos1, pos2)
and edited the loop
However, my lua is rusty.
Ideas?
Lua:
local action = Action()
local config = {
boss = {
name = "Test Dragon",
position = Position(32332, 32217, 7),
},
playerPositions = {
{ pos = Position(32336, 32215, 7), teleport = Position(32331, 32215, 7) },
{ pos = Position(32337, 32215, 7), teleport = Position(32332, 32215, 7) },
{ pos = Position(32338, 32215, 7), teleport = Position(32333, 32215, 7) },
{ pos = Position(32339, 32215, 7), teleport = Position(32334, 32215, 7) },
},
specPos = {
from = Position(32330, 32214, 7),
to = Position(32335, 32218, 7),
},
exit = Position(32338, 32217, 7),
}
-- reset timer
local teleportTimer = 10 -- seconds
-- canary config
--local lever = BossLever(config)
function isPositionEqual(pos1, pos2)
return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z
end
function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- If lever is pressed, and cooldown is active.
if item.itemid == 2773 then
player:say("Cling", TALKTYPE_MONSTER_SAY)
player:sendTextMessage(MESSAGE_STATUS_WARNING, "Sorry, this room is currently in use. Please, come back later.")
return true
end
-- If lever time is over or reset
if item.itemid == 2772 then
item:transform(2773)
Game.createMonster(config.boss.name, config.boss.position, 1) -- 1 being one mob
-- teleport player(s)
for _, positionData in ipairs(config.playerPositions) do
local posTile = Tile(positionData.pos)
local newTeleportPos = positionData.teleport
local creatures = posTile:getCreatures()
for _, creature in ipairs(creatures) do
if creature:isPlayer() then
local playerName = creature:getName()
for _, validPos in ipairs(config.playerPositions) do
if isPositionEqual(creature:getPosition(), validPos.pos) then
print("Teleporting player:", playerName)
creature:teleportTo(newTeleportPos, true)
newTeleportPos:sendMagicEffect(CONST_ME_TELEPORT)
end
end
end
end
end
addEvent(function() -- Change lever back once time is up
item:transform(2772)
-- Kick players, remove mobs from radius
end, teleportTimer * 1000)
end
return true
end
action:aid(2550)
action:register()
Code is fixed, added. Edited main code.
added:
function isPositionEqual(pos1, pos2)
and edited the loop
Lua:
for _, positionData in ipairs(config.playerPositions) do
local posTile = Tile(positionData.pos)
local newTeleportPos = positionData.teleport
local creatures = posTile:getCreatures()
for _, creature in ipairs(creatures) do
if creature:isPlayer() then
local playerName = creature:getName()
for _, validPos in ipairs(config.playerPositions) do
if isPositionEqual(creature:getPosition(), validPos.pos) then
print("Teleporting player:", playerName)
creature:teleportTo(newTeleportPos, true)
newTeleportPos:sendMagicEffect(CONST_ME_TELEPORT)
end
end
end
end
end
Last edited: