Skip to content

Commit

Permalink
Merge pull request #1753 from Daztek/floating-player
Browse files Browse the repository at this point in the history
Player: add bChatWindow parameter to FloatingTextStringOnCreature()
  • Loading branch information
Daztek authored Apr 22, 2024
2 parents be21aa5 + ae96852 commit 93b3a40
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ https://github.com/nwnxee/unified/compare/build8193.36.12...HEAD
- Player: ReloadColorPalettes()

### Changed
- N/A
- Player: added bChatWindow parameter to FloatingTextStringOnCreature()

### Deprecated
- N/A
Expand Down
8 changes: 5 additions & 3 deletions Plugins/Player/NWScript/nwnx_player.nss
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ void NWNX_Player_SetCreatureNameOverride(object oPlayer, object oCreature, strin
/// @param oPlayer The player to display the text to.
/// @param oCreature The creature to display the text above.
/// @param sText The text to display.
void NWNX_Player_FloatingTextStringOnCreature(object oPlayer, object oCreature, string sText);
/// @param bChatWindow If TRUE, sText will be displayed in oPlayer's chat window.
void NWNX_Player_FloatingTextStringOnCreature(object oPlayer, object oCreature, string sText, int bChatWindow = TRUE);

/// @brief Toggle oPlayer's PlayerDM status.
/// @note This function does nothing for actual DMClient DMs or players with a client version < 8193.14
Expand Down Expand Up @@ -918,10 +919,11 @@ void NWNX_Player_SetCreatureNameOverride(object oPlayer, object oCreature, strin
NWNX_CallFunction(NWNX_Player, sFunc);
}

void NWNX_Player_FloatingTextStringOnCreature(object oPlayer, object oCreature, string sText)
void NWNX_Player_FloatingTextStringOnCreature(object oPlayer, object oCreature, string sText, int bChatWindow = TRUE)
{
string sFunc = "FloatingTextStringOnCreature";

NWNX_PushArgumentInt(bChatWindow);
NWNX_PushArgumentString(sText);
NWNX_PushArgumentObject(oCreature);
NWNX_PushArgumentObject(oPlayer);
Expand Down Expand Up @@ -1147,7 +1149,7 @@ object NWNX_Player_GetTURD(object oPlayer)

NWNX_PushArgumentObject(oPlayer);
NWNX_CallFunction(NWNX_Player, sFunc);

return NWNX_GetReturnValueObject();
}

Expand Down
13 changes: 12 additions & 1 deletion Plugins/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,14 +1264,25 @@ NWNX_EXPORT ArgumentStack FloatingTextStringOnCreature(ArgumentStack&& args)
auto text = args.extract<std::string>();
ASSERT_OR_THROW(!text.empty());

int32_t bChatWindow = true;
try
{
bChatWindow = !!args.extract<int32_t>();
}
catch(const std::runtime_error&)
{
LOG_WARNING("NWNX_Player_FloatingTextStringOnCreature() called from NWScript without 'bChatWindow' parameter. Please update nwnx_player.nss");
}

if (auto *pCreature = Utils::AsNWSCreature(Utils::GetGameObject(oidCreature)))
{
if (auto *pMessage = static_cast<CNWSMessage*>(Globals::AppManager()->m_pServerExoApp->GetNWSMessage()))
if (auto *pMessage = Globals::AppManager()->m_pServerExoApp->GetNWSMessage())
{
CNWCCMessageData messageData;
messageData.SetObjectID(0, pCreature->m_idSelf);
messageData.SetInteger(9, 94);
messageData.SetString(0, text);
messageData.SetInteger(0, bChatWindow);

pMessage->SendServerToPlayerCCMessage(pPlayer->m_nPlayerID, Constants::MessageClientSideMsgMinor::Feedback, &messageData, nullptr);
}
Expand Down

0 comments on commit 93b3a40

Please sign in to comment.