ff_u_dbg_heal
Debug chat command: heal the speaker.
Enables /heal <number> in debug mode:
/heal 12: heals the speaker by 12 hit points./heal -1: heals the speaker fully.
The visual effect is the one of the matching Cure Wounds spell (light, moderate, serious, critical), or of the Heal spell for large amounts and full heals. The heal is applied as an effect rather than by casting the spell, so the amount is exact (no dice).
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("/heal NUMBER: ", C1) + _RGB("Heal yourself by NUMBER hit points, -1 to heal fully.", C2));
}
// -----------------------------------------------------------------------------
//! @brief Return the healing visual effect of the Cure Wounds or Heal spell for nAmount.
//! @param nAmount Hit points healed.
//! @return A VFX_IMP_HEALING_* constant.
int GetHealingVisual(int nAmount);
int GetHealingVisual(int nAmount)
{
if (nAmount <= 10)
return VFX_IMP_HEALING_S; // Cure Light Wounds
if (nAmount <= 20)
return VFX_IMP_HEALING_M; // Cure Moderate Wounds
if (nAmount <= 30)
return VFX_IMP_HEALING_L; // Cure Serious Wounds
if (nAmount <= 40)
return VFX_IMP_HEALING_G; // Cure Critical Wounds
return VFX_IMP_HEALING_X; // Heal
}
// -----------------------------------------------------------------------------
//! @brief Heal oPC by nAmount hit points, or fully if nAmount is -1.
//! @param oPC The player to heal.
//! @param nAmount Hit points to heal, or -1 to heal fully.
void HealPC(object oPC, int nAmount);
void HealPC(object oPC, int nAmount)
{
int nVisual = VFX_IMP_HEALING_X;
if (nAmount == -1)
nAmount = GetMaxHitPoints(oPC) - GetCurrentHitPoints(oPC);
else
nVisual = GetHealingVisual(nAmount);
if (nAmount <= 0)
return;
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(nVisual), oPC);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(nAmount), oPC);
}
// -----------------------------------------------------------------------------
//! @brief Handle the /heal 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 != "/heal")
return;
SetPCChatMessage("");
int nAmount = StringToInt(sArgs.sArg1);
if (nAmount == 0 || nAmount < -1)
{
SendMessageToPC(oSpeaker, _RGB("Usage: /heal NUMBER (positive, or -1 to heal fully)", CHAT_COLOR_DEBUG));
return;
}
HealPC(oSpeaker, nAmount);
LogWarning("Player " + GetObjectInfo(oSpeaker) + " /heal " + 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();
}