View Single Post
Re: Making entities follow the player
Old
  (#3)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: Making entities follow the player - 03-05-2004

Well, pfnWalkMove does not work but it appears random mathematical guessing does.
The hostages now follow their new user except for one bug...
They float.

Here is the new version of PlayerPostThink_Post...
Code:
 // Called every frame after physics have been applied.
 // Also called after the gamedll's version.
 void 
 PlayerPostThink_Post( edict_t* pEdict ) {
    // The player's entity index.
    int iPlayerIndex = ENTINDEX( pEdict );
 
    // Pointer to our hostage entity.
    edict_t* pHostage = NULL;
    
    // Do we have a valid hostage?
    // Added:
    // The hostage "movement" is done here to save
    // hooking another function.
    // Besides, the hostage is our bitch anyways for
    // the time being.
    if ( ! FNullEnt( pEdict->v.euser4 ) ) {
 	  pHostage = pEdict->v.euser4;
 
 	  // Release the hostage if either they are too far away,
 	  // out of sight,
 	  // the hostage is dead
 	  // or the player is dead.
 	  if ( ( pEdict->v.origin - pHostage->v.origin ).Length( ) > 1024.0f   || 
 		    !IsVisible( pHostage, pEdict->v.origin + pEdict->v.view_ofs )  ||
 			 pHostage->v.health == 0									   || 
 			 pEdict->v.health == 0 ) {
 		 // We are either too far away, out of sight or someone died.
 		 // Release the hostage.
 		 pEdict->v.euser4 = NULL;
 	 }
 	 else {
 		 // The hostage can see us and we aren't too far away.
 		 // Face our user.
 		 // Thanks to PMB for this angles stuff :)
 		 pHostage->v.angles = UTIL_VecToAngles( pEdict->v.origin - ( pHostage->v.origin + pHostage->v.view_ofs ) );
 		 pHostage->v.angles.x = 0;
 
 		 // Follow our user!
 		 pHostage->v.avelocity = pEdict->v.avelocity;
 		 pHostage->v.velocity = ( ( pEdict->v.origin - pHostage->v.origin ) - pEdict->v.velocity ) - gpGlobals->v_forward * 64;
 	  }
    }
 
    RETURN_META( MRES_IGNORED );
 }
Attached is a zipped demo of what the floating looks like.
Just unzip to your ( steam ) cstrike directory, go into CS and type "playdemo hostage.dem".
Attached Files
File Type: zip hostage.zip (189.0 KB, 424 views)
  
Reply With Quote