From 8c2b873074308af441aa2bdec6b4931fff6ba3a0 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 29 Oct 2024 16:41:28 -0300 Subject: [PATCH] refactor: enhance VIP status handling and improve clarity --- data/libs/systems/vip.lua | 12 ++++++------ data/scripts/creaturescripts/player/login.lua | 12 ++++++------ data/scripts/talkactions/player/vip.lua | 8 +++----- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/data/libs/systems/vip.lua b/data/libs/systems/vip.lua index 9e76fd8ad80..49ef7bcf8cc 100644 --- a/data/libs/systems/vip.lua +++ b/data/libs/systems/vip.lua @@ -45,17 +45,17 @@ function Player.onAddVip(self, days, silent) self:kv():scoped("account"):set("vip-system", true) end -function CheckPremiumAndPrint(player, msgType) - if player:getVipDays() == 0xFFFF then - player:sendTextMessage(msgType, "You have an unlimited VIP status.") +function Player.sendVipStatus(self) + if self:getVipDays() == 0xFFFF then + self:sendTextMessage(MESSAGE_LOGIN, "You have unlimited VIP status.") return true end - local playerVipTime = player:getVipTime() + local playerVipTime = self:getVipTime() if playerVipTime < os.time() then - player:sendTextMessage(msgType, "Your VIP status is currently inactive.") + self:sendTextMessage(MESSAGE_STATUS, "Your VIP status is currently inactive.") return true end - player:sendTextMessage(msgType, string.format("You have %s of VIP time remaining.", getFormattedTimeRemaining(playerVipTime))) + self:sendTextMessage(MESSAGE_LOGIN, string.format("You have %s of VIP time remaining.", getFormattedTimeRemaining(playerVipTime))) end diff --git a/data/scripts/creaturescripts/player/login.lua b/data/scripts/creaturescripts/player/login.lua index 5f9f0e695f4..20049d87621 100644 --- a/data/scripts/creaturescripts/player/login.lua +++ b/data/scripts/creaturescripts/player/login.lua @@ -118,19 +118,19 @@ function playerLoginGlobal.onLogin(player) -- Updates the player's VIP status and executes corresponding actions if applicable. if configManager.getBoolean(configKeys.VIP_SYSTEM_ENABLED) then - local isVipNow = player:isVip() - local wasVip = player:kv():scoped("account"):get("vip-system") or false + local isCurrentlyVip = player:isVip() + local hadVipStatus = player:kv():scoped("account"):get("vip-system") or false - if wasVip ~= isVipNow then - if wasVip then + if hadVipStatus ~= isCurrentlyVip then + if hadVipStatus then player:onRemoveVip() else player:onAddVip(player:getVipDays()) end end - if isVipNow then - CheckPremiumAndPrint(player, MESSAGE_LOGIN) + if isCurrentlyVip then + player:sendVipStatus() end end diff --git a/data/scripts/talkactions/player/vip.lua b/data/scripts/talkactions/player/vip.lua index 65ca4be99f8..a80f6dd54dc 100644 --- a/data/scripts/talkactions/player/vip.lua +++ b/data/scripts/talkactions/player/vip.lua @@ -1,12 +1,10 @@ local vip = TalkAction("!checkvip", "!vip") function vip.onSay(player, words, param) - if not player:isVip() then - local msg = "You do not have VIP on your account." - player:sendCancelMessage(msg) - player:sendTextMessage(MESSAGE_STATUS, msg) + if player:isVip() then + player:sendVipStatus() else - CheckPremiumAndPrint(player, MESSAGE_STATUS) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have VIP on your account.") end return true end