Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events: NWNX_ON_SET_EXPERIENCE update to allow SetEventResult #1789

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Comment on lines +221 to +224
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you skip the event without setting a result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only checking from the phone now so I hope I'm not overlooking anything but my intention was that then nothing happens. No CallOriginal. Skipping the event (without setting a result) means no xp change.


PushEventData("XP", std::to_string(nValue));
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 | 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
Expand Down
Loading