From debb06216b49b528cfbeac9805dedde54ed03f56 Mon Sep 17 00:00:00 2001 From: KnowOne Date: Wed, 26 Feb 2025 21:25:20 -0600 Subject: [PATCH] all in 1 quest command for IF --- scripts/commands/quest.lua | 154 +++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 scripts/commands/quest.lua diff --git a/scripts/commands/quest.lua b/scripts/commands/quest.lua new file mode 100644 index 00000000000..2b7544831df --- /dev/null +++ b/scripts/commands/quest.lua @@ -0,0 +1,154 @@ +----------------------------------- +-- func: quest optional , logid and quest ids work by numbers or string.format +-- desc: quest command built with menu control, can add/delete/complete quests, see status, +-- see vars in the IF format of 'Prog', 'Option', 'Stage', 'Wait'. +-- Can clear vars in the IF format +----------------------------------- +local logIdHelpers = require('scripts/globals/log_ids') +----------------------------------- + +---@type TCommand +local commandObj = {} + +commandObj.cmdprops = +{ + permission = 1, + parameters = 'sss' +} + +local function error(player, msg) + player:printToPlayer(msg) + player:printToPlayer('!quest {player}', xi.msg.channel.NS_LINKSHELL3) +end + +commandObj.onTrigger = function(player, logId, questId, target) + -- validate logId + local questLog = logIdHelpers.getQuestLogInfo(logId) + if questLog == nil then + error(player, 'Invalid logID.') + return + end + + local logName = questLog.full_name + logId = questLog.quest_log + + -- validate questId + local areaQuestIds = xi.quest.id[xi.quest.area[logId]] + if questId ~= nil then + questId = tonumber(questId) or areaQuestIds[string.upper(questId)] + end + + if questId == nil or questId < 0 then + error(player, 'Invalid questID.') + return + end + + -- validate target + local targ + if target == nil then + targ = player:getCursorTarget() + if targ == nil or not targ:isPC() then + targ = player + end + else + targ = GetPlayerByName(target) + if targ == nil then + error(player, string.format('Player named %s not found!', target, xi.msg.channel.NS_LINKSHELL3)) + return + end + end + + local status = targ:getQuestStatus(logId, questId) + + local menu = + { + title = 'Quest Menu', + onStart = function(playerArg) + local statusName = 'Error' + switch (status): caseof + { + [0] = function(x) + statusName = 'AVAILABLE' + end, + + [1] = function(x) + statusName = 'ACCEPTED' + end, + + [2] = function(x) + statusName = 'COMPLETED' + end, + } + playerArg:printToPlayer(string.format('Player %s status for %s quest ID %i is: %s', targ:getName(), logName, questId, statusName), xi.msg.channel.NS_LINKSHELL3) + playerArg:printToPlayer(string.format('Player %s variables for %s Quest %i are', targ:getName(), logName, questId), xi.msg.channel.NS_LINKSHELL3) + playerArg:printToPlayer(string.format('Prog: %i, Stage: %i, Option: %i, Wait %i', xi.quest.getVar(targ, logId, questId, 'Prog'), + xi.quest.getVar(targ, logId, questId, 'Stage'), xi.quest.getVar(targ, logId, questId, 'Option'), xi.quest.getVar(targ, logId, questId, 'Wait')), xi.msg.channel.NS_LINKSHELL3) + end, + + options = + { + { + 'Add Quest', + function(playerArg) + if status == xi.questStatus.QUEST_ACCEPTED then + playerArg:printToPlayer(string.format('Quest %s %i is already Accepted on %s', logName, questId, targ:getName()), xi.msg.channel.NS_LINKSHELL3) + return + elseif status == xi.questStatus.QUEST_COMPLETED then + targ:delQuest(logId, questId) + playerArg:printToPlayer(string.format('Quest was in Completed status'), xi.msg.channel.NS_LINKSHELL3) + end + + targ:addQuest(logId, questId) + playerArg:printToPlayer(string.format('Added %s quest %i to %s.', logName, questId, targ:getName()), xi.msg.channel.NS_LINKSHELL3) + end, + }, + { + 'Complete Quest', + function(playerArg) + if status == xi.questStatus.QUEST_COMPLETED then + playerArg:printToPlayer(string.format('Quest %s %i is already Completed', logName, questId), xi.msg.channel.NS_LINKSHELL3) + return + elseif status == xi.questStatus.QUEST_AVAILABLE then + targ:addQuest(logId, questId) + playerArg:printToPlayer(string.format('Quest was in the Available status'), xi.msg.channel.NS_LINKSHELL3) + end + + targ:completeQuest(logId, questId) + playerArg:printToPlayer(string.format('Completed %s Quest with ID %u for %s', logName, questId, targ:getName()), xi.msg.channel.NS_LINKSHELL3) + end, + }, + { + 'Delete Quest', + function(playerArg) + if status == xi.questStatus.QUEST_AVAILABLE then + playerArg:printToPlayer(string.format('Quest %s %i is already in Available status', logName, questId), xi.msg.channel.NS_LINKSHELL3) + return + end + + targ:delQuest(logId, questId) + playerArg:printToPlayer(string.format('Deleted %s quest %i from %s.', logName, questId, targ:getName()), xi.msg.channel.NS_LINKSHELL3) + end, + }, + { + 'Clear Vars', + function(playerArg) + xi.quest.setVar(targ, logId, questId, 'Prog', 0) + xi.quest.setVar(targ, logId, questId, 'Stage', 0) + xi.quest.setVar(targ, logId, questId, 'Option', 0) + xi.quest.setVar(targ, logId, questId, 'Wait', 0) + playerArg:printToPlayer(string.format('Player %s variables for %s Quest %i are cleared', targ:getName(), logName, questId), xi.msg.channel.NS_LINKSHELL3) + end, + }, + }, + + onCancelled = function(playerArg) + playerArg:printToPlayer('Quest Menu Cancelled', xi.msg.channel.NS_LINKSHELL3) + end, + + onEnd = function(playerArg) + end, + } + player:customMenu(menu) +end + +return commandObj