Skip to content

Commit

Permalink
improve: conversion of levers to new standard (#1021)
Browse files Browse the repository at this point in the history
This script is a continuation of PR #648, in it, converting some levers that are with the old pattern.
  • Loading branch information
Glatharth authored Apr 27, 2023
1 parent e718895 commit ba714da
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 1,540 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
local config = {
bossName = "Megasylvan Yselda",
boss = {
name = "Megasylvan Yselda",
position = Position(32619, 32493, 12)
},
requiredLevel = 250,
timeToFightAgain = 20, -- In hour
timeToDefeatBoss = 20, -- In minutes
timeToFightAgain = 20 * 60 * 60,
timeToDefeatBoss = 20 * 60,
playerPositions = {
{pos = Position(32578, 32500, 12), teleport = Position(32619, 32498, 12), effect = CONST_ME_TELEPORT},
{pos = Position(32578, 32501, 12), teleport = Position(32619, 32498, 12), effect = CONST_ME_TELEPORT},
{pos = Position(32578, 32502, 12), teleport = Position(32619, 32498, 12), effect = CONST_ME_TELEPORT},
{pos = Position(32578, 32503, 12), teleport = Position(32619, 32498, 12), effect = CONST_ME_TELEPORT},
{pos = Position(32578, 32504, 12), teleport = Position(32619, 32498, 12), effect = CONST_ME_TELEPORT}
},
bossPosition = Position(32619, 32493, 12),
specPos = {
from = Position(32601, 32486, 12),
to = Position(32633, 32509, 12)
Expand All @@ -21,72 +23,7 @@ local config = {

local megasylvanYseldaLever = Action()
function megasylvanYseldaLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if config.playerPositions[1].pos ~= player:getPosition() then
return false
end
local spec = Spectators()
spec:setOnlyPlayer(false)
spec:setRemoveDestination(config.exit)
spec:setCheckPosition(config.specPos)
spec:check()
if spec:getPlayers() > 0 then
player:say("There's someone fighting with " .. config.bossName .. ".", TALKTYPE_MONSTER_SAY)
return true
end
local lever = Lever()
lever:setPositions(config.playerPositions)
lever:setCondition(function(creature)
if not creature or not creature:isPlayer() then
return true
end
if creature:getLevel() < config.requiredLevel then
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All the players need to be level " .. config.requiredLevel .. " or higher.")
return false
end
if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face ".. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
return false
end
return true
end)
lever:checkPositions()
if lever:checkConditions() then
spec:removeMonsters()
local monster = Game.createMonster(config.bossName, config.bossPosition, true, true)
if not monster then
return true
end
lever:teleportPlayers()
lever:setStorageAllPlayers(config.storage, os.time() + config.timeToFightAgain * 3600)
addEvent(function()
local old_players = lever:getInfoPositions()
spec:clearCreaturesCache()
spec:setOnlyPlayer(true)
spec:check()
local player_remove = {}
for i, v in pairs(spec:getCreatureDetect()) do
for _, v_old in pairs(old_players) do
if v_old.creature == nil or v_old.creature:isMonster() then
break
end
if v:getName() == v_old.creature:getName() then
table.insert(player_remove, v_old.creature)
break
end
end
end
spec:removePlayers(player_remove)
end, config.timeToDefeatBoss * 60 * 1000)
end
return CreateDefaultLeverBoss(player, config)
end

megasylvanYseldaLever:position({x = 32578, y = 32499, z = 12})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
local config = {
bossName = "The Dread Maiden",
boss = {
name = "The Dread Maiden",
position = Position(33712, 31503, 14)
},
requiredLevel = 250,
timeToFightAgain = 20, -- In hour
timeToDefeatBoss = 20, -- In minutes
timeToFightAgain = 20 * 60 * 60,
timeToDefeatBoss = 20 * 60,
playerPositions = {
{pos = Position(33739, 31506, 14), teleport = Position(33711, 31510, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33740, 31506, 14), teleport = Position(33711, 31510, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33741, 31506, 14), teleport = Position(33711, 31510, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33742, 31506, 14), teleport = Position(33711, 31510, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33743, 31506, 14), teleport = Position(33711, 31510, 14), effect = CONST_ME_TELEPORT}
},
bossPosition = Position(33712, 31503, 14),
specPos = {
from = Position(33703, 31494, 14),
to = Position(33721, 31512, 14)
Expand All @@ -21,72 +23,7 @@ local config = {

local dreadMaidenLever = Action()
function dreadMaidenLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if config.playerPositions[1].pos ~= player:getPosition() then
return false
end
local spec = Spectators()
spec:setOnlyPlayer(false)
spec:setRemoveDestination(config.exit)
spec:setCheckPosition(config.specPos)
spec:check()
if spec:getPlayers() > 0 then
player:say("There's someone fighting with " .. config.bossName .. ".", TALKTYPE_MONSTER_SAY)
return true
end
local lever = Lever()
lever:setPositions(config.playerPositions)
lever:setCondition(function(creature)
if not creature or not creature:isPlayer() then
return true
end
if creature:getLevel() < config.requiredLevel then
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All the players need to be level " .. config.requiredLevel .. " or higher.")
return false
end
if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face ".. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
return false
end
return true
end)
lever:checkPositions()
if lever:checkConditions() then
spec:removeMonsters()
local monster = Game.createMonster(config.bossName, config.bossPosition, true, true)
if not monster then
return true
end
lever:teleportPlayers()
lever:setStorageAllPlayers(config.storage, os.time() + config.timeToFightAgain * 3600)
addEvent(function()
local old_players = lever:getInfoPositions()
spec:clearCreaturesCache()
spec:setOnlyPlayer(true)
spec:check()
local player_remove = {}
for i, v in pairs(spec:getCreatureDetect()) do
for _, v_old in pairs(old_players) do
if v_old.creature == nil or v_old.creature:isMonster() then
break
end
if v:getName() == v_old.creature:getName() then
table.insert(player_remove, v_old.creature)
break
end
end
end
spec:removePlayers(player_remove)
end, config.timeToDefeatBoss * 60 * 1000)
end
return CreateDefaultLeverBoss(player, config)
end

dreadMaidenLever:position({x = 33738, y = 31506, z = 14})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
local config = {
bossName = "The Fear Feaster",
boss = {
name = "The Fear Feaster",
position = Position(33711, 31469, 14)
},
requiredLevel = 250,
timeToFightAgain = 20, -- In hour
timeToDefeatBoss = 20, -- In minutes
timeToFightAgain = 20 * 60 * 60,
timeToDefeatBoss = 20 * 60,
playerPositions = {
{pos = Position(33734, 31471, 14), teleport = Position(33711, 31476, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33735, 31471, 14), teleport = Position(33711, 31476, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33736, 31471, 14), teleport = Position(33711, 31476, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33737, 31471, 14), teleport = Position(33711, 31476, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33738, 31471, 14), teleport = Position(33711, 31476, 14), effect = CONST_ME_TELEPORT}
},
bossPosition = Position(33711, 31469, 14),
specPos = {
from = Position(33705, 31463, 14),
to = Position(33719, 31477, 14)
Expand All @@ -21,72 +23,7 @@ local config = {

local fearFeasterLever = Action()
function fearFeasterLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if config.playerPositions[1].pos ~= player:getPosition() then
return false
end
local spec = Spectators()
spec:setOnlyPlayer(false)
spec:setRemoveDestination(config.exit)
spec:setCheckPosition(config.specPos)
spec:check()
if spec:getPlayers() > 0 then
player:say("There's someone fighting with " .. config.bossName .. ".", TALKTYPE_MONSTER_SAY)
return true
end
local lever = Lever()
lever:setPositions(config.playerPositions)
lever:setCondition(function(creature)
if not creature or not creature:isPlayer() then
return true
end
if creature:getLevel() < config.requiredLevel then
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All the players need to be level " .. config.requiredLevel .. " or higher.")
return false
end
if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face ".. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
return false
end
return true
end)
lever:checkPositions()
if lever:checkConditions() then
spec:removeMonsters()
local monster = Game.createMonster(config.bossName, config.bossPosition, true, true)
if not monster then
return true
end
lever:teleportPlayers()
lever:setStorageAllPlayers(config.storage, os.time() + config.timeToFightAgain * 3600)
addEvent(function()
local old_players = lever:getInfoPositions()
spec:clearCreaturesCache()
spec:setOnlyPlayer(true)
spec:check()
local player_remove = {}
for i, v in pairs(spec:getCreatureDetect()) do
for _, v_old in pairs(old_players) do
if v_old.creature == nil or v_old.creature:isMonster() then
break
end
if v:getName() == v_old.creature:getName() then
table.insert(player_remove, v_old.creature)
break
end
end
end
spec:removePlayers(player_remove)
end, config.timeToDefeatBoss * 60 * 1000)
end
return CreateDefaultLeverBoss(player, config)
end

fearFeasterLever:position({x = 33733, y = 31471, z = 14})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
local config = {
bossName = "The Pale Worm",
boss = {
name = "The Pale Worm",
position = Position(33805, 31504, 14)
},
requiredLevel = 250,
timeToFightAgain = 20, -- In hour
timeToDefeatBoss = 25, -- In minutes
timeToFightAgain = 20 * 60 * 60,
timeToDefeatBoss = 25 * 60,
playerPositions = {
{pos = Position(33772, 31504, 14), teleport = Position(33808, 31515, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33773, 31504, 14), teleport = Position(33808, 31515, 14), effect = CONST_ME_TELEPORT},
Expand All @@ -15,7 +18,6 @@ local config = {
{pos = Position(33774, 31505, 14), teleport = Position(33808, 31515, 14), effect = CONST_ME_TELEPORT},
{pos = Position(33775, 31505, 14), teleport = Position(33808, 31515, 14), effect = CONST_ME_TELEPORT}
},
bossPosition = Position(33805, 31504, 14),
specPos = {
from = Position(33793, 31496, 14),
to = Position(33816, 31515, 14)
Expand All @@ -26,72 +28,7 @@ local config = {

local paleWormLever = Action()
function paleWormLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if config.playerPositions[1].pos ~= player:getPosition() then
return false
end
local spec = Spectators()
spec:setOnlyPlayer(false)
spec:setRemoveDestination(config.exit)
spec:setCheckPosition(config.specPos)
spec:check()
if spec:getPlayers() > 0 then
player:say("There's someone fighting with " .. config.bossName .. ".", TALKTYPE_MONSTER_SAY)
return true
end
local lever = Lever()
lever:setPositions(config.playerPositions)
lever:setCondition(function(creature)
if not creature or not creature:isPlayer() then
return true
end
if creature:getLevel() < config.requiredLevel then
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All the players need to be level " .. config.requiredLevel .. " or higher.")
return false
end
if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face ".. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
return false
end
return true
end)
lever:checkPositions()
if lever:checkConditions() then
spec:removeMonsters()
local monster = Game.createMonster(config.bossName, config.bossPosition, true, true)
if not monster then
return true
end
lever:teleportPlayers()
lever:setStorageAllPlayers(config.storage, os.time() + config.timeToFightAgain * 3600)
addEvent(function()
local old_players = lever:getInfoPositions()
spec:clearCreaturesCache()
spec:setOnlyPlayer(true)
spec:check()
local player_remove = {}
for i, v in pairs(spec:getCreatureDetect()) do
for _, v_old in pairs(old_players) do
if v_old.creature == nil or v_old.creature:isMonster() then
break
end
if v:getName() == v_old.creature:getName() then
table.insert(player_remove, v_old.creature)
break
end
end
end
spec:removePlayers(player_remove)
end, config.timeToDefeatBoss * 60 * 1000)
end
return CreateDefaultLeverBoss(player, config)
end

paleWormLever:position({x = 33771, y = 31504, z = 14})
Expand Down
Loading

0 comments on commit ba714da

Please sign in to comment.