void StickyCombatModes::SetCombatModeHook(API::CNWSCreature* thisPtr, uint8_t newMode, bool forceNewMode)
{
if (thisPtr->m_bPlayerCharacter)
{
const uint8_t currentMode = thisPtr->m_nCombatMode;
if (g_plugin->m_dispatchMessages && currentMode != newMode)
{
// ToggleMode gets called with modes which are +1 to what the script constants expect.
// It then calls SetCombatMode with the 'proper' modes.
// To simplify things, we just correct the mode we dispatch here, so the game events
// receive what they expect to.
auto messaging = g_plugin->GetServices()->m_messaging.get();
if (currentMode != 0)
{
messaging->BroadcastMessage("NWNX_EVENT_PUSH_EVENT_DATA", { "MODE", std::to_string(currentMode + 1) } );
messaging->BroadcastMessage("NWNX_EVENT_SIGNAL_EVENT", { "NWNX_ON_MODE_OFF", ObjectIDToString(thisPtr->m_idSelf) });
}
if (newMode != 0)
{
messaging->BroadcastMessage("NWNX_EVENT_PUSH_EVENT_DATA", { "MODE", std::to_string(newMode + 1) } );
messaging->BroadcastMessage("NWNX_EVENT_SIGNAL_EVENT", { "NWNX_ON_MODE_ON", ObjectIDToString(thisPtr->m_idSelf) });
}
}
}
return g_setCombatModeHook->CallOriginal<void>(thisPtr, newMode, forceNewMode);
}
Now that we no longer have the StickyCombatModes plugin, we need to move this event to the Events plugin with the same effective outputs as above.
The StickyCombatModes plugin used to use the messaging bus to add two events -
NWNX_ON_MODE_ON
andNWNX_ON_MODE_OFF
.The code looked like this:
... later ...
Now that we no longer have the StickyCombatModes plugin, we need to move this event to the Events plugin with the same effective outputs as above.