Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Globalize functions
Browse files Browse the repository at this point in the history
Style cleanup and logic changes after retail testing.
  • Loading branch information
cocosolos committed May 14, 2020
1 parent 6a09bcb commit 78a0aa3
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 277 deletions.
1 change: 1 addition & 0 deletions scripts/zones/Misareaux_Coast/IDs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ zones[tpz.zone.MISAREAUX_COAST] =
DOOR_CLOSED = 7347, -- The door is locked tight.
LOGGING_IS_POSSIBLE_HERE = 7601, -- Logging is possible here if you have <item>.
NOTHING_HERE_YET = 7660; -- There is nothing here yet. Check again in the morning.
ALREADY_BAITED = 7661; -- The trap already contains <item>.
APPEARS_TO_BE_TRAP = 7662; -- There appears to be some kind of trap here. Bits of fish are lying around the area.
DID_NOT_CATCH_ANYTHING = 7663; -- You did not catch anything.
PUT_IN_TRAP = 7664; -- You put <item> in the trap.
Expand Down
27 changes: 8 additions & 19 deletions scripts/zones/Misareaux_Coast/Zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
-----------------------------------
require("scripts/globals/conquest")
require("scripts/globals/helm")
require("scripts/zones/Misareaux_Coast/IDs")
local ID = require("scripts/zones/Misareaux_Coast/IDs")
local MISAREAUX_COAST = require("scripts/zones/Misareaux_Coast/globals")
-----------------------------------

function onInitialize(zone)
tpz.helm.initZone(zone, tpz.helm.type.LOGGING)
MISAREAUX_COAST.ziphiusHandleQM()
end

function onConquestUpdate(zone, updatetype)
Expand All @@ -18,8 +20,8 @@ end

function onZoneIn(player,prevZone)
local cs = -1
if (player:getXPos() == 0 and player:getYPos() == 0 and player:getZPos() == 0) then
player:setPos(567.624,-20,280.775,120)
if player:getXPos() == 0 and player:getYPos() == 0 and player:getZPos() == 0 then
player:setPos(567.624, -20, 280.775, 120)
end
return cs
end
Expand All @@ -28,22 +30,9 @@ function onRegionEnter(player,region)
end

function onGameHour(zone)
local ZIPHIUS_QM_BASE = 16879919
if VanadielHour() == 22 then -- Spawn traps for Ziphius
for i = ZIPHIUS_QM_BASE, ZIPHIUS_QM_BASE+5, 1 do
GetNPCByID(i):setStatus(tpz.status.NORMAL)
end
elseif VanadielHour() == 7 then -- Despawn traps for Ziphius
for i = ZIPHIUS_QM_BASE, ZIPHIUS_QM_BASE+5, 1 do
GetNPCByID(i):setStatus(tpz.status.DISAPPEAR)
GetNPCByID(i):setLocalVar("[Ziphius]Bait Trap", 0)
end
elseif VanadielHour() == 4 then -- Despawn non-baited traps
for i = ZIPHIUS_QM_BASE, ZIPHIUS_QM_BASE+5, 1 do
if (GetNPCByID(i):getLocalVar("[Ziphius]Bait Trap") == 0) then
GetNPCByID(i):setStatus(tpz.status.DISAPPEAR)
end
end
local vHour = VanadielHour()
if vHour >= 22 or vHour <= 7 then
MISAREAUX_COAST.ziphiusHandleQM()
end
end

Expand Down
80 changes: 80 additions & 0 deletions scripts/zones/Misareaux_Coast/globals.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
-----------------------------------
-- Zone: Misareaux_Coast (25)
-- Desc: this file contains functions that are shared by multiple luas in this zone's directory
-----------------------------------
local ID = require("scripts/zones/Misareaux_Coast/IDs")
require("scripts/globals/npc_util")
-----------------------------------

