diff --git a/regamedll/dlls/client.cpp b/regamedll/dlls/client.cpp index 97c6f4c1..cbc6873c 100644 --- a/regamedll/dlls/client.cpp +++ b/regamedll/dlls/client.cpp @@ -100,19 +100,6 @@ NOXREF void set_suicide_frame(entvars_t *pev) pev->nextthink = -1; } -void TeamChangeUpdate(CBasePlayer *player, int team_id) -{ - MESSAGE_BEGIN(MSG_ALL, gmsgTeamInfo); - WRITE_BYTE(player->entindex()); - WRITE_STRING(GetTeamName(team_id)); - MESSAGE_END(); - - if (team_id != UNASSIGNED) - { - player->SetScoreboardAttributes(); - } -} - void BlinkAccount(CBasePlayer *player, int numBlinks) { MESSAGE_BEGIN(MSG_ONE, gmsgBlinkAcct, NULL, player->pev); @@ -1650,7 +1637,9 @@ BOOL __API_HOOK(HandleMenu_ChooseTeam)(CBasePlayer *player, int slot) player->RemoveAllItems(TRUE); player->m_bHasC4 = false; +#ifdef REGAMEDLL_FIXES if (player->m_iTeam != SPECTATOR) +#endif { // notify other clients of player joined to team spectator UTIL_LogPrintf("\"%s<%i><%s><%s>\" joined team \"SPECTATOR\"\n", STRING(player->pev->netname), @@ -1684,16 +1673,18 @@ BOOL __API_HOOK(HandleMenu_ChooseTeam)(CBasePlayer *player, int slot) TheBots->OnEvent(EVENT_PLAYER_CHANGED_TEAM, player); } - TeamChangeUpdate(player, player->m_iTeam); + player->TeamChangeUpdate(); edict_t *pentSpawnSpot = g_pGameRules->GetPlayerSpawnSpot(player); player->StartObserver(pentSpawnSpot->v.origin, pentSpawnSpot->v.angles); +#ifndef REGAMEDLL_FIXES + // TODO: it was already sent in StartObserver MESSAGE_BEGIN(MSG_ALL, gmsgSpectator); WRITE_BYTE(ENTINDEX(player->edict())); WRITE_BYTE(1); MESSAGE_END(); - +#endif // do we have fadetoblack on? (need to fade their screen back in) if (fadetoblack.value) { @@ -1719,12 +1710,10 @@ BOOL __API_HOOK(HandleMenu_ChooseTeam)(CBasePlayer *player, int slot) // If the code gets this far, the team is not TEAM_UNASSIGNED // Player is switching to a new team (It is possible to switch to the // same team just to choose a new appearance) - if (CSGameRules()->TeamFull(team)) { // The specified team is full // attempt to kick a bot to make room for this player - bool madeRoom = false; if (cv_bot_auto_vacate.value > 0 && !player->IsBot()) { @@ -1834,7 +1823,6 @@ BOOL __API_HOOK(HandleMenu_ChooseTeam)(CBasePlayer *player, int slot) // Show the appropriate Choose Appearance menu // This must come before ClientKill() for CheckWinConditions() to function properly - if (player->pev->deadflag == DEAD_NO) { ClientKill(player->edict()); @@ -1850,7 +1838,7 @@ BOOL __API_HOOK(HandleMenu_ChooseTeam)(CBasePlayer *player, int slot) TheBots->OnEvent(EVENT_PLAYER_CHANGED_TEAM, player); } - TeamChangeUpdate(player, player->m_iTeam); + player->TeamChangeUpdate(); szOldTeam = GetTeam(oldTeam); szNewTeam = GetTeam(team); diff --git a/regamedll/dlls/client.h b/regamedll/dlls/client.h index 8e0a746d..1db472d9 100644 --- a/regamedll/dlls/client.h +++ b/regamedll/dlls/client.h @@ -114,7 +114,6 @@ extern unsigned short g_iShadowSprite; int CMD_ARGC_(); const char *CMD_ARGV_(int i); void set_suicide_frame(entvars_t *pev); -void TeamChangeUpdate(CBasePlayer *player, int team_id); void BlinkAccount(CBasePlayer *player, int numBlinks = 2); BOOL ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *szRejectReason); void ClientDisconnect(edict_t *pEntity); diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 7293aae2..4ac0350c 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -9309,3 +9309,16 @@ void CBasePlayer::ReloadWeapons(CBasePlayerItem *pWeapon, bool bForceReload, boo } #endif } + +void CBasePlayer::TeamChangeUpdate() +{ + MESSAGE_BEGIN(MSG_ALL, gmsgTeamInfo); + WRITE_BYTE(entindex()); + WRITE_STRING(GetTeamName(m_iTeam)); + MESSAGE_END(); + + if (m_iTeam != UNASSIGNED) + { + SetScoreboardAttributes(); + } +} diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index 8c1db1a2..729050da 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -594,6 +594,7 @@ public: edict_t *EntSelectSpawnPoint(); void SetScoreAttrib(CBasePlayer *dest); void ReloadWeapons(CBasePlayerItem *pWeapon = nullptr, bool bForceReload = false, bool bForceRefill = false); + void TeamChangeUpdate(); #ifdef REGAMEDLL_ADD CCSPlayer *CSPlayer() const; diff --git a/regamedll/public/regamedll/regamedll_interfaces.h b/regamedll/public/regamedll/regamedll_interfaces.h index f8676cc6..63124ca3 100644 --- a/regamedll/public/regamedll/regamedll_interfaces.h +++ b/regamedll/public/regamedll/regamedll_interfaces.h @@ -83,6 +83,9 @@ public: virtual bool SelectSpawnSpot(const char *pEntClassName, CBaseEntity* &pSpot); virtual bool SwitchWeapon(CBasePlayerItem *pWeapon); virtual void SwitchTeam(); + virtual bool JoinTeam(TeamName team); + virtual void StartObserver(Vector& vecPosition, Vector& vecViewAngle); + virtual void TeamChangeUpdate(); CBasePlayer *BasePlayer() const; public: diff --git a/regamedll/regamedll/regamedll_interfaces_impl.cpp b/regamedll/regamedll/regamedll_interfaces_impl.cpp index be0a9f42..46055d79 100644 --- a/regamedll/regamedll/regamedll_interfaces_impl.cpp +++ b/regamedll/regamedll/regamedll_interfaces_impl.cpp @@ -36,6 +36,95 @@ Vector CCSEntity::FireBullets3(Vector &vecSrc, Vector &vecDirShooting, float vec return m_pContainingEntity->FireBullets3(vecSrc, vecDirShooting, vecSpread, flDistance, iPenetration, iBulletType, iDamage, flRangeModifier, pevAttacker, bPistol, shared_rand); }; +bool CCSPlayer::JoinTeam(TeamName team) +{ + CBasePlayer *pPlayer = BasePlayer(); + switch (team) + { + case SPECTATOR: + { + // are we already a spectator? + if (pPlayer->m_iTeam == SPECTATOR) + return false; + + pPlayer->RemoveAllItems(TRUE); + pPlayer->m_bHasC4 = false; + + pPlayer->m_iTeam = SPECTATOR; + pPlayer->m_iJoiningState = JOINED; + + pPlayer->m_pIntroCamera = NULL; + pPlayer->m_bTeamChanged = true; + + pPlayer->TeamChangeUpdate(); + + edict_t *pentSpawnSpot = g_pGameRules->GetPlayerSpawnSpot(pPlayer); + pPlayer->StartObserver(pentSpawnSpot->v.origin, pentSpawnSpot->v.angles); + + // do we have fadetoblack on? (need to fade their screen back in) + if (fadetoblack.value) + { + UTIL_ScreenFade(pPlayer, Vector(0, 0, 0), 0.001, 0, 0, FFADE_IN); + } + + return true; + } + case CT: + case TERRORIST: + { + if (pPlayer->m_iTeam == SPECTATOR) + { + // If they're switching into spectator, setup spectator properties.. + pPlayer->m_bNotKilled = true; + pPlayer->m_iIgnoreGlobalChat = IGNOREMSG_NONE; + pPlayer->m_iTeamKills = 0; + + pPlayer->pev->solid = SOLID_NOT; + pPlayer->pev->movetype = MOVETYPE_NOCLIP; + pPlayer->pev->effects = EF_NODRAW; + pPlayer->pev->effects |= EF_NOINTERP; + pPlayer->pev->takedamage = DAMAGE_NO; + pPlayer->pev->deadflag = DEAD_DEAD; + pPlayer->pev->velocity = g_vecZero; + pPlayer->pev->punchangle = g_vecZero; + + pPlayer->m_bHasNightVision = false; + pPlayer->m_iHostagesKilled = 0; + pPlayer->m_fDeadTime = 0; + pPlayer->has_disconnected = false; + + pPlayer->m_iJoiningState = GETINTOGAME; + pPlayer->SendItemStatus(); + + SET_CLIENT_MAXSPEED(ENT(pPlayer->pev), 1); + SET_MODEL(ENT(pPlayer->pev), "models/player.mdl"); + } + break; + } + } + + if (pPlayer->pev->deadflag == DEAD_NO) + { + ClientKill(pPlayer->edict()); + pPlayer->pev->frags++; + } + + MESSAGE_BEGIN(MSG_BROADCAST, gmsgScoreInfo); + WRITE_BYTE(ENTINDEX(pPlayer->edict())); + WRITE_SHORT(int(pPlayer->pev->frags)); + WRITE_SHORT(pPlayer->m_iDeaths); + WRITE_SHORT(0); + WRITE_SHORT(0); + MESSAGE_END(); + + // Switch their actual team... + pPlayer->m_bTeamChanged = true; + pPlayer->m_iTeam = team; + pPlayer->TeamChangeUpdate(); + + return true; +} + bool CCSPlayer::RemovePlayerItem(const char* pszItemName) { CBasePlayer *pPlayer = BasePlayer(); @@ -89,3 +178,5 @@ void CCSPlayer::Observer_SetMode(int iMode) { BasePlayer()->Observer_SetMode(iMo bool CCSPlayer::SelectSpawnSpot(const char *pEntClassName, CBaseEntity* &pSpot) { return BasePlayer()->SelectSpawnSpot(pEntClassName, pSpot); } bool CCSPlayer::SwitchWeapon(CBasePlayerItem *pWeapon) { return BasePlayer()->SwitchWeapon(pWeapon) != FALSE; } void CCSPlayer::SwitchTeam() { BasePlayer()->SwitchTeam(); } +void CCSPlayer::StartObserver(Vector& vecPosition, Vector& vecViewAngle) { BasePlayer()->StartObserver(vecPosition, vecViewAngle); } +void CCSPlayer::TeamChangeUpdate() { BasePlayer()->TeamChangeUpdate(); }