Team Player class model problem. Created 1 year ago2023-02-18 23:18:20 UTC by RoJAn RoJAn

Created 1 year ago2023-02-18 23:18:20 UTC by RoJAn RoJAn

Posted 1 year ago2023-02-18 23:18:20 UTC Post #347347
Hi, i was modding in my half life build for a team play game, and i wanted my team classes to have different player models, in this case, i used the "t_team" code (that i declared on player.h and used to allow my classes to have different weapons after spawnning) to edit the ChangePlayerTeam and the ClientUserInfoChanged from "teamplay_gamerules.cpp"

The weapon player class code on "teamplay_gamerules.cpp":
BOOL CHalfLifeTeamplay :: ClientCommand( CBasePlayer *pPlayer, const char *pcmd )
/Blah Blah Blah Code/
else if (FStrEq(pcmd, "scout") || FStrEq(pcmd, "soldier") || FStrEq(pcmd, "medic"))
{
/Blah Blah Blah Code/

if (FStrEq(pcmd, "scout"))
{
pPlayer->t_team = 1;
}

if (FStrEq(pcmd, "soldier"))
{
pPlayer->t_team = 2;
}

if (FStrEq(pcmd, "medic"))
{
pPlayer->t_team = 3;
}
And then in "multiplay_gamerules.cpp" i added on the part if (addDefault) something like this:
if (pPlayer->t_team == 1)
Code to give for the player
This code worked for the weapons, so i thought that would work for other things, but im having a little issue.
https://www.youtube.com/watch?v=cFt1XcfDQfg
As you see in this video, the model of the class doesn't change to the default model until I manually change the model to another one that I'm not currently using.
The code in theory works, but not as it should, I'm sure something is missing, but I don't know what it is, this is the code for class model change:
void CHalfLifeTeamplay::ChangePlayerTeam( CBasePlayer *pPlayer, const char *pTeamName, BOOL bKill, BOOL bGib )
{
int damageFlags = DMG_GENERIC;
int clientIndex = pPlayer->entindex();

if ( !bGib )
{
damageFlags |= DMG_NEVERGIB;
}
else
{
damageFlags |= DMG_ALWAYSGIB;
}

if ( bKill )
{
// kill the player, remove a death, and let them start on the new team
m_DisableDeathMessages = TRUE;
m_DisableDeathPenalty = TRUE;

entvars_t *pevWorld = VARS( INDEXENT(0) );
pPlayer->TakeDamage( pevWorld, pevWorld, 900, damageFlags );

m_DisableDeathMessages = FALSE;
m_DisableDeathPenalty = FALSE;
}

// copy out the team name from the model
strncpy( pPlayer->m_szTeamName, pTeamName, TEAM_NAME_LENGTH );

if (pPlayer->t_team == 1)
{
g_engfuncs.pfnSetClientKeyValue(clientIndex, g_engfuncs.pfnGetInfoKeyBuffer(pPlayer->edict()), "model", "scout");
}
else if (pPlayer->t_team == 2)
{
g_engfuncs.pfnSetClientKeyValue(clientIndex, g_engfuncs.pfnGetInfoKeyBuffer(pPlayer->edict()), "model", "soldier");
}
else if (pPlayer->t_team == 3)
{
g_engfuncs.pfnSetClientKeyValue(clientIndex, g_engfuncs.pfnGetInfoKeyBuffer(pPlayer->edict()), "model", "medic");
}
//g_engfuncs.pfnSetClientKeyValue(clientIndex, g_engfuncs.pfnGetInfoKeyBuffer(pPlayer->edict()), "model", pPlayer->m_szTeamName);
g_engfuncs.pfnSetClientKeyValue( clientIndex, g_engfuncs.pfnGetInfoKeyBuffer( pPlayer->edict() ), "team", pPlayer->m_szTeamName );

// notify everyone's HUD of the team change
MESSAGE_BEGIN( MSG_ALL, gmsgTeamInfo );
WRITE_BYTE( clientIndex );
WRITE_STRING( pPlayer->m_szTeamName );
MESSAGE_END();

MESSAGE_BEGIN( MSG_ALL, gmsgScoreInfo );
WRITE_BYTE( clientIndex );
WRITE_SHORT( pPlayer->pev->frags );
WRITE_SHORT( pPlayer->m_iDeaths );
WRITE_SHORT( 0 );
WRITE_SHORT( g_pGameRules->GetTeamIndex( pPlayer->m_szTeamName ) + 1 );
MESSAGE_END();
}
void CHalfLifeTeamplay::ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer )
{
// an observer can change a lot, but isn''t visible so hasn''t got to do much here

if (pPlayer->m_afPhysicsFlags & PFLAG_OBSERVER)

return;

// prevent skin/color/model changes

char* mdls = g_engfuncs.pfnInfoKeyValue(infobuffer, "model");

//if the model name and the teamname are the same then return

if (pPlayer->t_team == 1)
{
if (!stricmp(mdls, "scout"))
return;
}
if (pPlayer->t_team == 2)
{
if (!stricmp(mdls, "soldier"))
return;
}
if (pPlayer->t_team == 3)
{
if (!stricmp(mdls, "medic"))
return;
}

//else make sure the player model is the same as the teamname
if (pPlayer->t_team == 1)
{
g_engfuncs.pfnSetClientKeyValue(pPlayer->entindex(), g_engfuncs.pfnGetInfoKeyBuffer(pPlayer->edict()), "model", "scout");
}
else if (pPlayer->t_team == 2)
{
g_engfuncs.pfnSetClientKeyValue(pPlayer->entindex(), g_engfuncs.pfnGetInfoKeyBuffer(pPlayer->edict()), "model", "soldier");
}
else if (pPlayer->t_team == 3)
{
g_engfuncs.pfnSetClientKeyValue(pPlayer->entindex(), g_engfuncs.pfnGetInfoKeyBuffer(pPlayer->edict()), "model", "medic");
}
//g_engfuncs.pfnSetClientKeyValue(pPlayer->entindex(), g_engfuncs.pfnGetInfoKeyBuffer(pPlayer->edict()), "model", pPlayer->m_szTeamName);
}
Posted 1 year ago2023-02-21 22:34:43 UTC Post #347359
Now i already fixed it, it was a problem on the ChangePlayerTeam function, maybe i could show something on the way!
You must be logged in to post a response.