local MISAREAUX_COAST = {
------------------------------------------
-- Handle spawn/despawn for Ziphius NM QMs
------------------------------------------
ziphiusHandleQM = function()
local vHour = VanadielHour()
if vHour >= 7 and vHour < 22 then -- Despawn traps for Ziphius
for i = ID.npc.ZIPHIUS_QM_BASE, ID.npc.ZIPHIUS_QM_BASE+5 do
GetNPCByID(i):setStatus(tpz.status.DISAPPEAR)
GetNPCByID(i):resetLocalVars()
end
elseif vHour >= 22 or vHour < 4 then -- Spawn traps for Ziphius
local random = GetNPCByID(ID.npc.ZIPHIUS_QM_BASE + math.random(0, 5))
if random:getStatus() == tpz.status.DISAPPEAR then
random:setLocalVar("[Ziphius]Spawn", 1)
end
for i = ID.npc.ZIPHIUS_QM_BASE, ID.npc.ZIPHIUS_QM_BASE+5 do
GetNPCByID(i):setStatus(tpz.status.NORMAL)
end
elseif vHour == 4 then -- Despawn non-baited traps
for i = ID.npc.ZIPHIUS_QM_BASE, ID.npc.ZIPHIUS_QM_BASE+5 do
if GetNPCByID(i):getLocalVar("[Ziphius]Baited") == 0 then
GetNPCByID(i):setStatus(tpz.status.DISAPPEAR)
end
end
end
end,
------------------------------------
-- Trade function for Ziphius NM QMs
------------------------------------
ziphiusOnTrade = function(player, npc, trade)
local baited = npc:getLocalVar("[Ziphius]Baited") == 1
if not baited and npcUtil.tradeHas(trade, 16994) then -- Trade Slice of Carp
npc:setLocalVar("[Ziphius]Bait"..player:getName(), 1)
npc:setLocalVar("[Ziphius]Baited", 1)
player:confirmTrade()
player:messageSpecial(ID.text.PUT_IN_TRAP, 16994)
end
end,
------------------------------------
-- Spawn function for Ziphius NM QMs
------------------------------------
ziphiusOnTrigger = function(player, npc)
local baited = npc:getLocalVar("[Ziphius]Baited") == 1
local baitedByPlayer = npc:getLocalVar("[Ziphius]Bait"..player:getName()) == 1
local vHour = VanadielHour()
if vHour >= 22 or vHour < 4 then
if not baited then
player:messageSpecial(ID.text.APPEARS_TO_BE_TRAP)
elseif baited and baitedByPlayer then
player:messageSpecial(ID.text.NOTHING_HERE_YET)
else
player:messageSpecial(ID.text.ALREADY_BAITED, 16994)
end
elseif vHour >= 4 and vHour < 7 then
if baitedByPlayer then
if npc:getLocalVar("[Ziphius]Spawn") == 1 then
npc:resetLocalVars()
npc:setStatus(tpz.status.DISAPPEAR)
SpawnMob(ID.mob.ZIPHIUS):updateClaim(player)
GetMobByID(ID.mob.ZIPHIUS):setPos(npc:getXPos(), npc:getYPos(), npc:getZPos()-1)
else
player:messageSpecial(ID.text.DID_NOT_CATCH_ANYTHING)
end
else
player:messageSpecial(ID.text.ALREADY_BAITED, 16994)
end
end
end,
}

return MISAREAUX_COAST
47 changes: 4 additions & 43 deletions scripts/zones/Misareaux_Coast/npcs/qm2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,12 @@
-- NPC: ??? (Spawn Ziphius)
-- !pos 76 -16 534 25
-----------------------------------

require("scripts/globals/npc_util")
local ID = require("scripts/zones/Misareaux_Coast/IDs")
local MISAREAUX_COAST = require("scripts/zones/Misareaux_Coast/globals")

function onTrade(player,npc,trade)
local baited = npc:getLocalVar("[Ziphius]Bait Trap")

-- Trade Slice of Carp
if (npcUtil.tradeHas(trade, 16994) and baited == 0) then
npc:setLocalVar("[Ziphius]Bait Trap", 1)
player:confirmTrade()
player:messageSpecial(ID.text.PUT_IN_TRAP, 16994)
else
player:messageSpecial(ID.text.NOTHING_HERE_YET)
end
end
function onTrigger(player,npc)
local baited = npc:getLocalVar("[Ziphius]Bait Trap")

