[HL1] Create my own monster

Hi,

I'm impressed that Alien Grunt's in Sven Co-op throwing a snark/squeak nest and wanted to trying to make the same for my own mod.
But I'm new to C++ (not trained) and need some help on the way.

I have start with the squeak nest already.

The whole project/workspace it belongs to:
http://hpb-bot.bots-united.com/monster.html

cmbasemonster.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class CMSQNest : public CMBaseMonster
{
public:
	void Spawn( void );
	void Precache( void );
	void SetYawSpeed( void );
	int  Classify ( void );
	void HandleAnimEvent( MonsterEvent_t *pEvent );
	void RunAI( void );
	int  TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType );
	void Killed( entvars_t *pevAttacker, int iGib );
	BOOL CheckMeleeAttack1 ( float flDot, float flDist );
	Schedule_t *GetSchedule( void );
};

squeaknest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include	"extdll.h"
#include	"util.h"
#include	"cmbase.h"
#include    "cmbasemonster.h"
#include	"monsters.h"
#include	"defaultai.h"
#include	"schedule.h"
#include	"weapons.h"
#include	"decals.h"

#define		SQNEST_SPRINT_DIST	456

//=========================================================
// Monster's Anim Events Go Here
//=========================================================

// None yet


//=========================================================
// Classify - indicates this monster's place in the 
// relationship table.
//=========================================================
int	CMSQNest :: Classify ( void )
{
	return	CLASS_ALIEN_MONSTER;
}

//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
void CMSQNest :: SetYawSpeed ( void )
{
	pev->yaw_speed = 9999;
}

//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void CMSQNest :: HandleAnimEvent( MonsterEvent_t *pEvent )
{
	/*switch( pEvent->event )
	{
	case 0:
	default:*/
		CMBaseMonster::HandleAnimEvent( pEvent );
		/*break;
	}*/
}

//=========================================================
// CheckMeleeAttack1 - alien grunts zap the crap out of 
// any enemy that gets too close. 
//=========================================================
BOOL CMSQNest :: CheckMeleeAttack1 ( float flDot, float flDist )
{
	if ( HasConditions ( bits_COND_SEE_ENEMY ) && flDist <= 80.0 && flDot >= 0.5 && m_hEnemy != NULL )
	{
		//return CMSQNest::Killed( );
	}
	return FALSE;
}

//=========================================================
// Spawn
//=========================================================
void CMSQNest :: Spawn()
{
	Precache();

	SET_MODEL( ENT(pev), "models/w_sqknest.mdl" );
	UTIL_SetSize(pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX);

	pev->solid			= SOLID_SLIDEBOX;
	pev->movetype		= MOVETYPE_STEP;
	m_bloodColor		= BLOOD_COLOR_GREEN;
	pev->health			= 5;
	pev->view_ofs		= VEC_VIEW;// position of the eyes relative to monster's origin.
	m_flFieldOfView		= VIEW_FIELD_FULL;// indicates the width of this monster's forward view cone ( as a dotproduct result )
	m_MonsterState		= MONSTERSTATE_NONE;

	MonsterInit();
}

//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
void CMSQNest :: Precache()
{
	PRECACHE_MODEL( "models/w_sqknest.mdl" );
	PRECACHE_MODEL( "models/w_sqknestt.mdl" );

	PRECACHE_MODEL("models/w_squeak.mdl");
	PRECACHE_SOUND("squeek/sqk_blast1.wav");
	PRECACHE_SOUND("common/bodysplat.wav");
	PRECACHE_SOUND("squeek/sqk_die1.wav");
	PRECACHE_SOUND("squeek/sqk_hunt1.wav");
	PRECACHE_SOUND("squeek/sqk_hunt2.wav");
	PRECACHE_SOUND("squeek/sqk_hunt3.wav");
	PRECACHE_SOUND("squeek/sqk_deploy1.wav");
}

//========================================================
// RunAI - overridden for gonome because there are things
// that need to be checked every think.
//========================================================
void CMSQNest :: RunAI ( void )
{
	// first, do base class stuff
	CMBaseMonster :: RunAI();

	if ( m_hEnemy != NULL && m_Activity == ACT_WALK )
	{
		// chasing enemy. Sprint for last bit
		if ( (pev->origin - m_hEnemy->v.origin).Length2D() < SQNEST_SPRINT_DIST )
		{
			pev->framerate = 1.25;
		}
	}
}

//=========================================================
// GetSchedule - Decides which type of schedule best suits
// the monster's current state and conditions. Then calls
// monster's member function to get a pointer to a schedule
// of the proper type.
//=========================================================
Schedule_t *CMSQNest :: GetSchedule( void )
{
	switch	( m_MonsterState )
	{
	case MONSTERSTATE_COMBAT:
			// dead enemy
			if ( HasConditions( bits_COND_ENEMY_DEAD ) )
			{
				// call base class, all code to handle dead enemies is centralized there.
				return CMBaseMonster :: GetSchedule();
			}
			if ( HasConditions(bits_COND_NEW_ENEMY) )
			{
				return GetScheduleOfType( SCHED_WAKE_ANGRY );
			}

			return GetScheduleOfType ( SCHED_CHASE_ENEMY );

			break;
	}
	return CMBaseMonster :: GetSchedule();
}

//=========================================================
// Override all damage
//=========================================================
int CMSQNest :: TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType )
{
	return CMBaseMonster :: TakeDamage ( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}

void CMSQNest::Killed( entvars_t *pevAttacker, int iGib )
{
	CMSqueakGrenade *pSqueak = CreateClassPtr((CMSqueakGrenade *)NULL);

	if (pSqueak != NULL)
	{
		pSqueak->pev->origin = pev->origin;
		pSqueak->pev->owner = edict();

		pSqueak->Spawn();

		TraceResult tr;
		UTIL_TraceLine( pev->origin, pev->origin - Vector(0,0,100), ignore_monsters, edict(), &tr);
		UTIL_DecalTrace( &tr, DECAL_BLOOD1 );
	}
	UTIL_BloodDrips( pev->origin, g_vecZero, BloodColor(), 80 );
	SetThink( SUB_Remove );
}

Spawns fine, but it won't move.
If I get close enough (within SQNEST_SPRINT_DIST) to it so do I recognize it want to "walk" towards the enemy/player, because it start to make frames but it's just staying there and making frames repeatedly like it want to "walk".
Hi there,

You may have better luck asking this question in the "general C++ programming" forum - this isn't exactly beginner stuff.

Hope that helps.

All the best,
NwN
Topic archived. No new replies allowed.