From f5b02d1d4dc32f5af3d956c46ecdcc3129d8010f Mon Sep 17 00:00:00 2001 From: WinterSolstice8 <60417494+wintersolstice8@users.noreply.github.com> Date: Fri, 17 Jan 2025 22:04:39 -0700 Subject: [PATCH 1/2] [lua] [core] add optional arg to setAnimationSub to not send packet --- scripts/specs/core/CBaseEntity.lua | 3 ++- src/map/lua/lua_baseentity.cpp | 13 +++++++++---- src/map/lua/lua_baseentity.h | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/specs/core/CBaseEntity.lua b/scripts/specs/core/CBaseEntity.lua index ad1f2355b00..91b38af357b 100644 --- a/scripts/specs/core/CBaseEntity.lua +++ b/scripts/specs/core/CBaseEntity.lua @@ -1202,8 +1202,9 @@ function CBaseEntity:getAnimationSub() end ---@param animationsub integer +---@param sendUpdate boolean? ---@return nil -function CBaseEntity:setAnimationSub(animationsub) +function CBaseEntity:setAnimationSub(animationsub, sendUpdate) end ---@nodiscard diff --git a/src/map/lua/lua_baseentity.cpp b/src/map/lua/lua_baseentity.cpp index 35140597870..77403dd3f15 100644 --- a/src/map/lua/lua_baseentity.cpp +++ b/src/map/lua/lua_baseentity.cpp @@ -5503,21 +5503,26 @@ uint8 CLuaBaseEntity::getAnimationSub() * Function: setAnimationSub() * Purpose : Returns animation sub for an entity or updates if var supplied * Example : - * Notes : + * Notes : sendUpdate is true by default (false is the edge case.) ************************************************************************/ -void CLuaBaseEntity::setAnimationSub(uint8 animationsub) +void CLuaBaseEntity::setAnimationSub(uint8 animationsub, sol::object const& sendUpdate) { if (m_PBaseEntity->animationsub != animationsub) { + bool sendPacket = (sendUpdate != sol::lua_nil) ? sendUpdate.as() : true; + m_PBaseEntity->animationsub = animationsub; if (m_PBaseEntity->objtype == TYPE_PC) { auto* PChar = static_cast(m_PBaseEntity); - PChar->pushPacket(PChar); + if (sendPacket) + { + PChar->pushPacket(PChar); + } } - else + else if (sendPacket) { m_PBaseEntity->loc.zone->UpdateEntityPacket(m_PBaseEntity, ENTITY_UPDATE, UPDATE_COMBAT); } diff --git a/src/map/lua/lua_baseentity.h b/src/map/lua/lua_baseentity.h index 7ea05330695..6a2ce651205 100644 --- a/src/map/lua/lua_baseentity.h +++ b/src/map/lua/lua_baseentity.h @@ -290,7 +290,7 @@ class CLuaBaseEntity uint8 getAnimation(); void setAnimation(uint8 animation); uint8 getAnimationSub(); - void setAnimationSub(uint8 animationsub); + void setAnimationSub(uint8 animationsub, sol::object const& sendUpdate); bool getCallForHelpFlag() const; void setCallForHelpFlag(bool cfh); bool getCallForHelpBlocked() const; From 511f89721fedb04339678530f8e4d4f82429c9a5 Mon Sep 17 00:00:00 2001 From: WinterSolstice8 <60417494+wintersolstice8@users.noreply.github.com> Date: Fri, 17 Jan 2025 22:35:43 -0700 Subject: [PATCH 2/2] [lua] Small FoV treasure casket adjustments * Allow for "no" and "do not want item" option * Fix despawn not working --- scripts/globals/caskets.lua | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/scripts/globals/caskets.lua b/scripts/globals/caskets.lua index c96d548e9ba..007ef0fe22e 100644 --- a/scripts/globals/caskets.lua +++ b/scripts/globals/caskets.lua @@ -217,9 +217,9 @@ end -- Desc: Despawn a chest and reset its local var's ----------------------------------- local function removeChest(npc) - npc:setAnimationSub(0) + npc:setAnimationSub(0, false) npc:setStatus(xi.status.DISAPPEAR) - npc:setLocalVar('[caskets]SPAWNSTATUS', casketInfo.spawnStatus.DESPAWNED) + npc:resetLocalVars() end ----------------------------------- @@ -278,7 +278,7 @@ local function setCasketData(player, x, y, z, r, npc, partyID, mobLvl) ----------------------------------- -- Despawn chest after 3 Mins ----------------------------------- - npc:timer(180000, function(npcArg) + npc:timer(1000 * 60 * 3, function(npcArg) removeChest(npcArg) end) end @@ -548,7 +548,7 @@ end ----------------------------------- -- Desc: Gives the player the temp item from a casket based on the selection of the csid ----------------------------------- -local function giveTempItem(player, npc, tempNum) +local function giveTempItem(player, npc, tempNum, subOption) local tempQuery = string.format('[caskets]TEMP' ..tempNum.. '') local tempID = npc:getLocalVar(tempQuery) local zoneId = player:getZoneID() @@ -559,6 +559,13 @@ local function giveTempItem(player, npc, tempNum) return end + -- 2 = "do not obtain" + -- 1 = "obtain" + -- 0 = "None of them" + if subOption == 2 or subOption == 0 then + return + end + if tempID == 0 then player:messageSpecial(ID.text.UNABLE_TO_OBTAIN_ITEM) return @@ -596,7 +603,7 @@ end ----------------------------------- -- Desc: Gives the player the item from a casket based on the selection of the csid ----------------------------------- -local function giveItem(player, npc, itemNum) +local function giveItem(player, npc, itemNum, subOption) local itemQuery = string.format('[caskets]ITEM' ..itemNum.. '') local itemID = npc:getLocalVar(itemQuery) local zoneId = player:getZoneID() @@ -607,6 +614,13 @@ local function giveItem(player, npc, itemNum) return end + -- 2 = "do not obtain" + -- 1 = "obtain" + -- 0 = "None of them" + if subOption == 2 or subOption == 0 then + return + end + if itemID == 0 then player:messageSpecial(ID.text.UNABLE_TO_OBTAIN_ITEM) return @@ -939,12 +953,13 @@ xi.caskets.onEventFinish = function(player, csid, option, npc) end elseif locked == 0 then - local itemPos = bit.band(option, 0x7) + local itemPos = bit.band(option, 0x7) + local subOption = bit.band(bit.rshift(option, 16), 0x3) -- 2 bit mask if lootType == 1 then - giveTempItem(player, chestObj, itemPos) + giveTempItem(player, chestObj, itemPos, subOption) elseif lootType == 2 then - giveItem(player, chestObj, itemPos) + giveItem(player, chestObj, itemPos, subOption) end end end