From e569328f3d4f3349331ec30d6b7a5be939ac1ab6 Mon Sep 17 00:00:00 2001 From: Luke Elrod Date: Mon, 30 Dec 2024 18:57:55 -0800 Subject: [PATCH] feat: SetUsedItem lua func --- apps/openmw-mp/Script/Functions/Items.cpp | 13 +++++++++++++ apps/openmw-mp/Script/Functions/Items.hpp | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index 335936593..bb3794760 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -270,6 +270,19 @@ void ItemFunctions::SendItemUse(unsigned short pid) noexcept packet->Send(false); } +bool ItemFunctions::SetUsedItem(unsigned short pid, const char* refId) noexcept +{ + Player* player; + GET_PLAYER(pid, player, false); + for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++) { + if (Misc::StringUtils::ciEqual(player->equipmentItems[slot].refId, refId)) { + player->usedItem = player->equipmentItems[slot]; + return true; + } + } + return false; +} + // All methods below are deprecated versions of methods from above void ItemFunctions::InitializeInventoryChanges(unsigned short pid) noexcept diff --git a/apps/openmw-mp/Script/Functions/Items.hpp b/apps/openmw-mp/Script/Functions/Items.hpp index f761f2701..d95a425ab 100644 --- a/apps/openmw-mp/Script/Functions/Items.hpp +++ b/apps/openmw-mp/Script/Functions/Items.hpp @@ -39,6 +39,7 @@ {"SendEquipment", ItemFunctions::SendEquipment},\ {"SendInventoryChanges", ItemFunctions::SendInventoryChanges},\ {"SendItemUse", ItemFunctions::SendItemUse},\ + {"SetUsedItem", ItemFunctions::SetUsedItem},\ \ {"InitializeInventoryChanges", ItemFunctions::InitializeInventoryChanges},\ {"AddItem", ItemFunctions::AddItem} @@ -312,6 +313,15 @@ public: */ static void SendItemUse(unsigned short pid) noexcept; + /** + * \brief Update a player's recorded usedItem. Only usable on equipped items. + * + * \param pid The player ID affected. + * \param refId The name of the equipped item. + * \return bool + */ + static bool SetUsedItem(unsigned short pid, const char* refId) noexcept; + // All methods below are deprecated versions of methods from above static void InitializeInventoryChanges(unsigned short pid) noexcept;