Add "displayname" keyvalue for custom monster names.

This commit is contained in:
Julian
2020-06-03 01:36:04 -03:00
parent 4d61695e6b
commit 1e68434df5
25 changed files with 149 additions and 23 deletions

View File

@@ -58,7 +58,7 @@ Current milestones are separated by "Tiers", which are as follows:
### Tier 2 ### Tier 2
- Add *-at least minimal-* death messages. *-Example: "\<player\> was killed by a \<monster\>".-* **[DONE]** - Add *-at least minimal-* death messages. *-Example: "\<player\> was killed by a \<monster\>".-* **[DONE]**
- Implement HUD info about the monsters, along with the "displayname" keyvalue. - Implement HUD info about the monsters, along with the "displayname" keyvalue. **[DONE]**
- Implement custom monster classification, the "classify" keyvalue. - Implement custom monster classification, the "classify" keyvalue.
### Tier 3 ### Tier 3

View File

@@ -543,6 +543,11 @@ void CMAGrunt :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_alien_grunt" ); pev->classname = MAKE_STRING( "monster_alien_grunt" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Alien Grunt" );
}
} }
//========================================================= //=========================================================

View File

@@ -86,6 +86,11 @@ void CMApache :: Spawn( void )
m_iSoundState = 0; m_iSoundState = 0;
pev->classname = MAKE_STRING( "monster_apache" ); pev->classname = MAKE_STRING( "monster_apache" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Apache" );
}
} }

View File

@@ -359,6 +359,11 @@ void CMBarney :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_barney" ); pev->classname = MAKE_STRING( "monster_barney" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Barney" );
}
} }
//========================================================= //=========================================================

View File

@@ -48,6 +48,7 @@ public:
void CMInfoBM::Spawn( void ) void CMInfoBM::Spawn( void )
{ {
pev->classname = MAKE_STRING( "info_bigmomma" );
} }
void CMInfoBM::KeyValue( KeyValueData* pkvd ) void CMInfoBM::KeyValue( KeyValueData* pkvd )
@@ -612,6 +613,11 @@ void CMBigMomma :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_bigmomma" ); pev->classname = MAKE_STRING( "monster_bigmomma" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Big Momma" );
}
} }
//========================================================= //=========================================================

View File

@@ -619,6 +619,11 @@ void CMBullsquid :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_bullchicken" ); pev->classname = MAKE_STRING( "monster_bullchicken" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Bullsquid" );
}
} }
//========================================================= //=========================================================

View File

@@ -540,7 +540,6 @@ public:
class CMBaseMonster; class CMBaseMonster;
extern int GetMonsterIndex(void); extern int GetMonsterIndex(void);
// //

View File

@@ -101,7 +101,9 @@ public:
string_t m_iszTriggerTarget;// name of target that should be fired. string_t m_iszTriggerTarget;// name of target that should be fired.
Vector m_HackedGunPos; // HACK until we can query end of gun Vector m_HackedGunPos; // HACK until we can query end of gun
string_t m_szMonsterName; // Monster name to display on HUD
void KeyValue( KeyValueData *pkvd ); void KeyValue( KeyValueData *pkvd );
// monster use function // monster use function

View File

