From 2f1278cb7caa22574613aa56e8c1bb334bbd7547 Mon Sep 17 00:00:00 2001 From: gasaichandesu Date: Wed, 19 Aug 2026 21:38:56 +0400 Subject: [PATCH] fix(premium): allow to spawn only one squire per player --- lua_scripts/MWPremium/mwpremium.lua | 44 ++++++++++++++++++----------- sql/Premium/world.sql | 2 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/lua_scripts/MWPremium/mwpremium.lua b/lua_scripts/MWPremium/mwpremium.lua index 5600f9d97..f2f40d59e 100644 --- a/lua_scripts/MWPremium/mwpremium.lua +++ b/lua_scripts/MWPremium/mwpremium.lua @@ -13,6 +13,9 @@ local SQUIRE_CREATURE_TEMPLATE_ID = 9000001 local NPC_TEXT_ID = 10000000 +local premiums_table = {} +local squires_table = {} + ---todo extract to utils ---@param inputstr string ---@param separator string @@ -30,7 +33,7 @@ end ---@return boolean local function IsPremium(player) - return player:HasFlag(PREMIUM_FLAG_INDEX, 1) + return premiums_table[player:GetAccountId()] == true end local function OnPremiumPlayer(player) @@ -58,7 +61,7 @@ local function RefreshPremiumStatus(player) local flags = query:GetUInt32(0) if HasFlag(flags, ACCOUNT_FLAG_RECURRING_BILLING) then - player:SetFlag(PREMIUM_FLAG_INDEX, 1) + premiums_table[player:GetAccountId()] = true OnPremiumPlayer(player) @@ -108,7 +111,16 @@ end local function OnSummonSquireCast(player) local x, y, z, o = player:GetLocation() + if (squires_table[player:GetGUIDLow()] ~= nil) then + local existing_squire = player:GetMap():GetWorldObject(squires_table[player:GetGUIDLow()]) + if (existing_squire ~= nil) then + existing_squire:DespawnOrUnsummon() + end + end + local squire = player:SpawnCreature(SQUIRE_CREATURE_TEMPLATE_ID, x + 1, y + 1, z, o, 1, 30000) + squires_table[player:GetGUIDLow()] = squire:GetGUID() + print(squires_table[player:GetGUIDLow()]) if squire then squire:SetFaction(player:GetFaction()) @@ -141,26 +153,27 @@ local function OnGossipSelect(event, player, creature, sender, intid, code) player:GossipComplete() end - if intid == 2 then - player:SendShowBank(creature) - player:GossipComplete() - end + if intid == 2 then + player:SendShowBank(creature) + player:GossipComplete() + end - if intid == 3 then - player:SendAuctionMenu(creature) - player:GossipComplete() - end + if intid == 3 then + player:SendAuctionMenu(creature) + player:GossipComplete() + end - if intid == 4 then - player:DurabilityRepairAll() - player:PlayDirectSound(1116) - player:GossipComplete() - end + if intid == 4 then + player:DurabilityRepairAll() + player:PlayDirectSound(1116) + player:GossipComplete() + end end end local function OnLogout(event, player) player:RemoveSpell(SUMMON_SQUIRE_SPELL_ID) + squires_table[player:GetGUID()] = nil end RegisterCreatureGossipEvent(SQUIRE_CREATURE_TEMPLATE_ID, 1, OnGossipHello) @@ -169,4 +182,3 @@ RegisterPlayerEvent(PLAYER_EVENT_ON_LOGIN, OnLogin) RegisterPlayerEvent(PLAYER_EVENT_ON_LOGOUT, OnLogout) RegisterPlayerEvent(PLAYER_EVENT_ON_COMMAND, OnCommand) RegisterPlayerEvent(PLAYER_EVENT_ON_SPELL_CAST, OnSpellCast) - diff --git a/sql/Premium/world.sql b/sql/Premium/world.sql index 221979176..96169402b 100644 --- a/sql/Premium/world.sql +++ b/sql/Premium/world.sql @@ -97,7 +97,7 @@ VALUES 0, 1163, 1524, -'SmartAI', +'PassiveAI', 0, 1.0, 4.0,