Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new CVars mp_playerid_showhealth & mp_playerid_field #1046

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ cvar_t ammo_respawn_time = { "mp_ammo_respawn_time", "20", FCVAR_SERVER, 2
cvar_t vote_flags = { "mp_vote_flags", "km", 0, 0.0f, nullptr };
cvar_t votemap_min_time = { "mp_votemap_min_time", "180", 0, 180.0f, nullptr };

cvar_t playerid_showhealth = { "mp_playerid_showhealth", "1", FCVAR_SERVER, 1.0f, nullptr };
cvar_t playerid_field = { "mp_playerid_field", "3", FCVAR_SERVER, 3.0f, nullptr };

void GameDLL_Version_f()
{
if (Q_stricmp(CMD_ARGV(1), "version") != 0)
Expand Down Expand Up @@ -463,6 +466,9 @@ void EXT_FUNC GameDLLInit()
CVAR_REGISTER(&cv_bot_enable);
CVAR_REGISTER(&cv_hostage_ai_enable);

CVAR_REGISTER(&playerid_showhealth);
CVAR_REGISTER(&playerid_field);

// print version
CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");

Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ extern cvar_t weapon_respawn_time;
extern cvar_t ammo_respawn_time;
extern cvar_t vote_flags;
extern cvar_t votemap_min_time;
extern cvar_t playerid_showhealth;
extern cvar_t playerid_field;

#endif

Expand Down
51 changes: 49 additions & 2 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,39 @@ void CBasePlayer::SendItemStatus()
MESSAGE_END();
}

#ifdef REGAMEDLL_ADD
inline const char *GetPlayerIdString(bool sameTeam)
{
switch (static_cast<int>(playerid_showhealth.value))
{
case 1: // show health teammate only (cs default)
{
switch (static_cast<int>(playerid_field.value))
{
case 1: return sameTeam ? "1 %c1: %p2\n2 : %i3%%" : "1 %c1: %p2"; // show team text only
case 2: return sameTeam ? "1 %p2\n2 %h: %i3%%" : "1 %p2"; // show health text only
case 3: return sameTeam ? "1 %c1: %p2\n2 %h: %i3%%" : "1 %c1: %p2"; // show team text & health text (cs default)
default: return sameTeam ? "1 %p2\n2 : %i3%%" : "1 %p2"; // don't show text
}
}
case 2: // show health all
{
switch (static_cast<int>(playerid_field.value))
{
case 1: return "1 %c1: %p2\n2 : %i3%%"; // show team text only
case 2: return "1 %p2\n2 %h: %i3%%"; // show health text only
case 3: return "1 %c1: %p2\n2 %h: %i3%%"; // show team text & health text
default: return "1 %p2\n2 : %i3%%"; // don't show text
}
}
default: // don't show health
{
return (static_cast<int>(playerid_field.value) == 0) ? "1 %p2" : "1 %c1: %p2";
}
}
}
#endif

const char *GetCSModelName(int item_id)
{
const char *modelName = nullptr;
Expand Down Expand Up @@ -8073,11 +8106,17 @@ void CBasePlayer::UpdateStatusBar()
if (sameTeam || GetObserverMode() != OBS_NONE)
{
if (playerid.value != PLAYERID_MODE_OFF || GetObserverMode() != OBS_NONE)
#ifndef REGAMEDLL_ADD
Q_strlcpy(sbuf0, "1 %c1: %p2\n2 %h: %i3%%");
#else
Q_strlcpy(sbuf0, GetPlayerIdString(sameTeam));
#endif
else
Q_strlcpy(sbuf0, " ");

newSBarState[SBAR_ID_TARGETHEALTH] = int((pEntity->pev->health / pEntity->pev->max_health) * 100);
#ifdef REGAMEDLL_ADD
if (static_cast<int>(playerid_showhealth.value) != 0)
newSBarState[SBAR_ID_TARGETHEALTH] = int((pEntity->pev->health / pEntity->pev->max_health) * 100);
#endif

if (!(m_flDisplayHistory & DHF_FRIEND_SEEN) && !(pev->flags & FL_SPECTATOR))
{
Expand All @@ -8088,10 +8127,18 @@ void CBasePlayer::UpdateStatusBar()
else if (GetObserverMode() == OBS_NONE)
{
if (playerid.value != PLAYERID_MODE_TEAMONLY && playerid.value != PLAYERID_MODE_OFF)
#ifndef REGAMEDLL_ADD
Q_strlcpy(sbuf0, "1 %c1: %p2");
#else
Q_strlcpy(sbuf0, GetPlayerIdString(sameTeam));
#endif
else
Q_strlcpy(sbuf0, " ");

#ifdef REGAMEDLL_ADD
if (static_cast<int>(playerid_showhealth.value) == 2)
newSBarState[SBAR_ID_TARGETHEALTH] = int((pEntity->pev->health / pEntity->pev->max_health) * 100);
#endif
if (!(m_flDisplayHistory & DHF_ENEMY_SEEN))
{
m_flDisplayHistory |= DHF_ENEMY_SEEN;
Expand Down
Loading