View Single Post
Re: cs weapons modification
Old
  (#17)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Re: cs weapons modification - 14-09-2005

As far as I know it's impossible to inflict real damage to a player outside the mod unless you have the source.

Although, a while ago I posted an extremely cheap hack to cause real damage to entities.
It involved creating a trigger_hurt entity with the right settings and forcing the target player to touch it.

The one I posted on here had a few careless bugs that crept in due to lack of sleep but this one should work.

Code:
// Causes pain to someone by using a trigger_hurt to apply damage
// Params:
// pVictim	 - Who takes the damage
// pInflictor  - Who does the damage
// flAmount	- How much damage to do ( TRIGGER_HURT TAKES ARMOR INTO ACCOUNT! )
// iDmgmask	- See DMG_xxx macros, in cbase.h I think
// pszPainname - What should this pain be called? NULL leaves it at trigger_hurt
void Pain( edict_t* pVictim, edict_t* pInflictor, float flAmount, int iDmgmask, const char* pszPainname ) {
   char		   szKeyValue[ 32 ]; // Will contain iDmgmask as a string  
   edict_t*	   pEnt = NULL;	  // Trigger_hurt entity pointer
   KeyValueData   keyData;		  // Used to setup the damage type on the trigger_hurt entity

   // Create a trigger_hurt entity
   pEnt = CREATE_NAMED_ENTITY( MAKE_STRING( "trigger_hurt" ) );

   // Make sure it's valid
   if ( ! FNullEnt( pEnt ) ) {	
	  if ( pszPainname ) pEnt->v.classname = MAKE_STRING( pszPainname ); // Custom name! ( if set )
	  pEnt->v.dmg_inflictor = pInflictor;			 // Who's attacking me?
	  pEnt->v.owner = pInflictor;					 // ^^^^^
	  pEnt->v.dmg = flAmount;						 // Take this much damage ( note: goes by trigger_hurt rules! )
	  pEnt->v.dmg_take = 1.0f;					    // TODO: Figure out what this does... later
	  pEnt->v.dmgtime = 2.0f;						 // ^^^^^

	  // Somewhere out of the way
	  SET_ORIGIN( pEnt, Vector( -4000, -4000, -4000 ) );
	  SET_SIZE( pEnt, Vector( -32, -32, -32 ), Vector( 32, 32, 32 ) );

	  // Setup the damage type
	  _snprintf( szKeyValue, sizeof( szKeyValue ), "%d", iDmgmask ); // Setup value string
	  keyData.szClassName = ( char* ) pszPainname; // TODO: ??? 
	  keyData.szKeyName = "damagetype";		    // damagetype key
	  keyData.szValue = szKeyValue;			    // What kind of damage to do
	  keyData.fHandled = FALSE;				    // Not handled yet

	  // Set the key/value pair on the entity
	  MDLL_KeyValue( pEnt, &keyData );

	  // Spawn it and force it to touch us...
	  MDLL_Spawn( pEnt );
	  MDLL_Touch( pEnt, pVictim );

	  // So noone accidentally walks into it later on
	  REMOVE_ENTITY( pEnt );
   }
}
It does cause damage but I'm not 100% sure that the inflicting entity gets credit for it.
Good luck on your plugin.
  
Reply With Quote