[Commands] Add #sethp Command. (#1840)

- Add #sethp [Health] command to set an NPC or player's health to a specified amount, or to max if the amount is greater than their max.
- Cleanup #heal command message and logic.
This commit is contained in:
Kinglykrab 2021-11-27 19:08:00 -05:00 committed by GitHub
parent c4c5256438
commit a5348e207b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 14 deletions

View File

@ -490,6 +490,7 @@ SET(gm_commands
gm_commands/setcrystals.cpp gm_commands/setcrystals.cpp
gm_commands/setfaction.cpp gm_commands/setfaction.cpp
gm_commands/setgraveyard.cpp gm_commands/setgraveyard.cpp
gm_commands/sethp.cpp
gm_commands/setlanguage.cpp gm_commands/setlanguage.cpp
gm_commands/setlsinfo.cpp gm_commands/setlsinfo.cpp
gm_commands/setmana.cpp gm_commands/setmana.cpp

View File

@ -326,6 +326,7 @@ int command_init(void)
command_add("setcrystals", "[value] - Set your or your player target's available radiant or ebon crystals", AccountStatus::GMAdmin, command_setcrystals) || command_add("setcrystals", "[value] - Set your or your player target's available radiant or ebon crystals", AccountStatus::GMAdmin, command_setcrystals) ||
command_add("setfaction", "[Faction ID] - Sets targeted NPC's faction in the database", AccountStatus::GMAreas, command_setfaction) || command_add("setfaction", "[Faction ID] - Sets targeted NPC's faction in the database", AccountStatus::GMAreas, command_setfaction) ||
command_add("setgraveyard", "[zone name] - Creates a graveyard for the specified zone based on your target's LOC.", AccountStatus::GMMgmt, command_setgraveyard) || command_add("setgraveyard", "[zone name] - Creates a graveyard for the specified zone based on your target's LOC.", AccountStatus::GMMgmt, command_setgraveyard) ||
command_add("sethp", "[Health] - Set your or your target's Health", AccountStatus::GMAdmin, command_sethp) ||
command_add("setlanguage", "[language ID] [value] - Set your target's language skillnum to value", AccountStatus::Guide, command_setlanguage) || command_add("setlanguage", "[language ID] [value] - Set your target's language skillnum to value", AccountStatus::Guide, command_setlanguage) ||
command_add("setlsinfo", "[email] [password] - Set login server email address and password (if supported by login server)", AccountStatus::Steward, command_setlsinfo) || command_add("setlsinfo", "[email] [password] - Set login server email address and password (if supported by login server)", AccountStatus::Steward, command_setlsinfo) ||
command_add("setmana", "[Mana] - Set your or your target's Mana", AccountStatus::GMAdmin, command_setmana) || command_add("setmana", "[Mana] - Set your or your target's Mana", AccountStatus::GMAdmin, command_setmana) ||

View File

@ -247,6 +247,7 @@ void command_setanim(Client *c, const Seperator *sep);
void command_setcrystals(Client *c, const Seperator *sep); void command_setcrystals(Client *c, const Seperator *sep);
void command_setfaction(Client *c, const Seperator *sep); void command_setfaction(Client *c, const Seperator *sep);
void command_setgraveyard(Client *c, const Seperator *sep); void command_setgraveyard(Client *c, const Seperator *sep);
void command_sethp(Client *c, const Seperator *sep);
void command_setlanguage(Client *c, const Seperator *sep); void command_setlanguage(Client *c, const Seperator *sep);
void command_setlsinfo(Client *c, const Seperator *sep); void command_setlsinfo(Client *c, const Seperator *sep);
void command_setmana(Client *c, const Seperator *sep); void command_setmana(Client *c, const Seperator *sep);

View File

@ -2,20 +2,28 @@
void command_heal(Client *c, const Seperator *sep) void command_heal(Client *c, const Seperator *sep)
{ {
auto target = c->GetTarget() ? c->GetTarget() : c; Mob* target = c;
if (c->GetTarget()) {
target = c->GetTarget();
}
target->Heal(); target->Heal();
if (c != target) {
c->Message( c->Message(
Chat::White, Chat::White,
fmt::format( fmt::format(
"Healed {} ({}) to full.", "Set {} to full Health ({}).",
target->GetCleanName(), (
target->GetID() c == target ?
).c_str() "yourself" :
); fmt::format(
} "{} ({})",
else { target->GetCleanName(),
c->Message(Chat::White, "Healed yourself to full."); target->GetID()
} )
),
target->GetMaxHP()
).c_str()
);
} }

View File

@ -0,0 +1,55 @@
#include "../client.h"
void command_sethp(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (!arguments || !sep->IsNumber(1)) {
c->Message(Chat::White, "Usage: #sethp [Health]");
return;
}
auto health = static_cast<int>(std::min(std::stoll(sep->arg[1]), (long long) 2000000000));
bool set_to_max = false;
Mob* target = c;
if (c->GetTarget()) {
target = c->GetTarget();
}
if (health >= target->GetMaxHP()) {
health = target->GetMaxHP();
set_to_max = true;
}
target->SetHP(health);
target->SendHPUpdate();
c->Message(
Chat::White,
fmt::format(
"Set {} to {} Health{}.",
(
c == target ?
"yourself" :
fmt::format(
"{} ({})",
target->GetCleanName(),
target->GetID()
)
),
(
set_to_max ?
"full" :
std::to_string(health)
),
(
set_to_max ?
fmt::format(
" ({})",
health
) :
""
)
).c_str()
);
}