Page 1 of 1

plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sat Sep 17, 2011 12:01 am
by Stormy
So I've been fiddling with custom entities for a few days and I'm a little overwhelmed. The VDC only provided half the info and google made it all sound irrelevant. I'm trying to create an NPC that anyone can download and plug straight into their mod, much like a custom prop. Props have the advantage of being able to just change their world model and any model is compatible with any mod (generally). Entities seem to need to be hardcoded into the mod? Is that right?

Exactly what I'm trying to do is this: I have made a new model for the headcrab, which is rigged to the old rig and uses all the same animations, it's all good in HLMV. I want to make a new entity (a straight clone of npc_headcrab with new models and sounds) that anyone can download and put in their map or mod. I don't want to just replace the model for the old headcrab.

How do I go about this? Should I be looking at VPKs or GCFs? If anyone can point me in the general direction that would be super.

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sat Sep 17, 2011 1:07 am
by LordDz
Make it as a prefab, then anyone can change the npc_whateverthefuckyerusing to npc_whatevertheyfeellikeusing ?

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sat Sep 17, 2011 7:23 am
by Stormy
I'm not sure I follow, wouldn't that still require the entity to be compiled, and therefore still hardcoded? I mean, a prefab doesn't extract the entities it uses and save them elsewhere, it just stores a bunch of internal pointers to assets, right?

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sat Sep 17, 2011 12:56 pm
by Gary
Interesting fact, all zombies are in one cpp file. You can declare multiple entities.

You should also able to copy the head crab ai from a new file... Cant say how, I would have to learn first.

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sat Sep 17, 2011 1:24 pm
by Stormy
Yeah all the headcrabs share the same cpp file too. it already includes all the ai in the script, all I have done is changed the linking model file and the entity name, leaving all the local variables and private declarations as "headcrab" just in case it messes something up in a reference file. But in order to compile I have to compile the entire mod, and there must be some files somewhere that I am missing. Is there a way to compile just the one file without compiling the mod? I feel like I'm going around in circles here, I need to sleep...

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sat Sep 17, 2011 6:08 pm
by zombie@computer
Code: Select all
class MyNewHeadcrap : public CHeadcrab
{
public:
     MyNewHeadcrap()
     {
            Precache();
            SetModel("models/MyNewHeadcrap.mdl" );
     }
     void Precache()
     {
           PrecacheModel( "models/MyNewHeadcrap.mdl" );
     }
};

all there is to it.

not sure if this works in plugins, ive never touched plugins nor ever will.

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sun Sep 18, 2011 2:29 am
by Stormy
Thanks for the advice, but I can't get it to work. I'm getting the "failed to create unknown entity type" console error. I have added a new class in the npc_headcrab.h file (copying from Cbaseheadcrab) and copied the relevant entries in the npc_headcrab.cpp file as well. I worked through my errors and have an error free compile, but the entity isn't being created. Shouldn't this output a file of some sort? Like a combinecrab.mdl file? I noticed that there is a headcrab.obj file, which I thought was just a model source file but it appears to be updated whenever I compile the code. Here's what I have modified in the files so far:

npc_headcrab.cpp:
Code: Select all

void Ccombinecrab::Precache( void )
{
   PrecacheModel( "models/m4m/combinecrab.mdl" );

   PrecacheScriptSound( "NPC_HeadCrab.Gib" );
   PrecacheScriptSound( "NPC_HeadCrab.Idle" );
   PrecacheScriptSound( "NPC_HeadCrab.Alert" );
   PrecacheScriptSound( "NPC_HeadCrab.Pain" );
   PrecacheScriptSound( "NPC_HeadCrab.Die" );
   PrecacheScriptSound( "NPC_HeadCrab.Attack" );
   PrecacheScriptSound( "NPC_HeadCrab.Bite" );
   PrecacheScriptSound( "NPC_Headcrab.BurrowIn" );
   PrecacheScriptSound( "NPC_Headcrab.BurrowOut" );

   BaseClass::Precache();
}

void Ccombinecrab::Spawn( void )
{
   Precache();
   SetModel( "models/m4m/combinecrab.mdl" );

   BaseClass::Spawn();

   m_iHealth = sk_headcrab_health.GetFloat();
   m_flBurrowTime = 0.0f;
   m_bCrawlFromCanister = false;
   m_bMidJump = false;

   NPCInit();
   HeadcrabInit();
}

Activity Ccombinecrab::NPC_TranslateActivity( Activity eNewActivity )
{
   if ( eNewActivity == ACT_WALK )
      return ACT_RUN;

   return BaseClass::NPC_TranslateActivity( eNewActivity );
}


void Ccombinecrab::IdleSound( void )
{
   EmitSound( "NPC_HeadCrab.Idle" );
}

void Ccombinecrab::AlertSound( void )
{
   EmitSound( "NPC_HeadCrab.Alert" );
}

void Ccombinecrab::PainSound( const CTakeDamageInfo &info )
{
   if( IsOnFire() && random->RandomInt( 0, HEADCRAB_BURN_SOUND_FREQUENCY ) > 0 )
   {
      // Don't squeak every think when burning.
      return;
   }

   EmitSound( "NPC_HeadCrab.Pain" );
}

