Skip to content

Commit

Permalink
Events: NWNX_ON_SET_EXPERIENCE update: SetEventResult, real xp in AFTER
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikgit committed Oct 10, 2024
1 parent 695efc6 commit 77d7d75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 12 additions & 8 deletions Plugins/Events/Events/ObjectEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,19 @@ void SetExperienceHook(CNWSCreatureStats *thisPtr, uint32_t nValue, BOOL bDoLeve
if (!bDoLevel) {
s_SetExperienceHook->CallOriginal<void>(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<void>(thisPtr, nValue, bDoLevel);

PushAndSignal("NWNX_ON_SET_EXPERIENCE_AFTER");
}
else if (const auto newXP = String::FromString<uint32_t>(result))
{
s_SetExperienceHook->CallOriginal<void>(thisPtr, newXP.value(), bDoLevel);
}

PushEventData("XP", std::to_string(thisPtr->m_nExperience));
SignalEvent("NWNX_ON_SET_EXPERIENCE_AFTER", thisPtr->m_pBaseCreature->m_idSelf);
}
}

Expand Down
4 changes: 3 additions & 1 deletion Plugins/Events/NWScript/nwnx_events.nss
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,9 @@ _______________________________________
Event Data Tag | Type | Notes
----------------------|--------|-------
XP | int | The xp value that is being set |
XP | int | In the BEFORE event: The xp value that is about to be set. AFTER event: The xp the creature actually has now. |
@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
Expand Down

0 comments on commit 77d7d75

Please sign in to comment.