Skip to content

Commit

Permalink
refactor: enhance VIP status handling and improve clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Oct 29, 2024
1 parent b0cb6b7 commit 8c2b873
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
12 changes: 6 additions & 6 deletions data/libs/systems/vip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions data/scripts/creaturescripts/player/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions data/scripts/talkactions/player/vip.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 8c2b873

Please sign in to comment.