@@ -589,7 +589,11 @@ void CMBaseMonster :: Killed( entvars_t *pevAttacker, int iGib )
{ {
unsigned int cCount = 0; unsigned int cCount = 0;
BOOL fDone = FALSE; BOOL fDone = FALSE;
// If a player killed this monster, add score
if ( UTIL_IsPlayer( ENT( pevAttacker ) ) )
pevAttacker->frags += 1.0;
if ( HasMemory( bits_MEMORY_KILLED ) ) if ( HasMemory( bits_MEMORY_KILLED ) )
{ {
if ( ShouldGibMonster( iGib ) ) if ( ShouldGibMonster( iGib ) )
@@ -822,7 +826,7 @@ int CMBaseMonster :: TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker
{ {
float flTake; float flTake;
Vector vecDir; Vector vecDir;
if (!pev->takedamage) if (!pev->takedamage)
return 0; return 0;

View File

@@ -312,6 +312,11 @@ void CMController :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_alien_controller" ); pev->classname = MAKE_STRING( "monster_alien_controller" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Alien Controller" );
}
} }
//========================================================= //=========================================================
@@ -1115,6 +1120,8 @@ void CMControllerHeadBall :: Spawn( void )
m_hOwner = pev->owner; m_hOwner = pev->owner;
pev->dmgtime = gpGlobals->time; pev->dmgtime = gpGlobals->time;
pev->classname = MAKE_STRING( "controller_head_ball" );
} }
@@ -1299,9 +1306,10 @@ void CMControllerZapBall :: Spawn( void )
m_hOwner = pev->owner; m_hOwner = pev->owner;
pev->dmgtime = gpGlobals->time; // keep track of when ball spawned pev->dmgtime = gpGlobals->time; // keep track of when ball spawned
pev->nextthink = gpGlobals->time + 0.1; pev->nextthink = gpGlobals->time + 0.1;
pev->classname = MAKE_STRING( "controller_energy_ball" );
} }
void CMControllerZapBall :: Precache( void ) void CMControllerZapBall :: Precache( void )
{ {
PRECACHE_MODEL("sprites/xspark4.spr"); PRECACHE_MODEL("sprites/xspark4.spr");

View File

@@ -59,6 +59,7 @@ extern gamedll_funcs_t *gpGamedllFuncs;
extern cvar_t *dllapi_log; extern cvar_t *dllapi_log;
extern cvar_t *monster_spawn; extern cvar_t *monster_spawn;
extern cvar_t *monster_show_deaths; extern cvar_t *monster_show_deaths;
extern cvar_t *monster_show_info;
// Player TakeDamage and Killed // Player TakeDamage and Killed
int g_DamageMsg; int g_DamageMsg;
@@ -322,7 +323,7 @@ void check_monster_hurt(edict_t *pAttacker)
} }
void check_monster_dead(void) void check_monster_dead(edict_t *pAttacker)
{ {
for (int index = 0; index < monster_ents_used; index++) for (int index = 0; index < monster_ents_used; index++)
{ {
@@ -341,8 +342,9 @@ void check_monster_dead(void)
pent->v.flags &= ~FL_KILLME; // clear FL_KILLME bit pent->v.flags &= ~FL_KILLME; // clear FL_KILLME bit
pent->v.deadflag = DEAD_NO; // bring back to life pent->v.deadflag = DEAD_NO; // bring back to life
monsters[index].pMonster->Killed(VARS(pent), 0); monsters[index].pMonster->Killed(VARS(pAttacker), 0);
monsters[index].killed = TRUE; monsters[index].killed = TRUE;
} }
} }
@@ -386,8 +388,17 @@ void check_player_dead( edict_t *pPlayer )
// Killed by a monster? // Killed by a monster?
if ( pAttacker->v.flags & FL_MONSTER ) if ( pAttacker->v.flags & FL_MONSTER )
{ {
// TODO: Custom monster name // Check the first character for 'aeiou'.
sprintf( szMessage, "* %s was killed by a monster.\n", szPlayerName ); CMBaseMonster *pMonster = GetClassPtr((CMBaseMonster *)VARS(pAttacker));
char szCheck[2];
strncpy( szCheck, STRING( pMonster->m_szMonsterName ), 1 );
// Make the first character lowercase
szCheck[0] = tolower( szCheck[ 0 ] );
if ( strncmp( szCheck, "a", 1 ) == 0 || strncmp( szCheck, "e", 1 ) == 0 || strncmp( szCheck, "i", 1 ) == 0 || strncmp( szCheck, "o", 1 ) == 0 || strncmp( szCheck, "u", 1 ) == 0 )
sprintf( szMessage, "* %s was killed by an %s.\n", szPlayerName, STRING( pMonster->m_szMonsterName ) );
else
sprintf( szMessage, "* %s was killed by a %s.\n", szPlayerName, STRING( pMonster->m_szMonsterName ) );
} }
else else
{ {
@@ -475,8 +486,8 @@ void check_player_dead( edict_t *pPlayer )
void check_monster_info( edict_t *pPlayer ) void check_monster_info( edict_t *pPlayer )
{ {
// Monster Info is disabled // Monster Info is disabled
//if (!monster_show_info->value) if (!monster_show_info->value)
//return; return;
// Player must be alive // Player must be alive
if ( UTIL_IsAlive( pPlayer ) ) if ( UTIL_IsAlive( pPlayer ) )
@@ -508,10 +519,10 @@ void check_monster_info( edict_t *pPlayer )
if (tr.pHit->v.flags & FL_MONSTER) if (tr.pHit->v.flags & FL_MONSTER)
{ {
// Get monster info // Get monster info
// TODO: Add monster custom name and count monster frags CMBaseMonster *pMonster = GetClassPtr((CMBaseMonster *)VARS(tr.pHit));
edict_t *pMonster = tr.pHit;
char szInfo[512]; char szInfo[512];
sprintf(szInfo, "Enemy: %s\nHealth: %.0f\nFrags: %.0f\n", STRING( pMonster->v.classname ), pMonster->v.health, pMonster->v.frags ); sprintf(szInfo, "Enemy: %s\nHealth: %.0f\nFrags: %.0f\n", STRING( pMonster->m_szMonsterName ), pMonster->pev->health, pMonster->pev->frags );
// Create a TE_TEXTMESSAGE and show the monster information // Create a TE_TEXTMESSAGE and show the monster information
MESSAGE_BEGIN( MSG_ONE, SVC_TEMPENTITY, NULL, pPlayer ); MESSAGE_BEGIN( MSG_ONE, SVC_TEMPENTITY, NULL, pPlayer );
@@ -1229,7 +1240,7 @@ void mmDispatchThink( edict_t *pent )
{ {
monsters[index].pMonster->Think(); monsters[index].pMonster->Think();
check_monster_dead(); check_monster_dead(pent);
RETURN_META(MRES_SUPERCEDE); RETURN_META(MRES_SUPERCEDE);
} }
@@ -1251,7 +1262,7 @@ void mmDispatchTouch( edict_t *pentTouched, edict_t *pentOther )
{ {
monsters[index].pMonster->Touch(pentOther); monsters[index].pMonster->Touch(pentOther);
check_monster_dead(); check_monster_dead(pentOther);
RETURN_META(MRES_SUPERCEDE); RETURN_META(MRES_SUPERCEDE);
} }
@@ -1463,7 +1474,7 @@ C_DLLEXPORT int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVers
void mmDispatchThink_Post( edict_t *pent ) void mmDispatchThink_Post( edict_t *pent )
{ {
check_monster_hurt(pent); check_monster_hurt(pent);
check_monster_dead(); check_monster_dead(pent);
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
@@ -1471,7 +1482,7 @@ void mmDispatchThink_Post( edict_t *pent )
void mmPlayerPostThink_Post( edict_t *pEntity ) void mmPlayerPostThink_Post( edict_t *pEntity )
{ {
check_monster_hurt(pEntity); check_monster_hurt(pEntity);
check_monster_dead(); check_monster_dead(pEntity);
check_player_dead(pEntity); check_player_dead(pEntity);
check_monster_info(pEntity); check_monster_info(pEntity);

View File

@@ -686,6 +686,11 @@ void CMGargantua :: Spawn()
m_flameTime = gpGlobals->time + 2; m_flameTime = gpGlobals->time + 2;
pev->classname = MAKE_STRING( "monster_gargantua" ); pev->classname = MAKE_STRING( "monster_gargantua" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Gargantua" );
}
} }

View File

@@ -228,10 +228,15 @@ void CMHAssassin :: Spawn()
m_iTargetRanderamt = 20; m_iTargetRanderamt = 20;
pev->renderamt = 20; pev->renderamt = 20;
pev->rendermode = kRenderTransTexture; pev->rendermode = kRenderTransTexture;
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_human_assassin" ); pev->classname = MAKE_STRING( "monster_human_assassin" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Female Assassin" );
}
} }
//========================================================= //=========================================================

View File

@@ -258,6 +258,11 @@ void CMHeadCrab :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_headcrab" ); pev->classname = MAKE_STRING( "monster_headcrab" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Head Crab" );
}
} }
//========================================================= //=========================================================