if VanadielHour() >= 22 or VanadielHour() < 4 then
if (baited == 0) then
player:messageSpecial(ID.text.APPEARS_TO_BE_TRAP)
else
player:messageSpecial(ID.text.NOTHING_HERE_YET)
end
elseif VanadielHour() >= 4 and VanadielHour() < 7 then
if (baited == 1) then
if (math.random(1,1000) <= 176) then
SpawnMob(ID.mob.ZIPHIUS):updateClaim(player)
GetMobByID(ID.mob.ZIPHIUS):setPos(npc:getXPos(),npc:getYPos(),npc:getZPos()-1)
npc:setStatus(tpz.status.DISAPPEAR)
else
player:messageSpecial(ID.text.DID_NOT_CATCH_ANYTHING)
end
npc:setLocalVar("[Ziphius]Bait Trap", 0)
else
player:messageSpecial(ID.text.APPEARS_TO_BE_TRAP)
end
end
MISAREAUX_COAST.ziphiusOnTrade(player, npc, trade)
end

function onEventUpdate(player,csid,option)

end

function onEventFinish(player,csid,option)

function onTrigger(player,npc)
MISAREAUX_COAST.ziphiusOnTrigger(player, npc)
end
47 changes: 4 additions & 43 deletions scripts/zones/Misareaux_Coast/npcs/qm3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,12 @@
-- NPC: ??? (Spawn Ziphius)
-- !pos 102.5 -16 525 25
-----------------------------------

require("scripts/globals/npc_util")
local ID = require("scripts/zones/Misareaux_Coast/IDs")
local MISAREAUX_COAST = require("scripts/zones/Misareaux_Coast/globals")

function onTrade(player,npc,trade)
local baited = npc:getLocalVar("[Ziphius]Bait Trap")

-- Trade Slice of Carp
if (npcUtil.tradeHas(trade, 16994) and baited == 0) then
npc:setLocalVar("[Ziphius]Bait Trap", 1)
player:confirmTrade()
player:messageSpecial(ID.text.PUT_IN_TRAP, 16994)
else
player:messageSpecial(ID.text.NOTHING_HERE_YET)
end
end
function onTrigger(player,npc)
local baited = npc:getLocalVar("[Ziphius]Bait Trap")

if VanadielHour() >= 22 or VanadielHour() < 4 then
if (baited == 0) then
player:messageSpecial(ID.text.APPEARS_TO_BE_TRAP)
else
player:messageSpecial(ID.text.NOTHING_HERE_YET)
end
elseif VanadielHour() >= 4 and VanadielHour() < 7 then
if (baited == 1) then
if (math.random(1,1000) <= 176) then
SpawnMob(ID.mob.ZIPHIUS):updateClaim(player)
GetMobByID(ID.mob.ZIPHIUS):setPos(npc:getXPos(),npc:getYPos(),npc:getZPos()-1)
npc:setStatus(tpz.status.DISAPPEAR)
else
player:messageSpecial(ID.text.DID_NOT_CATCH_ANYTHING)
end
npc:setLocalVar("[Ziphius]Bait Trap", 0)
else
player:messageSpecial(ID.text.APPEARS_TO_BE_TRAP)
end
end
MISAREAUX_COAST.ziphiusOnTrade(player, npc, trade)
end

function onEventUpdate(player,csid,option)

end

function onEventFinish(player,csid,option)

function onTrigger(player,npc)
MISAREAUX_COAST.ziphiusOnTrigger(player, npc)
end
47 changes: 4 additions & 43 deletions scripts/zones/Misareaux_Coast/npcs/qm4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,12 @@
-- NPC: ??? (Spawn Ziphius)
-- !pos 144.5 -16 520 25
-----------------------------------

require("scripts/globals/npc_util")
local ID = require("scripts/zones/Misareaux_Coast/IDs")
local MISAREAUX_COAST = require("scripts/zones/Misareaux_Coast/globals")

function onTrade(player,npc,trade)
local baited = npc:getLocalVar("[Ziphius]Bait Trap")

