.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Reducing damage (http://forums.bots-united.com/showthread.php?t=2463)

Austin 16-08-2004 00:26

Reducing damage
 
I have been using the following code to deny headshots to humans.
How would i modify this to reduce damage taken?
What I would like to do is deny all headshots and reduce all other damage to humans by half.

Code:

// ---------------------------------------------------------------------------------------
// TraceLine()
//
// Disallow headshot damange to human players
// ---------------------------------------------------------------------------------------
void TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
{
  TRACE_LINE(v1, v2, fNoMonsters, pentToSkip, ptr);
  if ( ((1<<HITGROUP_HEAD) & (1<<ptr->iHitgroup)) &&
                !(ptr->pHit->v.flags & FL_FAKECLIENT)          )
  {
        // return no damage
        ptr->flFraction = 1.0;
        RETURN_META(MRES_SUPERCEDE);
  }
  else
  {
        RETURN_META(MRES_IGNORED);
  }
}


MusicMan 16-08-2004 06:42

Re: Reducing damage
 
try and take a look at PMB's damage, headshot and no-headshot metamod plugins' source code.

Hope this helps :)

Austin 17-08-2004 01:38

Re: Reducing damage
 
Quote:

Originally Posted by MusicMan
try and take a look at PMB's damage, headshot and no-headshot metamod plugins' source code.

Hope this helps :)

tx, but that is exactly the opposite of what I am trying to do!

I guess I will look inthe sdk to see how the results of TraceLine() are used to inflict damage...

>Edit<
Hey, wait, Daaaaaa!
I will change a "-" to a "+" and use this to do exactly what I want!
Thanks again, and of course thanks PMB!

voogru 17-08-2004 15:46

Re: Reducing damage
 
Hook the Damage message.

It would look something like this:

Code:

void NSAMessage_Damage(void *buf, bool &bSend)
{
static int CurrentArg = 0;
if(buf == NULL)
{
CurrentArg = 0;
return;
}
float flDamage = 0;
CPlayer *pAttacker = NULL;
CPlayer *pVictim = NULL;
switch(CurrentArg)
{
case 1:
flDamage = (float)M_INT(buf);
if(UTIL_IsPlayerValid(CurrentMessageEdict)
&& CurrentMessageEdict->v.dmg_inflictor != NULL
&& UTIL_IsPlayerValid(CurrentMessageEdict->v.dmg_inflictor->v.owner)
&& flDamage > 0)
{
pAttacker = GetPlayerPointer(CurrentMessageEdict->v.dmg_inflictor->v.owner);
pVictim = GetPlayerPointer(CurrentMessageEdict);
 
if(pAttacker == NULL || pVictim == NULL)
{
        CurrentArg++;
        break;
}
pVictim->pev->health += flDamage * 0.5;
M_INT(buf) = (int)flDamage * 0.5;
}
CurrentArg++;
break;
default:
CurrentArg++;
break;
}
}

That would make everyone take about half damage. The problem with this however is anything that does more damage than the player has health for wont work, since this is done after the fact. As far as I know theres no real way to limit the damage before its done.

sfx1999 18-08-2004 05:08

Re: Reducing damage
 
Is it possible to override the player class' takedamage function, modifiy the incoming data, then send it back?

sPlOrYgOn 18-08-2004 05:13

Re: Reducing damage
 
I don't think so..
cs does it's own kind of damage stuff.. all internal so unless you start memory hacking you probably won't beable to intercept it..
then after all that it sends the packet message just to update the HUD of the player and sets pEdict->v.health...

Lazy 18-08-2004 06:36

Re: Reducing damage
 
Quote:

Originally Posted by sfx1999
Is it possible to override the player class' takedamage function, modifiy the incoming data, then send it back?

Maybe, if you could find the address of it first. I think thats why its so hard to do in the first place, I could be mistaken though.


All times are GMT +2. The time now is 00:47.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.