Npc New.cpp: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Source file npc_new.cpp is also known as monster_dummy.cpp; found in newly created mod folders and used as a template for creating a new npc from scratch. //========= Copyright ...") |
Le Glaconus (talk | contribs) mNo edit summary |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Dead end|date=January 2024}} | |||
== npc_New.cpp == | |||
<source lang=cpp> | |||
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// | //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// | ||
// This is a skeleton file for use when creating a new | // This is a skeleton file for use when creating a new | ||
Line 6: | Line 9: | ||
// NPC and add the copy to the build. | // NPC and add the copy to the build. | ||
// | // | ||
// Replace occurrences of CNPC_New with the new NPC's | |||
// classname. Don't forget the lower-case occurrence in | |||
// Replace | |||
// classname. Don't forget the lower-case | |||
// LINK_ENTITY_TO_CLASS() | // LINK_ENTITY_TO_CLASS() | ||
// | // | ||
Line 18: | Line 17: | ||
// | // | ||
// You're making a character based on CAI_BaseNPC. If this | // You're making a character based on CAI_BaseNPC. If this | ||
// is not true, make sure you replace all | // is not true, make sure you replace all occurrences | ||
// of 'CAI_BaseNPC' in this file with the appropriate | // of 'CAI_BaseNPC' in this file with the appropriate | ||
// parent class. | // parent class. | ||
Line 30: | Line 29: | ||
#include "ai_schedule.h" | #include "ai_schedule.h" | ||
#include "ai_hull.h" | #include "ai_hull.h" | ||
#include "ai_squad.h" | |||
#include "soundent.h" | #include "soundent.h" | ||
#include "game.h" | #include "game.h" | ||
Line 37: | Line 37: | ||
#include "ai_basenpc.h" | #include "ai_basenpc.h" | ||
#include "engine/IEngineSound.h" | #include "engine/IEngineSound.h" | ||
#define NPC_NEW_MODEL "models/mymodel.mdl" | |||
// memdbgon must be the last include file in a .cpp file!!! | // memdbgon must be the last include file in a .cpp file!!! | ||
Line 42: | Line 44: | ||
//========================================================= | //========================================================= | ||
// Private | // Private animevents | ||
//========================================================= | //========================================================= | ||
int | int NEWNPC_AE_ANIMEVENT; | ||
int NEWNPC_AE_ANIMEVENT2; | |||
//========================================================= | //========================================================= | ||
// | // Private activities | ||
//========================================================= | //========================================================= | ||
Activity ACT_NEWNPC_ACTIVITY; | |||
Activity ACT_NEWNPC_ACTIVITY2; | |||
//========================================================= | //========================================================= | ||
// | // Shared interaction | ||
//========================================================= | //========================================================= | ||
int g_interactionExample = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h | |||
int g_interactionExample2 = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h | |||
// | // ----------------------------------------------- | ||
// | // > Squad slots | ||
// | // ----------------------------------------------- | ||
enum | enum SquadSlot_T | ||
{ | { | ||
SQUAD_SLOT_EXAMPLE = LAST_SHARED_SQUADSLOT, | |||
SQUAD_SLOT_EXAMPLE2, | |||
}; | }; | ||
//========================================================= | //========================================================= | ||
//========================================================= | //========================================================= | ||
class | class CNPC_New : public CAI_BaseNPC | ||
{ | { | ||
DECLARE_CLASS( | DECLARE_CLASS( CNPC_New, CAI_BaseNPC ); | ||
DECLARE_DATADESC(); | |||
DEFINE_CUSTOM_AI; | |||
public: | public: | ||
Line 82: | Line 82: | ||
void Spawn( void ); | void Spawn( void ); | ||
Class_T Classify( void ); | Class_T Classify( void ); | ||
private: | |||
enum | |||
{ | |||
SCHED_NEWNPC_SCHEDULE = BaseClass::NEXT_SCHEDULE, | |||
SCHED_NEWNPC_SCHEDULE2, | |||
NEXT_SCHEDULE | |||
}; | |||
enum | |||
{ | |||
TASK_NEWNPC_TASK = BaseClass::NEXT_TASK, | |||
TASK_NEWNPC_TASK2, | |||
NEXT_TASK | |||
}; | |||
enum | |||
{ | |||
COND_NEWNPC_CONDITION = BaseClass::NEXT_CONDITION, | |||
COND_NEWNPC_CONDITION2, | |||
NEXT_CONDITION | |||
}; | |||
}; | }; | ||
LINK_ENTITY_TO_CLASS( npc_newnpc, | LINK_ENTITY_TO_CLASS( npc_newnpc, CNPC_New ); | ||
//--------------------------------------------------------- | //--------------------------------------------------------- | ||
// Save/Restore | // Save/Restore | ||
//--------------------------------------------------------- | //--------------------------------------------------------- | ||
BEGIN_DATADESC( | BEGIN_DATADESC( CNPC_New ) | ||
END_DATADESC() | END_DATADESC() | ||
AI_BEGIN_CUSTOM_NPC(npc_newnpc, CNPC_New) | |||
AI_END_CUSTOM_NPC() | |||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
Line 131: | Line 123: | ||
// | // | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
void | void CNPC_New::Precache( void ) | ||
{ | { | ||
PrecacheModel( | PrecacheModel( NPC_NEW_MODEL ); | ||
BaseClass::Precache(); | BaseClass::Precache(); | ||
} | } | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
Line 144: | Line 135: | ||
// | // | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
void | void CNPC_New::Spawn( void ) | ||
{ | { | ||
Precache(); | Precache(); | ||
SetModel( | SetModel( NPC_NEW_MODEL ); | ||
SetHullType(HULL_HUMAN); | SetHullType(HULL_HUMAN); | ||
SetHullSizeNormal(); | SetHullSizeNormal(); | ||
Line 156: | Line 147: | ||
SetMoveType( MOVETYPE_STEP ); | SetMoveType( MOVETYPE_STEP ); | ||
SetBloodColor( BLOOD_COLOR_RED ); | SetBloodColor( BLOOD_COLOR_RED ); | ||
m_iHealth | m_iHealth = 20; | ||
m_flFieldOfView | m_flFieldOfView = 0.5; // indicates the width of this NPC's forward view cone ( as a dotproduct result ) | ||
m_NPCState | m_NPCState = NPC_STATE_NONE; | ||
CapabilitiesClear(); | CapabilitiesClear(); | ||
CapabilitiesAdd( bits_CAP_TURN_HEAD | bits_CAP_MOVE_GROUND ); | |||
NPCInit(); | NPCInit(); | ||
} | } | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
Line 173: | Line 163: | ||
// Output : | // Output : | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
Class_T | Class_T CNPC_New::Classify( void ) | ||
{ | { | ||
return CLASS_NONE; | return CLASS_NONE; | ||
} | }</source> | ||
{{Uncategorized|date=January 2024}} |
Latest revision as of 12:12, 30 May 2025

This article has no
links to other VDC articles. Please help improve this article by adding links
that are relevant to the context within the existing text.
January 2024


January 2024
npc_New.cpp
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
// This is a skeleton file for use when creating a new
// NPC. Copy and rename this file for the new
// NPC and add the copy to the build.
//
// Replace occurrences of CNPC_New with the new NPC's
// classname. Don't forget the lower-case occurrence in
// LINK_ENTITY_TO_CLASS()
//
//
// ASSUMPTIONS MADE:
//
// You're making a character based on CAI_BaseNPC. If this
// is not true, make sure you replace all occurrences
// of 'CAI_BaseNPC' in this file with the appropriate
// parent class.
//
// You're making a human-sized NPC that walks.
//
//=============================================================================//
#include "cbase.h"
#include "ai_default.h"
#include "ai_task.h"
#include "ai_schedule.h"
#include "ai_hull.h"
#include "ai_squad.h"
#include "soundent.h"
#include "game.h"
#include "npcevent.h"
#include "entitylist.h"
#include "activitylist.h"
#include "ai_basenpc.h"
#include "engine/IEngineSound.h"
#define NPC_NEW_MODEL "models/mymodel.mdl"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//=========================================================
// Private animevents
//=========================================================
int NEWNPC_AE_ANIMEVENT;
int NEWNPC_AE_ANIMEVENT2;
//=========================================================
// Private activities
//=========================================================
Activity ACT_NEWNPC_ACTIVITY;
Activity ACT_NEWNPC_ACTIVITY2;
//=========================================================
// Shared interaction
//=========================================================
int g_interactionExample = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h
int g_interactionExample2 = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h
// -----------------------------------------------
// > Squad slots
// -----------------------------------------------
enum SquadSlot_T
{
SQUAD_SLOT_EXAMPLE = LAST_SHARED_SQUADSLOT,
SQUAD_SLOT_EXAMPLE2,
};
//=========================================================
//=========================================================
class CNPC_New : public CAI_BaseNPC
{
DECLARE_CLASS( CNPC_New, CAI_BaseNPC );
DECLARE_DATADESC();
DEFINE_CUSTOM_AI;
public:
void Precache( void );
void Spawn( void );
Class_T Classify( void );
private:
enum
{
SCHED_NEWNPC_SCHEDULE = BaseClass::NEXT_SCHEDULE,
SCHED_NEWNPC_SCHEDULE2,
NEXT_SCHEDULE
};
enum
{
TASK_NEWNPC_TASK = BaseClass::NEXT_TASK,
TASK_NEWNPC_TASK2,
NEXT_TASK
};
enum
{
COND_NEWNPC_CONDITION = BaseClass::NEXT_CONDITION,
COND_NEWNPC_CONDITION2,
NEXT_CONDITION
};
};
LINK_ENTITY_TO_CLASS( npc_newnpc, CNPC_New );
//---------------------------------------------------------
// Save/Restore
//---------------------------------------------------------
BEGIN_DATADESC( CNPC_New )
END_DATADESC()
AI_BEGIN_CUSTOM_NPC(npc_newnpc, CNPC_New)
AI_END_CUSTOM_NPC()
//-----------------------------------------------------------------------------
// Purpose:
//
//
//-----------------------------------------------------------------------------
void CNPC_New::Precache( void )
{
PrecacheModel( NPC_NEW_MODEL );
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose:
//
//
//-----------------------------------------------------------------------------
void CNPC_New::Spawn( void )
{
Precache();
SetModel( NPC_NEW_MODEL );
SetHullType(HULL_HUMAN);
SetHullSizeNormal();
SetSolid( SOLID_BBOX );
AddSolidFlags( FSOLID_NOT_STANDABLE );
SetMoveType( MOVETYPE_STEP );
SetBloodColor( BLOOD_COLOR_RED );
m_iHealth = 20;
m_flFieldOfView = 0.5; // indicates the width of this NPC's forward view cone ( as a dotproduct result )
m_NPCState = NPC_STATE_NONE;
CapabilitiesClear();
CapabilitiesAdd( bits_CAP_TURN_HEAD | bits_CAP_MOVE_GROUND );
NPCInit();
}
//-----------------------------------------------------------------------------
// Purpose:
//
//
// Output :
//-----------------------------------------------------------------------------
Class_T CNPC_New::Classify( void )
{
return CLASS_NONE;
}

This article has not been added to any content
categories. Please help out by
adding categories.
January 2024


January 2024