fix(premium): allow to spawn only one squire per player

This commit is contained in:
gasaichandesu
2026-08-19 21:38:56 +04:00
parent f8177f5ac4
commit 2f1278cb7c
2 changed files with 29 additions and 17 deletions
+28 -16
View File
@@ -13,6 +13,9 @@ local SQUIRE_CREATURE_TEMPLATE_ID = 9000001
local NPC_TEXT_ID = 10000000 local NPC_TEXT_ID = 10000000
local premiums_table = {}
local squires_table = {}
---todo extract to utils ---todo extract to utils
---@param inputstr string ---@param inputstr string
---@param separator string ---@param separator string
@@ -30,7 +33,7 @@ end
---@return boolean ---@return boolean
local function IsPremium(player) local function IsPremium(player)
return player:HasFlag(PREMIUM_FLAG_INDEX, 1) return premiums_table[player:GetAccountId()] == true
end end
local function OnPremiumPlayer(player) local function OnPremiumPlayer(player)
@@ -58,7 +61,7 @@ local function RefreshPremiumStatus(player)
local flags = query:GetUInt32(0) local flags = query:GetUInt32(0)
if HasFlag(flags, ACCOUNT_FLAG_RECURRING_BILLING) then if HasFlag(flags, ACCOUNT_FLAG_RECURRING_BILLING) then
player:SetFlag(PREMIUM_FLAG_INDEX, 1) premiums_table[player:GetAccountId()] = true
OnPremiumPlayer(player) OnPremiumPlayer(player)
@@ -108,7 +111,16 @@ end
local function OnSummonSquireCast(player) local function OnSummonSquireCast(player)
local x, y, z, o = player:GetLocation() 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) 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 if squire then
squire:SetFaction(player:GetFaction()) squire:SetFaction(player:GetFaction())
@@ -141,26 +153,27 @@ local function OnGossipSelect(event, player, creature, sender, intid, code)
player:GossipComplete() player:GossipComplete()
end end
if intid == 2 then if intid == 2 then
player:SendShowBank(creature) player:SendShowBank(creature)
player:GossipComplete() player:GossipComplete()
end end
if intid == 3 then if intid == 3 then
player:SendAuctionMenu(creature) player:SendAuctionMenu(creature)
player:GossipComplete() player:GossipComplete()
end end
if intid == 4 then if intid == 4 then
player:DurabilityRepairAll() player:DurabilityRepairAll()
player:PlayDirectSound(1116) player:PlayDirectSound(1116)
player:GossipComplete() player:GossipComplete()
end end
end end
end end
local function OnLogout(event, player) local function OnLogout(event, player)
player:RemoveSpell(SUMMON_SQUIRE_SPELL_ID) player:RemoveSpell(SUMMON_SQUIRE_SPELL_ID)
squires_table[player:GetGUID()] = nil
end end
RegisterCreatureGossipEvent(SQUIRE_CREATURE_TEMPLATE_ID, 1, OnGossipHello) 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_LOGOUT, OnLogout)
RegisterPlayerEvent(PLAYER_EVENT_ON_COMMAND, OnCommand) RegisterPlayerEvent(PLAYER_EVENT_ON_COMMAND, OnCommand)
RegisterPlayerEvent(PLAYER_EVENT_ON_SPELL_CAST, OnSpellCast) RegisterPlayerEvent(PLAYER_EVENT_ON_SPELL_CAST, OnSpellCast)
+1 -1
View File
@@ -97,7 +97,7 @@ VALUES
0, 0,
1163, 1163,
1524, 1524,
'SmartAI', 'PassiveAI',
0, 0,
1.0, 1.0,
4.0, 4.0,