2022-01-25 22:54:44 -05:00
require ( " global " ) ;
--[[
Populace Standard Script
Functions :
eventSwitch ( questId1 , questId2 , questId3 , questId4 , currentPage , maxPages , titleId ) - Shows a dialog box with which quest to trigger
when more than one quest is active for this npc .
Notes :
This scripts fires for all normal standard ENpcs in the world . Because of how the FFXIV dialog system works , everything is technically
a quest ; including the DefaultTalk responses . This script checks both static default quests and any relevant ones for that actor class
id . If only one exists ; it is automatically triggered otherwise a dialog box will appear for the player to choose what quest to do .
--]]
2019-06-19 01:10:15 -04:00
function init ( npc )
return false , false , 0 , 0 ;
end
2022-01-25 22:54:44 -05:00
function onEventStarted ( player , npc , eventType , eventName )
local defaultTalk = player : GetDefaultTalkQuest ( npc ) ;
2022-02-16 15:32:54 -05:00
local tutorialTalk = player : GetTutorialQuest ( npc ) ;
2022-01-25 22:54:44 -05:00
local activeQuests = player : GetQuestsForNpc ( npc ) ;
local possibleQuests = { } ;
-- Create the switch table for this npc
2022-02-07 05:13:34 -05:00
if ( defaultTalk ~= nil and eventType == ETYPE_TALK ) then
2022-01-25 22:54:44 -05:00
table.insert ( possibleQuests , defaultTalk ) ;
end
2022-02-07 05:13:34 -05:00
if ( tutorialTalk ~= nil and eventType == ETYPE_TALK ) then
2022-01-25 22:54:44 -05:00
table.insert ( possibleQuests , tutorialTalk ) ;
end
if ( activeQuests ~= nil ) then
table.insert ( possibleQuests , unpack ( activeQuests ) ) ;
end
-- Either let the player choose the quest or start it if it's the only one.
local chosenQuest = nil ;
if ( # possibleQuests > 1 ) then
local currentPage = 0 ;
local numPages = math.floor ( ( # possibleQuests - 1 ) / 4 ) + 1 ;
while ( true ) do
local page , index = callClientFunction ( player , " switchEvent " , possibleQuests [ currentPage * 4 + 1 ] , possibleQuests [ currentPage * 4 + 2 ] , possibleQuests [ currentPage * 4 + 3 ] , possibleQuests [ currentPage * 4 + 4 ] , currentPage + 1 , numPages , 0x3F1 ) ;
if ( page == 0 ) then
chosenQuest = possibleQuests [ ( currentPage * 4 ) + index ] ;
break ;
elseif ( page > 0 ) then
currentPage = page - 1 ;
else
player : EndEvent ( ) ;
return ;
end
end
elseif ( # possibleQuests == 1 ) then
chosenQuest = possibleQuests [ 1 ] ;
end
-- Run the quest event or tell the devs it's missing.
if ( chosenQuest ~= nil ) then
doQuestEvent ( player , npc , chosenQuest , eventType , eventName ) ;
else
local msg = string.format ( " ERROR: This PopulaceStandard actor has no defaultTalk or quest set. \n Actor Class Id: %s \n Event Name: %s " , tostring ( npc : GetActorClassId ( ) ) , eventName ) ;
printf ( msg ) ;
player : SendMessage ( 0x20 , " " , msg ) ;
player : EndEvent ( ) ;
end
2019-06-19 01:10:15 -04:00
end
2022-01-25 22:54:44 -05:00
function doQuestEvent ( player , npc , quest , eventType , eventName )
if ( eventType == 0 ) then
quest : OnCommand ( player , npc , eventName ) ;
elseif ( eventType == 1 ) then
quest : OnTalk ( player , npc ) ;
elseif ( eventType == 2 ) then
quest : OnPush ( player , npc , eventName ) ;
elseif ( eventType == 3 ) then
quest : OnEmote ( player , npc , eventName ) ;
elseif ( eventType == 5 ) then
quest : OnNotice ( player , npc , eventName ) ;
end
2019-06-19 01:10:15 -04:00
end