1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-03 15:19:42 +00:00

feat: SetUsedItem lua func

This commit is contained in:
Luke Elrod 2024-12-30 18:57:55 -08:00
parent 49be5b6405
commit e569328f3d
2 changed files with 23 additions and 0 deletions

View file

@ -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

View file

@ -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;