Npc New.cpp

From Valve Developer Community
Revision as of 23:08, 1 February 2013 by M4pster (talk | contribs) (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 ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 © 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. // // Leave this file in the build until we ship! Allowing // this file to be rebuilt with the rest of the game ensures // that it stays up to date with the rest of the NPC code. // // Replace occurances of CNewNPC with the new NPC's // classname. Don't forget the lower-case occurance 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 occurances // of 'CAI_BaseNPC' in this file with the appropriate // parent class. // // You're making a human-sized NPC that walks. // //=============================================================================//

  1. include "cbase.h"
  2. include "ai_default.h"
  3. include "ai_task.h"
  4. include "ai_schedule.h"
  5. include "ai_hull.h"
  6. include "soundent.h"
  7. include "game.h"
  8. include "npcevent.h"
  9. include "entitylist.h"
  10. include "activitylist.h"
  11. include "ai_basenpc.h"
  12. include "engine/IEngineSound.h"

// memdbgon must be the last include file in a .cpp file!!!

  1. include "tier0/memdbgon.h"

//========================================================= // Private activities //========================================================= int ACT_MYCUSTOMACTIVITY = -1;

//========================================================= // Custom schedules //========================================================= enum { SCHED_MYCUSTOMSCHEDULE = LAST_SHARED_SCHEDULE, };

//========================================================= // Custom tasks //========================================================= enum { TASK_MYCUSTOMTASK = LAST_SHARED_TASK, };


//========================================================= // Custom Conditions //========================================================= enum { COND_MYCUSTOMCONDITION = LAST_SHARED_CONDITION, };


//========================================================= //========================================================= class CNewNPC : public CAI_BaseNPC { DECLARE_CLASS( CNewNPC, CAI_BaseNPC );

public: void Precache( void ); void Spawn( void ); Class_T Classify( void );

DECLARE_DATADESC();

// This is a dummy field. In order to provide save/restore // code in this file, we must have at least one field // for the code to operate on. Delete this field when // you are ready to do your own save/restore for this // character. int m_iDeleteThisField;

DEFINE_CUSTOM_AI; };

LINK_ENTITY_TO_CLASS( npc_newnpc, CNewNPC ); IMPLEMENT_CUSTOM_AI( npc_citizen,CNewNPC );


//--------------------------------------------------------- // Save/Restore //--------------------------------------------------------- BEGIN_DATADESC( CNewNPC )

DEFINE_FIELD( m_iDeleteThisField, FIELD_INTEGER ),

END_DATADESC()

//----------------------------------------------------------------------------- // Purpose: Initialize the custom schedules // Input  : // Output : //----------------------------------------------------------------------------- void CNewNPC::InitCustomSchedules(void) { INIT_CUSTOM_AI(CNewNPC);

ADD_CUSTOM_TASK(CNewNPC, TASK_MYCUSTOMTASK);

ADD_CUSTOM_SCHEDULE(CNewNPC, SCHED_MYCUSTOMSCHEDULE);

ADD_CUSTOM_ACTIVITY(CNewNPC, ACT_MYCUSTOMACTIVITY);

ADD_CUSTOM_CONDITION(CNewNPC, COND_MYCUSTOMCONDITION); }

//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CNewNPC::Precache( void ) { PrecacheModel( "models/mymodel.mdl" );

BaseClass::Precache(); }


//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CNewNPC::Spawn( void ) { Precache();

SetModel( "models/mymodel.mdl" ); 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; m_NPCState = NPC_STATE_NONE;

CapabilitiesClear(); //CapabilitiesAdd( bits_CAP_NONE );

NPCInit(); }


//----------------------------------------------------------------------------- // Purpose: // // // Output : //----------------------------------------------------------------------------- Class_T CNewNPC::Classify( void ) { return CLASS_NONE; }

--M4pster 22:08, 1 February 2013 (PST)