void Ccombinecrab::DeathSound( const CTakeDamageInfo &info )
{
   EmitSound( "NPC_HeadCrab.Die" );
}

void Ccombinecrab::TelegraphSound( void )
{
   //FIXME: Need a real one
   EmitSound( "NPC_HeadCrab.Alert" );
}

void Ccombinecrab::AttackSound( void )
{
   EmitSound( "NPC_Headcrab.Attack" );
}

void Ccombinecrab::BiteSound( void )
{
   EmitSound( "NPC_HeadCrab.Bite" );
}

LINK_ENTITY_TO_CLASS( npc_combinecrab, Ccombinecrab );

float Ccombinecrab::MaxYawSpeed ( void )
{
   switch ( GetActivity() )
   {
   case ACT_IDLE:         
      return 30;

   case ACT_RUN:         
   case ACT_WALK:         
      return 20;

   case ACT_TURN_LEFT:
   case ACT_TURN_RIGHT:
      return 15;

   case ACT_RANGE_ATTACK1:
      {
         const Task_t *pCurTask = GetTask();
         if ( pCurTask && pCurTask->iTask == TASK_HEADCRAB_JUMP_FROM_CANISTER )
            return 15;
      }
      return 30;

   default:
      return 30;
   }

   return BaseClass::MaxYawSpeed();
}



npc_headcrab.h:
Code: Select all
class Ccombinecrab : public CBaseHeadcrab
{
   DECLARE_CLASS( Ccombinecrab, CBaseHeadcrab );

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

   float   MaxYawSpeed( void );
   Activity NPC_TranslateActivity( Activity eNewActivity );

   void   BiteSound( void );
   void   PainSound( const CTakeDamageInfo &info );
   void   DeathSound( const CTakeDamageInfo &info );
   void   IdleSound( void );
   void   AlertSound( void );
   void   AttackSound( void );
   void   TelegraphSound( void );
};


Mymod.fgd:
Code: Select all
@include "base.fgd"
 
@PointClass base(Targetname) studio("models/m4m/combinecrab.mdl")= npc_combinecrab :  "combinecrab"
[
]


thanks for helping me this far, at least.

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sun Sep 18, 2011 2:50 am
by Gary
Where are you declaring the entity name?

Oh and obj, while known as a model format, just stands for object in VS.

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sun Sep 18, 2011 4:40 am
by Stormy
Do you mean this line?
Code: Select all
LINK_ENTITY_TO_CLASS( npc_combinecrab, Ccombinecrab );


That's the only real mention of an entity name outside of the .fgd. I assumed it would appear after all of the entries about the class, but the fastheadcrab has it's MaxYawSpeed after the LINK_ENTITY, so I stayed with that order.

And about the .obj, I assume that must be the file that contains some information about the headcrab and variants then? Because it updates on each compile, but I can't read the contents of it, and can't import it into blender either.

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sun Sep 18, 2011 12:23 pm
by Gary
Ignore the obj thing, it's just something the compiler makes during the build.

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Mon Sep 19, 2011 7:43 am
by Jordash
why do you think the code would output a model? I can't seem to follow the logic pattern there...

The naming of the npc in the cpp file is the important one, the fdg is only for hammer. If you want to test your code use the 'npc_create npc_*' console command. Also, since you seem to be basing the code off the original headcrab, you don't need to have all the sounds and stuff mentioned again, they default to the original headcrab's if you don't mention them.

Also make sure the code is being copied, you need your client.dll and server.dll files to be in which ever mod you are playing.

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Thu May 16, 2013 7:41 am
by Stormy
I can't believe it was two years since I tried to do this. Since I made that steampunk turret model I want to include that as its own entity so I guess I'll give this another go.

By "Shouldn't this output a file of some sort?" I think I meant shouldn't it be an entity of its own within my mod? For instance the turret in portal is a turret_floor entity. If I was to clone it and change the models/sounds then I would want to create a turret_gentry entity. Once I added in the code and recompiled my mod I was hoping the combinecrab entity would show up in my entity list within hammer. Is this not how it works?

Also is there a way to extract the entity and all its logic and provide it as a download for other people to put in their mods or do they have to code in the entity in the same way I do, and I just provide the assets?

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Thu May 16, 2013 8:22 pm
by [Steve]
Hammer loads its entity list independently from your client/server dll's , from an Fgd file
https://developer.valvesoftware.com/wiki/FGD

so to place a custom ent in hammer you need to add it to one of the Fgd's or make your own and add it to those loaded by hammer.

However if you just want to test your new custom ent ingame without having to add it to a map , then just use the ent_Create console command.
If you would like me to go into further detail i don't mind writing a tutorial on how to create a new turret entity and add it to your fgd.

Also if all your wanting to do is a model swap then you don't need to create a new ent. in hammer you can edit the model key value and have a stock ent use a different model (this seems to work on most ents , tho some it doesn't).

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Thu May 16, 2013 10:10 pm
by Stormy
To be honest I hadn't looked at the entity in hammer to see if I could swap out the model. What about sound files? The turret uses custom sounds I assume I'll have to make a new entity for that.

Re: plugin/"bolt-on" entities (NPC's specifically)

PostPosted: Sat May 18, 2013 11:16 pm
by [Steve]
yeah custom ent would be the best way to go for new sounds.