[Noob Question] Model Entity

Grab your favourite IDE and tinker with the innards of game engines

[Noob Question] Model Entity

Postby TickingHands on Sat Jun 26, 2010 3:15 am

I've been following this tutorial: http://developer.valvesoftware.com/wiki/Authoring_a_Model_Entity

So I've reached the end(didn't animate it yet), and then I have compiled the source code (Game_HL2-2005 project).
I have the console command code in the .cpp, however, when I go in game(after debug) I cannot use the console command "create_sdk_modelentity". It claims it is an unknown command...

So...how do I get it into the game? In hammer (even though I've done the .fgd code) the entity doesn't show up, unless I'm looking in the wrong place...

P.S. Is it important that when I debug it says it cannot find the symbols or something?

Thanks for the help in advance.

Edit: If anyone wants any more information, please do tell. Or is a stupid question and you are all just "lol'ing"?
TickingHands
Member
Member
 
Joined: Thu Nov 19, 2009 1:56 am

Re: [Noob Question] Model Entity

Postby audryzas on Sat Jun 26, 2010 9:11 am

So it works in debug right?
So you probably compiled in in debug, but didn't compile it in release?
audryzas
Member
Member
 
Joined: Sun Jun 20, 2010 2:58 pm

Re: [Noob Question] Model Entity

Postby TickingHands on Sat Jun 26, 2010 5:51 pm

Uhm, well so when I compiled I had it use the hl2.exe. It just launches Half life 2 to the menu screen. So...I tried to load a random map and I did, then tried to use the console command "create_sdk_modelentity" but it claimed it was an unknown command.

I didn't try to compile it in release yet, should I try that out? But yes, in debug the only error I had was after it built and it said something about "symbols", it let me continue anyhow.

Edit: Well I compiled it as Release, didn't do anything...
Also, I checked the path where the tutorial said the model would be, yet I didn't see it.
Tutorial wrote:// Name of our entity's model
#define ENTITY_MODEL "models/gibs/airboat_broken_engine.mdl"
This hard-codes the model that our entity will present to the world. This is a static piece of information, not a variable: it cannot change once the code has been compiled. The path to the .mdl file is relative to the game directory (e.g. hl2/).
Note: We are only creating this define to make finding and changing its value later on easier. It has no effect on how our code works.


Though that shouldn't matter, the console still didn't recognize the command. Ayeyeye, what did I screw up eh? lol

Edit 2: Hmm, I just tried to run my mod through steam...It flashed the Half-life 2 background and made the that valve sound/music that crashed, with no errors. So, I guess that doesn't work.
TickingHands
Member
Member
 
Joined: Thu Nov 19, 2009 1:56 am

Re: [Noob Question] Model Entity

Postby TickingHands on Tue Jun 29, 2010 6:39 pm

Not to bump...but it has had 80 views and only 1 reply from another person.

Do you want to see the .fgd file for my mod? Or would the source code of what I typed up ( I don't copy/paste tutorials... )?
Or should I just be restarting everything to see if that works?

It seems either the question is too vague or stupid or maybe you just don't know...Still, a reply would be nice esp. if there is more info I could give which would help you assist me.
TickingHands
Member
Member
 
Joined: Thu Nov 19, 2009 1:56 am

Re: [Noob Question] Model Entity

Postby audryzas on Thu Jul 01, 2010 4:20 pm

Well theres nothing wrong with your fgd, something is wrong with the source itself.
It's either not compiled or the dll's are not being copied.
audryzas
Member
Member
 
Joined: Sun Jun 20, 2010 2:58 pm

Re: [Noob Question] Model Entity

Postby TickingHands on Thu Jul 01, 2010 9:58 pm

Thank you for the reply.

How can I make sure the dll's are being copied?

Here is the source code; I typed it up so I suppose I could have made a typo somewhere:

This is sdk_modelentity
Code: Select all
#include "cbase.h"

#define ENTITY_MODEL   "models/gibs/airboat_broken_engine.mdl"

class CMyModelEntity : public CBaseAnimating
{
public:
   DECLARE_CLASS( CMyModelEntity, CBaseAnimating );
   DECLARE_DATADESC();

   CMyModelEntity()
   {
      m_bActive = false;
   }

   void Spawn( void );
   void Precache( void );

   void MoveThink( void );

   //Input func.
   void InputToggle( inputdata_t &inputData );

private:
   
   bool      m_bActive;
   float      m_flNextChangeTime;
};

LINK_ENTITY_TO_CLASS( my_model_entity, CMyModelEntity );

//Data description
BEGIN_DATADESC( CMyModelEntity )

   // Save and load active state
   DEFINE_FIELD( m_bActive, FIELD_BOOLEAN ),
   DEFINE_FIELD( m_flNextChangeTime, FIELD_TIME ),

   //Link input name from hammer to input member func
   DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ),

   // Decalre the 'think' func
   DEFINE_THINKFUNC( MoveThink ),

END_DATADESC()


// -------- Precache assests used by the entity ----------
void CMyModelEntity::Precache( void )
{
   PrecacheModel( ENTITY_MODEL );

   BaseClass::Precache();
}

// -------- Sets up the entity's initial state ---------
void CMyModelEntity::Spawn( void )
{
   Precache();

   SetModel( ENTITY_MODEL );
   SetSolid( SOLID_BBOX );
   UTIL_SetSize( this, -Vector(20,20,20), Vector(20,20,20) );
}

// -------- Think function to randomly move the entity -------
void CMyModelEntity::MoveThink( void )
{
   // Check if we should change direction again
   if( m_flNextChangeTime < gpGlobals->curtime )
   {
      // Randomly take a new direction / speed
      Vector vecNewVelocity = RandomVector( -64.0f, 64.0f );
      SetAbsVelocity( vecNewVelocity );

      //Randomyly change it again with 1 to 3 sec.
      m_flNextChangeTime = gpGlobals->curtime + random->RandomFloat( 1.0f, 3.0f );
   }

   Vector velFacing = GetAbsVelocity();
   QAngle angFacing;
   VectorAngles( velFacing, angFacing );
   SetAbsAngles( angFacing );

   //Think every 20 Hz.
   // If not used, it will force the entity to stop 'thinking'
   SetNextThink( gpGlobals->curtime + 0.05f );
}

// -------- Toggle the movement of the entity ---------
void CMyModelEntity::InputToggle( inputdata_t &inputData )
{
   //Toggle active state
   if( !m_bActive )
   {
      // Start Thinking
      SetThink( &CMyModelEntity::MoveThink );

      SetNextThink( gpGlobals->curtime + 0.05f );

      // Start moving
      SetMoveType( MOVETYPE_FLY );

      // Force the Movethink func to choose the new speed and direc.
      m_flNextChangeTime = gpGlobals->curtime;

      // Update the m_bActive for the new state
      m_bActive = true;
   }
   else
   {
      //Stop thinking
      SetThink( NULL );

      //stop moving
      SetAbsVelocity( vec3_origin );
      SetMoveType( MOVETYPE_NONE );

      m_bActive = false;
   }
}

CON_COMMAND( create_sdk_modelentity, "Creates an instance of the sdk model entity in front of the player.")
{
   Vector vecForward;
   CBasePlayer *pPlayer = UTIL_GetCommandClient();
   if(!pPlayer)
   {
      Warning("Could not deterime calling player!\n");
      return;
   }

   AngleVectors( pPlayer->EyeAngles(), &vecForward );
   CBaseEntity *pEnt = CreateEntityByName( "my_model_entity" );
   if ( pEnt )
   {
      Vector vecOrigin = pPlayer->GetAbsOrigin() + vecForward * 256 + Vector(0,0,64);
      QAngle vecAngles(0, pPlayer->GetAbsAngles().y - 90, 0);
      pEnt->SetAbsOrigin(vecOrigin);
      pEnt->SetAbsAngles(vecAngles);
      DispatchSpawn(pEnt);
   }
}


Edit:
If I try to run Half Life 2 then run the map it goes but my model isn't there... I placed it on the map with Hammer and the console command still doesn't work.
I also did the next tutorial about brushes. I tied a brush to "my_brush_entity" and now the brush( a block ) doesn't show up either when I run the map.
TickingHands
Member
Member
 
Joined: Thu Nov 19, 2009 1:56 am

Re: [Noob Question] Model Entity

Postby audryzas on Fri Jul 02, 2010 9:15 am

If theres no errors it means your dll's are not copied. Hammer has nothing to do with this, game itself doesn't understand entity it self, because it does not exist.

Compile the dll's and look at the timestamps in mod\bin\(client.dll & server.dll) and src\game\(client & server)\release_(depends on mod)\(client.dll & server.dll).

If their time is the same (which is time when you compiled) then we'll see what else can be wrong.
audryzas
Member
Member
 
Joined: Sun Jun 20, 2010 2:58 pm

Return to Programming

Who is online

Users browsing this forum: No registered users