-- Trade Slice of Carp
if (npcUtil.tradeHas(trade, 16994) and baited == 0) then
npc:setLocalVar("[Ziphius]Bait Trap", 1)
player:confirmTrade()
player:messageSpecial(ID.text.PUT_IN_TRAP, 16994)
else
player:messageSpecial(ID.text.NOTHING_HERE_YET)
end
end
function onTrigger(player,npc)
local baited = npc:getLocalVar("[Ziphius]Bait Trap")

if VanadielHour() >= 22 or VanadielHour() < 4 then
if (baited == 0) then
player:messageSpecial(ID.text.APPEARS_TO_BE_TRAP)
else
player:messageSpecial(ID.text.NOTHING_HERE_YET)
end
elseif VanadielHour() >= 4 and VanadielHour() < 7 then
if (baited == 1) then
if (math.random(1,1000) <= 176) then
SpawnMob(ID.mob.ZIPHIUS):updateClaim(player)
GetMobByID(ID.mob.ZIPHIUS):setPos(npc:getXPos(),npc:getYPos(),npc:getZPos()-1)
npc:setStatus(tpz.status.DISAPPEAR)
else
player:messageSpecial(ID.text.DID_NOT_CATCH_ANYTHING)
end
npc:setLocalVar("[Ziphius]Bait Trap", 0)
else
player:messageSpecial(ID.text.APPEARS_TO_BE_TRAP)
end
end
MISAREAUX_COAST.ziphiusOnTrade(player, npc, trade)
end

function onEventUpdate(player,csid,option)

end

function onEventFinish(player,csid,option)

function onTrigger(player,npc)
MISAREAUX_COAST.ziphiusOnTrigger(player, npc)
end
47 changes: 4 additions & 43 deletions scripts/zones/Misareaux_Coast/npcs/qm5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,12 @@
-- NPC: ??? (Spawn Ziphius)
-- !pos 184.5 -16 517.5 25
-----------------------------------

require("scripts/globals/npc_util")
local ID = require("scripts/zones/Misareaux_Coast/IDs")
local MISAREAUX_COAST = require("scripts/zones/Misareaux_Coast/globals")

function onTrade(player,npc,trade)
local baited = npc:getLocalVar("[Ziphius]Bait Trap")

-- Trade Slice of Carp
if (npcUtil.tradeHas(trade, 16994) and baited == 0) then
npc:setLocalVar("[Ziphius]Bait Trap", 1)
player:confirmTrade()
player:messageSpecial(ID.text.PUT_IN_TRAP, 16994)
else
player:messageSpecial(ID.text.NOTHING_HERE_YET)
end
end
function onTrigger(player,npc)
local baited = npc:getLocalVar("[Ziphius]Bait Trap")

if VanadielHour() >= 22 or VanadielHour() < 4 then
if (baited == 0) then
player:messageSpecial(ID.text.APPEARS_TO_BE_TRAP)
else
player:messageSpecial(ID.text.NOTHING_HERE_YET)
end
elseif VanadielHour() >= 4 and VanadielHour() < 7 then
if (baited == 1) then
if (math.random(1,1000) <= 176) then
SpawnMob(ID.mob.ZIPHIUS):updateClaim(player)
GetMobByID(ID.mob.ZIPHIUS):setPos(npc:getXPos(),npc:getYPos(),npc:getZPos()-1)
npc:setStatus(tpz.status.DISAPPEAR)
else
player:messageSpecial(ID.text.DID_NOT_CATCH_ANYTHING)
end
npc:setLocalVar("[Ziphius]Bait Trap", 0)
else
player:messageSpecial(ID.text.APPEARS_TO_BE_TRAP)
end
end
MISAREAUX_COAST.ziphiusOnTrade(player, npc, trade)
end

function onEventUpdate(player,csid,option)

end

function onEventFinish(player,csid,option)

function onTrigger(player,npc)
MISAREAUX_COAST.ziphiusOnTrigger(player, npc)
end
Loading

0 comments on commit 78a0aa3

Please sign in to comment.