View File

@@ -888,6 +888,11 @@ void CMHGrunt :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_human_grunt" ); pev->classname = MAKE_STRING( "monster_human_grunt" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Human Grunt" );
}
} }
//========================================================= //=========================================================

View File

@@ -49,7 +49,7 @@ void CMHornet :: Spawn( void )
pev->movetype = MOVETYPE_FLY; pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX; pev->solid = SOLID_BBOX;
pev->takedamage = DAMAGE_YES; pev->takedamage = DAMAGE_YES;
pev->flags |= FL_MONSTER; pev->flags |= FL_MONSTER; // I have a bad feeling about this
pev->health = 1;// weak! pev->health = 1;// weak!
// hornets don't live as long in multiplayer // hornets don't live as long in multiplayer
@@ -83,6 +83,8 @@ void CMHornet :: Spawn( void )
pev->nextthink = gpGlobals->time + 0.1; pev->nextthink = gpGlobals->time + 0.1;
ResetSequenceInfo( ); ResetSequenceInfo( );
pev->classname = MAKE_STRING( "hornet" );
} }

View File

@@ -279,6 +279,11 @@ void CMHoundeye :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_houndeye" ); pev->classname = MAKE_STRING( "monster_houndeye" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Houndeye" );
}
} }
//========================================================= //=========================================================

View File

@@ -434,6 +434,11 @@ void CMISlave :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_alien_slave" ); pev->classname = MAKE_STRING( "monster_alien_slave" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Alien Slave" );
}
} }
//========================================================= //=========================================================

View File

