MCPcopy Create free account
hub / github.com/JACoders/OpenJK / G_ChangePlayerModel

Function G_ChangePlayerModel

code/game/g_client.cpp:1984–2043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1982}
1983
1984void G_ChangePlayerModel( gentity_t *ent, const char *newModel )
1985{
1986 if ( !ent || !ent->client || !newModel )
1987 {
1988 return;
1989 }
1990
1991 G_RemovePlayerModel( ent );
1992 if ( Q_stricmp( "player", newModel ) == 0 )
1993 {
1994 G_InitPlayerFromCvars( ent );
1995 return;
1996 }
1997
1998 //attempt to free the string (currently can't since it's always "player" )
1999 if( ent->NPC_type && gi.bIsFromZone(ent->NPC_type, TAG_G_ALLOC) ) {
2000 gi.Free(ent->NPC_type);
2001 }
2002 ent->NPC_type = G_NewString( newModel );
2003 G_RemoveWeaponModels( ent );
2004
2005 if ( strchr(newModel,'|') )
2006 {
2007 char name[MAX_QPATH];
2008 strcpy(name, newModel);
2009 char *p = strchr(name, '|');
2010 *p=0;
2011 p++;
2012
2013 if ( strstr(p, "model_default" ) )
2014 G_SetG2PlayerModel( ent, name, NULL, NULL, NULL );
2015 else
2016 G_SetG2PlayerModel( ent, name, p, NULL, NULL );
2017 }
2018 else
2019 {
2020 //FIXME: everything but force powers gets reset, those should, too...
2021 // currently leaves them as is except where otherwise noted in the NPCs.cfg?
2022 //FIXME: remove all weapons?
2023 if ( NPC_ParseParms( ent->NPC_type, ent ) )
2024 {
2025 G_AddWeaponModels( ent );
2026 NPC_SetAnim( ent, SETANIM_LEGS, ent->client->ps.legsAnim, SETANIM_FLAG_NORMAL|SETANIM_FLAG_RESTART );
2027 NPC_SetAnim( ent, SETANIM_TORSO, ent->client->ps.torsoAnim, SETANIM_FLAG_NORMAL|SETANIM_FLAG_RESTART );
2028 ClientUserinfoChanged( ent->s.number );
2029 //Ugh, kind of a hack for now:
2030 if ( ent->client->NPC_class == CLASS_BOBAFETT
2031 || ent->client->NPC_class == CLASS_ROCKETTROOPER )
2032 {
2033 //FIXME: remove saber, too?
2034 Boba_Precache(); // player as boba?
2035 }
2036 }
2037 else
2038 {
2039 gi.Printf( S_COLOR_RED"G_ChangePlayerModel: cannot find NPC %s\n", newModel );
2040 G_ChangePlayerModel( ent, "stormtrooper" ); //need a better fallback?
2041 }

Callers 5

SetMethod · 0.85
G_InitPlayerFromCvarsFunction · 0.85
ClientSpawnFunction · 0.85
G_DriveATSTFunction · 0.85
Svcmd_PlayerModel_fFunction · 0.85

Calls 12

G_RemovePlayerModelFunction · 0.85
Q_stricmpFunction · 0.85
G_InitPlayerFromCvarsFunction · 0.85
G_RemoveWeaponModelsFunction · 0.85
G_AddWeaponModelsFunction · 0.85
G_NewStringFunction · 0.70
G_SetG2PlayerModelFunction · 0.70
NPC_ParseParmsFunction · 0.70
NPC_SetAnimFunction · 0.70
ClientUserinfoChangedFunction · 0.70
Boba_PrecacheFunction · 0.70
FreeMethod · 0.45

Tested by

no test coverage detected