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 CVar: mp_max_alive_name_changes #236

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
| mp_fadetoblack | 0 | 0 | 2 | Observer's screen will fade to black on kill event or permanent.<br/> `0` No fade.<br/>`1` Fade to black and won't be able to watch anybody.<br/>`2` fade to black only on kill moment. |
| mp_falldamage | 1 | 0 | 1 | Damage from falling.<br/>`0` disabled <br/>`1` enabled |
| sv_allchat | 1 | 0 | 1 | Players can receive all other players text chat, team restrictions apply<br/>`0` disabled <br/>`1` enabled |
| mp_max_alive_name_changes | -1 | -1 | - | Maximum amount of nickname changes before next respawn<br/>`-1` unlimited (default behaviour) <br/>`0` Allow to change only at spawn </br>`>0` Allow to change arbitrary amount of nicks |
</details>

## How to install zBot for CS 1.6?
Expand Down
8 changes: 8 additions & 0 deletions dist/game.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,11 @@ mp_free_armor 0
//
// Default value: "0"
sv_allchat 0

// Maximum amount of nickname changes before next respawn.
// -1 - unlimited (default behaviour)
// 0 - Allow to change only at spawn
// >0 - Allow to change arbitrary amount of nicks
//
// Default value: "-1"
mp_max_alive_name_changes -1
20 changes: 20 additions & 0 deletions regamedll/dlls/API/CSPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ void CCSPlayer::Reset()
m_iWeaponInfiniteIds = 0;
m_bCanShootOverride = false;
m_bGameForcingRespawn = false;
m_iNickChangesBeforeSpawn = -1;
}

void CCSPlayer::OnSpawn()
Expand All @@ -562,3 +563,22 @@ void CCSPlayer::OnKilled()
}
#endif
}

EXT_FUNC void CCSPlayer::OnRoundRespawn()
{
m_iNickChangesBeforeSpawn = 0;
}

EXT_FUNC bool CCSPlayer::CanChangeNickname()
{
#ifdef REGAMEDLL_ADD
return (max_alive_name_changes.value >= 0 && m_iNickChangesBeforeSpawn > max_alive_name_changes.value);
#else
return false;
#endif
}

EXT_FUNC void CCSPlayer::OnNicknameChanged()
{
m_iNickChangesBeforeSpawn++;
}
2 changes: 2 additions & 0 deletions regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ cvar_t t_default_weapons_secondary = { "mp_t_default_weapons_secondary", "
cvar_t t_default_weapons_primary = { "mp_t_default_weapons_primary", "", 0, 0.0f, nullptr };
cvar_t free_armor = { "mp_free_armor", "0", 0, 0.0f, nullptr };
cvar_t allchat = { "sv_allchat", "0", 0, 0.0f, nullptr };
cvar_t max_alive_name_changes = { "mp_max_alive_name_changes", "-1", 0, 0.0f, nullptr };

void GameDLL_Version_f()
{
Expand Down Expand Up @@ -387,6 +388,7 @@ void EXT_FUNC GameDLLInit()
CVAR_REGISTER(&t_default_weapons_primary);
CVAR_REGISTER(&free_armor);
CVAR_REGISTER(&allchat);
CVAR_REGISTER(&max_alive_name_changes);

// print version
CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ extern cvar_t t_default_weapons_secondary;
extern cvar_t t_default_weapons_primary;
extern cvar_t free_armor;
extern cvar_t allchat;
extern cvar_t max_alive_name_changes;

#endif

Expand Down
14 changes: 13 additions & 1 deletion regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ bool EXT_FUNC CBasePlayer::__API_HOOK(SetClientUserInfoName)(char *infobuffer, c
}
#endif

if (pev->deadflag != DEAD_NO)
if (IsAlive()
#ifdef REGAMEDLL_ADD
|| CSPlayer()->CanChangeNickname()
#endif
)
{
m_bHasChangedName = true;
Q_snprintf(m_szNewName, sizeof(m_szNewName), "%s", szNewName);
Expand All @@ -191,6 +195,10 @@ bool EXT_FUNC CBasePlayer::__API_HOOK(SetClientUserInfoName)(char *infobuffer, c
WRITE_STRING(szNewName);
MESSAGE_END();

#ifdef REGAMEDLL_ADD
CSPlayer()->OnNicknameChanged();
#endif

UTIL_LogPrintf("\"%s<%i><%s><%s>\" changed name to \"%s\"\n", STRING(pev->netname), GETPLAYERUSERID(edict()), GETPLAYERAUTHID(edict()), GetTeam(m_iTeam), szNewName);
return true;
}
Expand Down Expand Up @@ -3842,6 +3850,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(RoundRespawn)()
#endif
}

#ifdef REGAMEDLL_ADD
CSPlayer()->OnRoundRespawn();
#endif

if (m_iMenu != Menu_ChooseAppearance)
{
respawn(pev);
Expand Down
7 changes: 6 additions & 1 deletion regamedll/public/regamedll/API/CSPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class CCSPlayer: public CCSMonster {
m_iWeaponInfiniteAmmo(0),
m_iWeaponInfiniteIds(0),
m_bCanShootOverride(false),
m_bGameForcingRespawn(false)
m_bGameForcingRespawn(false),
m_iNickChangesBeforeSpawn(-1)
{
m_szModel[0] = '\0';
}
Expand Down Expand Up @@ -101,6 +102,9 @@ class CCSPlayer: public CCSMonster {

void OnSpawn();
void OnKilled();
void OnRoundRespawn();
bool CanChangeNickname();
void OnNicknameChanged();

CBasePlayer *BasePlayer() const;

Expand All @@ -125,6 +129,7 @@ class CCSPlayer: public CCSMonster {
int m_iWeaponInfiniteIds;
bool m_bCanShootOverride;
bool m_bGameForcingRespawn;
int m_iNickChangesBeforeSpawn;
};

// Inlines
Expand Down