diff --git a/Plugins/Events/Events/ObjectEvents.cpp b/Plugins/Events/Events/ObjectEvents.cpp index fe9c3abd78c..f2338519ac7 100644 --- a/Plugins/Events/Events/ObjectEvents.cpp +++ b/Plugins/Events/Events/ObjectEvents.cpp @@ -212,15 +212,19 @@ void SetExperienceHook(CNWSCreatureStats *thisPtr, uint32_t nValue, BOOL bDoLeve if (!bDoLevel) { s_SetExperienceHook->CallOriginal(thisPtr, nValue, bDoLevel); } else { - auto PushAndSignal = [&](const std::string& ev) -> bool { - PushEventData("XP", std::to_string(nValue)); - return SignalEvent(ev, thisPtr->m_pBaseCreature->m_idSelf); - }; - - if (PushAndSignal("NWNX_ON_SET_EXPERIENCE_BEFORE")) + PushEventData("XP", std::to_string(nValue)); + std::string result; + if (SignalEvent("NWNX_ON_SET_EXPERIENCE_BEFORE", thisPtr->m_pBaseCreature->m_idSelf, &result)) + { s_SetExperienceHook->CallOriginal(thisPtr, nValue, bDoLevel); - - PushAndSignal("NWNX_ON_SET_EXPERIENCE_AFTER"); + } + else if (const auto newXP = String::FromString(result)) + { + s_SetExperienceHook->CallOriginal(thisPtr, newXP.value(), bDoLevel); + } + + PushEventData("XP", std::to_string(nValue)); + SignalEvent("NWNX_ON_SET_EXPERIENCE_AFTER", thisPtr->m_pBaseCreature->m_idSelf); } } diff --git a/Plugins/Events/NWScript/nwnx_events.nss b/Plugins/Events/NWScript/nwnx_events.nss index 5cf48815e23..ee8658e7a4c 100644 --- a/Plugins/Events/NWScript/nwnx_events.nss +++ b/Plugins/Events/NWScript/nwnx_events.nss @@ -1664,7 +1664,9 @@ _______________________________________ Event Data Tag | Type | Notes ----------------------|--------|------- - XP | int | The xp value that is being set | + XP | int | The xp value to be set. | + + @note To set a different xp value in the BEFORE event: Skip the event and call NWNX_Events_SetEventResult() with the new value. _______________________________________ ## Broadcast Attack of Opportunity Events - NWNX_ON_BROADCAST_ATTACK_OF_OPPORTUNITY_BEFORE