Skip to content

Commit

Permalink
fix(skymp5-server): fix Actor.EquipItem to add missing items (skyrim-…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Dec 15, 2023
1 parent 5d7b980 commit ff44ad1
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "PapyrusActor.h"

#include "MpActor.h"
#include "script_objects/EspmGameObject.h"
#include "script_objects/MpFormGameObject.h"

#include "SpSnippetFunctionGen.h"
Expand Down Expand Up @@ -183,6 +184,14 @@ VarValue PapyrusActor::EquipItem(VarValue self,
if (arguments.size() < 1) {
throw std::runtime_error("EquipItem requires at least one argument");
}

// If no such item in inventory, add one (this is standard behavior)
auto lookupRes = GetRecordPtr(arguments[0]);
auto baseId = lookupRes.ToGlobalId(lookupRes.rec->GetId());
if (actor->GetInventory().GetItemCount(baseId) == 0) {
actor->AddItem(baseId, 1);
}

SpSnippet(GetName(), "EquipItem",
SpSnippetFunctionGen::SerializeArguments(arguments).data(),
actor->GetFormId())
Expand Down

0 comments on commit ff44ad1

Please sign in to comment.