ff_u_dbg_dmg
Debug chat command: damage the speaker.
Enables the /damage <number> chat command, in debug mode only:
/damage 12: deals 12 points of magical damage to the speaker, with the negative energy visual of the Inflict Wounds spells./damage -1: kills the speaker.
Any other value prints the usage. Each use is logged as a warning.
The damage is applied as an effect rather than by casting an Inflict Wounds spell, so the amount is exact (no dice, no saving throw).
Source code
// @code
#include "ff_i_core"
// -----------------------------------------------------------------------------
//! @brief Print the help of the command.
void OnHelp();
void OnHelp()
{
object oSpeaker = GetPCChatSpeaker();
string C1 = CHAT_COLOR_DEBUG;
string C2 = CHAT_COLOR_SERVER;
SendMessageToPC(oSpeaker, _RGB("/damage NUMBER: ", C1) + _RGB("Damage yourself by NUMBER hit points, -1 to die.", C2));
}
// -----------------------------------------------------------------------------
//! @brief Damage oPC by nAmount hit points, or kill oPC if nAmount is -1.
//! @param oPC The player to damage.
//! @param nAmount Hit points of damage, or -1 to kill.
void DamagePC(object oPC, int nAmount);
void DamagePC(object oPC, int nAmount)
{
if (nAmount == -1)
{
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_DEATH), oPC);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), oPC);
return;
}
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_NEGATIVE_ENERGY), oPC);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(nAmount, DAMAGE_TYPE_MAGICAL), oPC);
}
// -----------------------------------------------------------------------------
//! @brief Handle the /damage command.
void OnChat();
void OnChat()
{
object oSpeaker = GetPCChatSpeaker();
string sMessage = GetStringTrim(GetStringLowerCase(GetPCChatMessage()));
if (sMessage == "")
return;
struct CLI_ARGUMENTS sArgs = GetArguments(sMessage);
if (sArgs.sArg0 != "/damage")
return;
SetPCChatMessage("");
int nAmount = StringToInt(sArgs.sArg1);
if (nAmount == 0 || nAmount < -1)
{
SendMessageToPC(oSpeaker, _RGB("Usage: /damage NUMBER (positive, or -1 to die)", CHAT_COLOR_DEBUG));
return;
}
DamagePC(oSpeaker, nAmount);
LogWarning("Player " + GetObjectInfo(oSpeaker) + " /damage " + IntToString(nAmount));
}
// -----------------------------------------------------------------------------
void main()
{
string sEvent = NWNX_Events_GetCurrentEvent();
if (sEvent == ON_REGISTER)
{
if (!GetIsDebug())
return;
SubscribeToEvent(ON_DEFAULT_PLAYER_CHAT, __FILE__);
SubscribeToEvent(ON_DEFAULT_PLAYER_CHAT_HELP, __FILE__);
}
else if (sEvent == ON_DEFAULT_PLAYER_CHAT)
OnChat();
else if (sEvent == ON_DEFAULT_PLAYER_CHAT_HELP)
OnHelp();
}