Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lua] rewrite logic to spawn skull NMs in Eldieme Necropolis #7011

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 57 additions & 58 deletions scripts/zones/The_Eldieme_Necropolis/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,61 @@
-----------------------------------
local ID = zones[xi.zone.THE_ELDIEME_NECROPOLIS]
-----------------------------------
local spawnSkulls = function()
-- Spawn all 7 Skulls
for skull = 1, 7 do
SpawnMob(ID.mob.LICH_C_MAGNUS + skull) -- IDs based off Lich C Magnus
end

-- Handle 7 Sins Skeleton NMs Spawns
local skullTrade = function(player, npc)
local candleCount =
{
ID.text.SKULL_FIVE_REMAIN,
ID.text.SKULL_FOUR_REMAIN,
ID.text.SKULL_THREE_REMAIN,
ID.text.SKULL_TWO_REMAIN,
ID.text.SKULL_ONE_REMAIN,
ID.text.SKULL_SPAWN,
}

local tradeCount = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullTradeCount') -- Track how many candles have been lit
local tradeWindow = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullTradeTimer') -- Track how much time before candles reset
local active = npc:getLocalVar('candleActive') -- Track if current candle has already been lit

for i = 1, 5 do
if tradeCount == 6 and os.time() < tradeWindow and os.time() > active then -- Final candle, spawn Skulls
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeCount', 0)
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullRespawn', os.time() + 3600) -- 1 hour cooldown to respawn skulls
player:messageSpecial(ID.text.SKULL_SPAWN)
player:confirmTrade()

-- Spawn all 7 Skulls
for skull = 1, 7 do
SpawnMob(ID.mob.LICH_C_MAGNUS + skull) -- IDs based off Lich C Magnus
end
-- Used to stop Skulls from being spawned until an hour from being spawned
SetServerVariable('[ELDIEME]TimeToRespawnSkulls', os.time() + 3600)
end

local brazierMessages =
{
ID.text.SKULL_SPAWN,
ID.text.SKULL_ONE_REMAIN,
ID.text.SKULL_TWO_REMAIN,
ID.text.SKULL_THREE_REMAIN,
ID.text.SKULL_FOUR_REMAIN,
ID.text.SKULL_FIVE_REMAIN,
ID.text.SKULL_SIX_REMAIN,
}

break
elseif tradeCount == i and os.time() < tradeWindow and os.time() > active then -- Candle trades 2 through 6
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeCount', i + 1)
npc:setLocalVar('candleActive', os.time() + 10)
player:messageSpecial(ID.text.THE_BRAZIER_IS_LIT)
player:messageSpecial(candleCount[i])
player:confirmTrade()
break
elseif os.time() > tradeWindow and os.time() > active then -- First candle trade to start timer
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeCount', 1)
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeTimer', os.time() + 40)
npc:setLocalVar('candleActive', os.time() + 10)
player:messageSpecial(ID.text.THE_BRAZIER_IS_LIT)
player:messageSpecial(ID.text.SKULL_SIX_REMAIN)
player:confirmTrade()
break
local countUnlitBraziers = function()
local numberNotLit = 7

for i = 0, 6 do
local brazier = GetNPCByID(ID.npc.CANDLE_OFFSET + i)
if brazier and brazier:getAnimation() == xi.anim.OPEN_DOOR then
numberNotLit = numberNotLit - 1
end
end

return numberNotLit
end

local eldiemeGlobal =
{
local lightBrazier = function(player, npc)
npc:setAnimation(xi.anim.OPEN_DOOR)

--unlight brazier after five minutes
npc:timer(300000, function()
npc:setAnimation(xi.anim.CLOSE_DOOR)
end)
Comment on lines +42 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so you are aware in the future, there is literally a function specifically to open a door, wait a specified number of seconds, and then close the same door, performing all 3 of these functions with one invocation without any seconds to milliseconds conversion or potential snags you can hit by invoking timer() directly. There is also a matching function to do a the reverse (closing a default open door, and then reopening it after a timeout).

npc:openDoor(300) would have done exactly what you did here in a single line.


player:messageSpecial(ID.text.THE_BRAZIER_IS_LIT)

local numberNotLit = countUnlitBraziers()
local messageAfterLightingBrazier = brazierMessages[numberNotLit + 1]

player:messageSpecial(messageAfterLightingBrazier)

if numberNotLit == 0 then
spawnSkulls()
end
end

local eldiemeGlobal = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local nameOfTheTable =
{

This applies for all tables and such

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry about that

-- Click on any of the intersection gates
gateOnTrigger = function(player, npc)
if npc:getAnimation() == xi.anim.CLOSE_DOOR then
Expand Down Expand Up @@ -87,30 +91,25 @@ local eldiemeGlobal =
end,

handleCandleTrade = function(player, npc, trade)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls

if
npcUtil.tradeHasExactly(trade, xi.item.FLINT_STONE) and
os.time() > timer
os.time() > GetServerVariable('[ELDIEME]TimeToRespawnSkulls') and
npcUtil.tradeHasExactly(trade, xi.item.FLINT_STONE)
then
skullTrade(player, npc)
elseif os.time() < timer then
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
lightBrazier(player, npc)
else
player:messageSpecial(ID.text.NOTHING_HAPPENED)
end
end,

handleCandleTrigger = function(player, npc)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls
local active = npc:getLocalVar('candlesActive')

if os.time() < active then
if npc:getAnimation() == xi.anim.OPEN_DOOR then
player:messageSpecial(ID.text.BRAZIER_ACTIVE)
elseif os.time() > timer and os.time() > active then
elseif os.time() > GetServerVariable('[ELDIEME]TimeToRespawnSkulls') then
player:messageSpecial(ID.text.BRAZIER_OUT, 0, xi.item.FLINT_STONE)
else
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
end
end,
}

return eldiemeGlobal
Loading