Skip to content

Commit

Permalink
Add new CVars playerid_showhealth & mp_playerid_field
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaqtincha committed Jan 25, 2025
1 parent f63ad67 commit 109a956
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
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
50 changes: 48 additions & 2 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,38 @@ void CBasePlayer::SendItemStatus()
MESSAGE_END();
}

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";
}
}
}


const char *GetCSModelName(int item_id)
{
const char *modelName = nullptr;
Expand Down Expand Up @@ -8073,11 +8105,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 +8126,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

0 comments on commit 109a956

Please sign in to comment.