From 224d721ed424c2003c8b854a7a235d4fba041ee3 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 13 Mar 2024 22:00:30 -0300 Subject: [PATCH] fix: vip functions --- data-otservbr-global/lib/others/load.lua | 1 - .../lib/others/vip_system.lua | 67 ------------------- data/libs/systems/load.lua | 1 + data/libs/systems/vip.lua | 62 +++++++++++++++++ 4 files changed, 63 insertions(+), 68 deletions(-) delete mode 100644 data-otservbr-global/lib/others/vip_system.lua create mode 100644 data/libs/systems/vip.lua diff --git a/data-otservbr-global/lib/others/load.lua b/data-otservbr-global/lib/others/load.lua index 1052efb7bd6..031c8fb2026 100644 --- a/data-otservbr-global/lib/others/load.lua +++ b/data-otservbr-global/lib/others/load.lua @@ -1,2 +1 @@ dofile(DATA_DIRECTORY .. "/lib/others/dawnport.lua") -dofile(DATA_DIRECTORY .. "/lib/others/vip_system.lua") diff --git a/data-otservbr-global/lib/others/vip_system.lua b/data-otservbr-global/lib/others/vip_system.lua deleted file mode 100644 index 5a393157c8c..00000000000 --- a/data-otservbr-global/lib/others/vip_system.lua +++ /dev/null @@ -1,67 +0,0 @@ -local config = { - activationMessage = "You have received %s VIP days.", - activationMessageType = MESSAGE_EVENT_ADVANCE, - - expirationMessage = "Your VIP days ran out.", - expirationMessageType = MESSAGE_ADMINISTRATOR, - - outfits = {}, - mounts = {}, -} - -function Player.onRemoveVip(self) - self:sendTextMessage(config.expirationMessageType, config.expirationMessage) - - for _, outfit in ipairs(config.outfits) do - self:removeOutfit(outfit) - end - - for _, mount in ipairs(config.mounts) do - self:removeMount(mount) - end - - local playerOutfit = self:getOutfit() - if table.contains(config.outfits, self:getOutfit().lookType) then - if self:getSex() == PLAYERSEX_FEMALE then - playerOutfit.lookType = 136 - else - playerOutfit.lookType = 128 - end - playerOutfit.lookAddons = 0 - self:setOutfit(playerOutfit) - end - - self:kv():scoped("account"):remove("vip-system") -end - -function Player.onAddVip(self, days, silent) - if not silent then - self:sendTextMessage(config.activationMessageType, string.format(config.activationMessage, days)) - end - - for _, outfit in ipairs(config.outfits) do - self:addOutfitAddon(outfit, 3) - end - - for _, mount in ipairs(config.mounts) do - self:addMount(mount) - end - - self:kv():scoped("account"):set("vip-system", true) -end - -function CheckPremiumAndPrint(player, msgType) - if player:getVipDays() == 0xFFFF then - player:sendTextMessage(msgType, "You have infinite amount of VIP days left.") - return true - end - - local playerVipTime = player:getVipTime() - if playerVipTime < os.time() then - local msg = "You do not have VIP on your account." - player:sendTextMessage(msgType, msg) - return true - end - - player:sendTextMessage(msgType, string.format("You have %s of VIP time left.", getFormattedTimeRemaining(playerVipTime))) -end diff --git a/data/libs/systems/load.lua b/data/libs/systems/load.lua index 5c7073ad64e..281b8b1d466 100644 --- a/data/libs/systems/load.lua +++ b/data/libs/systems/load.lua @@ -9,4 +9,5 @@ dofile(CORE_DIRECTORY .. "/libs/systems/hazard.lua") dofile(CORE_DIRECTORY .. "/libs/systems/hireling.lua") dofile(CORE_DIRECTORY .. "/libs/systems/raids.lua") dofile(CORE_DIRECTORY .. "/libs/systems/reward_boss.lua") +dofile(CORE_DIRECTORY .. "/libs/systems/vip.lua") dofile(CORE_DIRECTORY .. "/libs/systems/zones.lua") diff --git a/data/libs/systems/vip.lua b/data/libs/systems/vip.lua new file mode 100644 index 00000000000..cdf749d2084 --- /dev/null +++ b/data/libs/systems/vip.lua @@ -0,0 +1,62 @@ +-- Bonus mount and outfits +local outfits = {} +local mounts = {} + +function Player.onRemoveVip(self) + self:sendTextMessage(MESSAGE_ADMINISTRATOR, "Your VIP days ran out.") + + for _, outfit in ipairs(outfits) do + self:removeOutfit(outfit) + end + + for _, mount in ipairs(mounts) do + self:removeMount(mount) + end + + local playerOutfit = self:getOutfit() + if table.contains(outfits, self:getOutfit().lookType) then + if self:getSex() == PLAYERSEX_FEMALE then + playerOutfit.lookType = 136 + else + playerOutfit.lookType = 128 + end + + playerOutfit.lookAddons = 0 + self:setOutfit(playerOutfit) + end + + self:kv():scoped("account"):remove("vip-system") +end + +function Player.onAddVip(self, days, silent) + if not silent then + self:sendTextMessage(MESSAGE_ADMINISTRATOR, "You have received " .. days .. " VIP days.") + end + + for _, outfit in ipairs(outfits) do + self:addOutfitAddon(outfit, 3) + end + + for _, mount in ipairs(mounts) do + self:addMount(mount) + end + + self:kv():scoped("account"):set("vip-system", true) +end + +function CheckPremiumAndPrint(player, msgType) + local msg = "" + + if player:getVipDays() == 0xFFFF then + msg = "You have infinite amount of VIP days left." + else + local playerVipTime = player:getVipTime() + if playerVipTime < os.time() then + msg = "You do not have VIP on your account." + else + msg = "You have " .. getFormattedTimeRemaining(playerVipTime) .. " of VIP time left." + end + end + + player:sendTextMessage(MESSAGE_ADMINISTRATOR, msg) +end