@@ -85,6 +85,8 @@ cvar_t init_monster_spawn = {"monster_spawn", "1", FCVAR_EXTDLL, 0, NULL};
cvar_t *monster_spawn = NULL; cvar_t *monster_spawn = NULL;
cvar_t init_monster_show_deaths = {"monster_show_deaths", "1", FCVAR_EXTDLL, 0, NULL}; cvar_t init_monster_show_deaths = {"monster_show_deaths", "1", FCVAR_EXTDLL, 0, NULL};
cvar_t *monster_show_deaths = NULL; cvar_t *monster_show_deaths = NULL;
cvar_t init_monster_show_info = {"monster_show_info", "1", FCVAR_EXTDLL, 0, NULL};
cvar_t *monster_show_info = NULL;
// Metamod requesting info about this plugin: // Metamod requesting info about this plugin:
@@ -141,6 +143,9 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
CVAR_REGISTER(&init_monster_show_deaths); CVAR_REGISTER(&init_monster_show_deaths);
monster_show_deaths = CVAR_GET_POINTER("monster_show_deaths"); monster_show_deaths = CVAR_GET_POINTER("monster_show_deaths");
CVAR_REGISTER(&init_monster_show_info);
monster_show_info = CVAR_GET_POINTER("monster_show_info");
return(TRUE); return(TRUE);
} }

View File

@@ -2504,11 +2504,16 @@ void CMBaseMonster :: KeyValue( KeyValueData *pkvd )
m_iszTriggerTarget = ALLOC_STRING( pkvd->szValue ); m_iszTriggerTarget = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = TRUE; pkvd->fHandled = TRUE;
} }
else if (FStrEq(pkvd->szKeyName, "TriggerCondition") ) else if (FStrEq(pkvd->szKeyName, "TriggerCondition"))
{ {
m_iTriggerCondition = atoi( pkvd->szValue ); m_iTriggerCondition = atoi( pkvd->szValue );
pkvd->fHandled = TRUE; pkvd->fHandled = TRUE;
} }
else if (FStrEq(pkvd->szKeyName, "displayname"))
{
m_szMonsterName = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else else
{ {
CMBaseToggle::KeyValue( pkvd ); CMBaseToggle::KeyValue( pkvd );

View File

@@ -618,6 +618,11 @@ void CMScientist :: Spawn( void )
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_scientist" ); pev->classname = MAKE_STRING( "monster_scientist" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Scientist" );
}
} }
//========================================================= //=========================================================

View File

@@ -86,6 +86,11 @@ void CMSqueakGrenade :: Spawn( void )
m_hEnemy = NULL; m_hEnemy = NULL;
pev->classname = MAKE_STRING( "monster_snark" ); pev->classname = MAKE_STRING( "monster_snark" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// hi :3
m_szMonsterName = MAKE_STRING( "Snark" );
}
} }
void CMSqueakGrenade::Precache( void ) void CMSqueakGrenade::Precache( void )

View File

@@ -144,6 +144,11 @@ void CMTurret::Spawn()
pev->nextthink = gpGlobals->time + 0.3; pev->nextthink = gpGlobals->time + 0.3;
pev->classname = MAKE_STRING( "monster_turret" ); pev->classname = MAKE_STRING( "monster_turret" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Turret" );
}
} }
void CMTurret::Precache() void CMTurret::Precache()
@@ -172,6 +177,11 @@ void CMMiniTurret::Spawn()
pev->nextthink = gpGlobals->time + 0.3; pev->nextthink = gpGlobals->time + 0.3;
pev->classname = MAKE_STRING( "monster_miniturret" ); pev->classname = MAKE_STRING( "monster_miniturret" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Mini-Turret" );
}
} }
@@ -1014,6 +1024,11 @@ void CMSentry::Spawn()
pev->nextthink = gpGlobals->time + 0.3; pev->nextthink = gpGlobals->time + 0.3;
pev->classname = MAKE_STRING( "monster_sentry" ); pev->classname = MAKE_STRING( "monster_sentry" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Sentry Turret" );
}
} }
void CMSentry::Shoot(Vector &vecSrc, Vector &vecDirToEnemy) void CMSentry::Shoot(Vector &vecSrc, Vector &vecDirToEnemy)

View File

@@ -1762,6 +1762,10 @@ int UTIL_TakeDamage( edict_t *pEdict, entvars_t *pevInflictor, entvars_t *pevAtt
{ {
pEdict->v.health = 1; // can't suicide if already dead! pEdict->v.health = 1; // can't suicide if already dead!
gpGamedllFuncs->dllapi_table->pfnClientKill(pEdict); gpGamedllFuncs->dllapi_table->pfnClientKill(pEdict);
// Add 1 score to the monster that killed this player
if ( pevAttacker->flags & FL_MONSTER )
pevAttacker->frags += 1.0;
} }
// tell director about it // tell director about it

View File

@@ -256,6 +256,11 @@ void CMZombie :: Spawn()
MonsterInit(); MonsterInit();
pev->classname = MAKE_STRING( "monster_zombie" ); pev->classname = MAKE_STRING( "monster_zombie" );
if ( strlen( STRING( m_szMonsterName ) ) == 0 )
{
// default name
m_szMonsterName = MAKE_STRING( "Zombie" );
}
} }
//========================================================= //=========================================================