.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Manually killing in cs... (http://forums.bots-united.com/showthread.php?t=3955)

AssasinoRuso 10-05-2005 22:42

Manually killing in cs...
 
I'm having trouble doing manual damage in cs.... if I remember correctly this code is enough to kill in half life but... it bugs out in cs....

pEntity->v.health = -1;

pEntity->v.deadflag = DEAD_DEAD;

pEntity->v.takedamage = DAMAGE_NO;


what happens is, the player takes the idle model animation... err the one where it's hands are sort of up with no weapon.... it becomes nonsolid, there is no death animation... if you do this to yourself then the death cam turns on.... but there is never a message or score changing or anything like that. And also you can't respawn :-/

plz help.

Rick 10-05-2005 22:59

Re: Manually killing in cs...
 
I used ClientKill(or pfnClientKill) in my esf bots.

AssasinoRuso 10-05-2005 23:28

Re: Manually killing in cs...
 
true but, what I'm doing is trying to get a bot to do "manual" damage and get credit for it.... basically this is in a mod simmilar to wc3 and the bots have their own damages..... basically the bot shoots a temp entity towards player and when the enemy's health goes below 1 I want him to die and the bot who shot to get credit...

Rick 10-05-2005 23:54

Re: Manually killing in cs...
 
Yeah, I made some damaging function too...a bit dodgy though:
Code:

void UTIL_DamagePlayer(edict_t *pKiller, edict_t *pVictim, const char *Weapon, float Damage)
{
        static CBaseEntity *pDamageEnt = NULL;

        CBaseEntity *pEnt = (CBaseEntity *)GET_PRIVATE(pVictim);

        if (!pDamageEnt)
                pDamageEnt = UTIL_CreateEnt("info_target",Vector(0,0,0),Vector(0,0,0),        NULL);

        if ((pDamageEnt) && (pEnt))
        {
                UTIL_MakeVectors(WrapAngles(pVictim->v.angles+Vector(180,180,180)));
                pDamageEnt->pev->velocity = pDamageEnt->pev->velocity.Normalize() * 180 + gpGlobals->v_forward * 10;
                pDamageEnt->pev->origin = pKiller->v.origin;
                pDamageEnt->pev->owner = pKiller;
                pDamageEnt->pev->classname = MAKE_STRING(Weapon);
                pEnt->TakeDamage( pDamageEnt->pev, &pKiller->v,Damage,0);
        }
}

Not sure why I set the velocity...can't remember anymore :)

Pierre-Marie Baty 11-05-2005 00:28

Re: Manually killing in cs...
 
...except that CBaseStuff won't work in Counter-Strike, ain't I right ?

If you have the source code of the mod you're writting this for, do what Rick says ; else I'd say it's pretty much impossible.

AssasinoRuso 11-05-2005 06:46

Re: Manually killing in cs...
 
Pierre out of all the people :)

did you know that it's possible to add entities to cs? ;)

CBaseEntity DOES exist in cs.... this line turns edict_t into a semi workable CBaseEntity...

CBaseEntity *pEnt = (CBaseEntity *)GET_PRIVATE(pVictim);

only difference is that you can't use any functions....

AssasinoRuso 11-05-2005 06:49

Re: Manually killing in cs...
 
grr sorry for second post so shortly but... TakeDamage don't work for meh :( I tried before... and I actually have my own entity in cs so dont need to make one... it crashes when I do TakeDamage.... maybe it's where I'm doing it :-/ hmm.

Rick 11-05-2005 09:30

Re: Manually killing in cs...
 
Quote:

Originally Posted by Pierre-Marie Baty
...except that CBaseStuff won't work in Counter-Strike, ain't I right ?

If you have the source code of the mod you're writting this for, do what Rick says ; else I'd say it's pretty much impossible.

At the time I wrote this I didn't had the source code aswell, it was just luck it worked I guess :)

For the killing...sorry don't know any other way :-/

Lazy 12-05-2005 22:48

Re: Manually killing in cs...
 
I tried something like this a while ago but lost the source and forgot how until I remembered 20 minutes ago...

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 Ouch( 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 = INDEXENT( 0 );                  // Who's attacking me?
          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 );
  }
}

void ClientCommand( edict_t* pEdict ) {
  if ( FStrEq( CMD_ARGV( 0 ), "hurtme" ) ) {
          Ouch( pEdict, INDEXENT( 0 ), 35.0f, ( 1<< 4 ) /* DMG_FROZEN */, "canadian_winter" );

          RETURN_META( MRES_SUPERCEDE );
  }

  RETURN_META( MRES_IGNORED );
}

I just tested that locally by myself and it seems to work great, you can even have your custom death message set.
This should work with any mod that has trigger_hurt entities compiled in.

Pierre-Marie Baty 13-05-2005 15:15

Re: Manually killing in cs...
 
oh yeah, a trigger_hurt.. that's smart :)

and lol @ the canadian winter :D


All times are GMT +2. The time now is 14:07.

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