class CHEVScientist : public CSquadMonster
{
public:
void Spawn(void);
void Precache(void);
int iSpikes;
int Classify(void);
void SetYawSpeed(void);
};
However, you are defining or implementing a method down here:
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void CHEVScientist::HandleAnimEvent(MonsterEvent_t* pEvent)
{
...
}
Which is not declared in your class above. If you don't understand what I'm saying (methods, implemented, declared), then:Ah, You caught me, good prank?Thanks for wasting my time I guess.
class Class
{
public:
void Method()
{
// Avoid doing this if possible
}
};
// Class.h
class Class
{
public:
void Method();
}
// Class.cpp
void Class::Method()
{
// Do prefer doing this in .cpp files - sometimes it may not be possible
}
This is because of how declarations work in C and C++. When a header is #include
-ed into a .cpp file, it is literally copy-pasted there, together with other headers. If a datatype is declared above some code, then that code is quite simply "aware" that it exists.CBasePlayer
wasn't declared in one of these situations. So you gotta move that code into a .cpp and include player.h
to get the CBasePlayer
declaration. Or, if you absolutely have to do it in a header, you can use forward-declaration:
class CBasePlayer; // this class is more fully declared elsewhere
pOther
. It's probably an entvars_t*
which you first must convert into a CBaseEntity*
via some utility.Yeah, after a few days working with SDK, I'm starting to think that guys from Valve didn't know about any good coding practices or principles back in 1998.They knew about good principles, they just didn't really have the time to apply em. Between 1996 and 1998, the game spec changed so rapidly and so much, nobody could really keep up. Game code is very patchy, very volatile, and rapidly evolves. It's simply like that by nature.
but I also want to ask how to getCBasePlayer
fromCBaseEntity
if ( pEntity->IsPlayer() )
{
CBasePlayer* player = static_cast<CBasePlayer*>( pEntity );
...
}
It is possible you were getting errors because you were casting to CBasePlayer
and not CBasePlayer*
. This is just C++'s value and reference semantics. In C#, a value type is a struct. In C++, a value type is anything that isn't a pointer. So you were trying to, essentially, convert a reference type into a value type there. Possibly, I'm just guessing.IsPlayer
or checking pev->classname
), you use static_cast
. static_cast
will throw if the cast fails.dynamic_cast
(a bit like the is
keyword in C# but simultaneously it's an as
)template<class T>
T* As()
{
return static_cast<T*>( this );
}
template<class T>
T* TryAs()
{
if ( Is<T>() )
{
return As<T>();
}
return nullptr;
}
template<class T>
bool Is()
{
return dynamic_cast<T*>( this ) != nullptr;
}
Usage:
if ( pEntity->Is<CBasePlayer>() )
{
pEntity->As<CBasePlayer>()->DoPlayerSpecificStuff();
// or
CBasePlayer* player = pEntity->As<CBasePlayer>();
}
flTime
and others, that is the absolute time (in seconds) since the client started... something, I am not 100% sure if it's since joining the server or starting up the game altogether, but it's likely the latter.gHUD
is the HUD singleton. It represents the clientside as a whole, almost a bit of a god object I'm afraid..inline int gmsgMyMessage
) and register it, i.e. link it to a name: gmsgMyMessage = REGISTER_USER_MSG( "MyMessage", -1 )
, the last number saying how many bytes are sent in this message, -1 if unknownDECLARE_MESSAGE
and HOOK_MESSAGE
It is a hybrid server that runs both mods so both HL and CS clients can connect.This is gonna be interesting.
GetScheduleOfType
, probably an SDK difference of some sort? In either case you can also edit the tutorial itself.Personally, i strongly believe they are developing somethingI'm sure they're always developing something. I'm guessing that, right now, the gamedev work is mainly distributed across Deadlock (production and testing) and Counter-Strike 2 (maintenance and hopefully content updates), with maybe, maybe just a little bit of wiggle room? For an unannounced game in an early prototyping stage?
CGameRules
and the code around it.InstallGameRules
(assuming they'd be implemented as gamerules) instead of mangling with different DLLs. The latter could be pretty messy.