Skip to content

Commit

Permalink
[module] Add another custom NPC example (with a paginated menu)
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Oct 17, 2023
1 parent 2d5c912 commit c55c969
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions modules/custom/lua/test_npcs_in_gm_home.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,59 @@ require('scripts/zones/GM_Home/Zone')
-----------------------------------
local m = Module:new('test_npcs_in_gm_home')

-- Forward declarations (required)
local menu = {}
local page1 = {}
local page2 = {}

-- We need just a tiny delay to let the previous menu context be cleared out
-- 'New pages' are actually just whole new menus!
local delaySendMenu = function(player)
player:timer(50, function(playerArg)
playerArg:customMenu(menu)
end)
end

menu =
{
title = 'Test Menu (Paginated)',
options = {},
}

page1 =
{
{
'Send me to Jeuno!',
function(playerArg)
playerArg:setPos(0, 0, 0, 0, xi.zone.LOWER_JEUNO)
end,
},
{
'Next Page',
function(playerArg)
menu.options = page2
delaySendMenu(playerArg)
end,
},
}

page2 =
{
{
'Send me to Aht Urghan!',
function(playerArg)
playerArg:setPos(0, 0, 0, 0, xi.zone.AHT_URHGAN_WHITEGATE)
end,
},
{
'Previous Page',
function(playerArg)
menu.options = page1
delaySendMenu(playerArg)
end,
},
}

m:addOverride('xi.zones.GM_Home.Zone.onInitialize', function(zone)
-- Call the zone's original function for onInitialize
super(zone)
Expand Down Expand Up @@ -67,6 +120,22 @@ m:addOverride('xi.zones.GM_Home.Zone.onInitialize', function(zone)

-- You could also just not capture the object
-- zone:insertDynamicEntity({ ...

-- Menu NPC Example
zone:insertDynamicEntity({
objtype = xi.objType.NPC,
name = 'Menu Example',
look = 2433,
x = 5.000,
y = 0.000,
z = 5.000,
rotation = 0,
widescan = 1,
onTrigger = function(player, npc)
menu.options = page1
delaySendMenu(player)
end,
})
end)

return m

0 comments on commit c55c969

Please sign in to comment.