.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Getting the enemy's weapon-help plz (http://forums.bots-united.com/showthread.php?t=5369)

noGrip 10-06-2006 12:55

Getting the enemy's weapon-help plz
 
Hi all,

I'm trying to build a bot for counter-strike 1.6. I want to know what weapon the bot's sighted enemy is using. For that I'm using the entvars_s structure. I do something like this (short version):

Code:

//What enemies do i see?
edict_t** visibleEnemies = vision->seeEnemies();
edict_t* targetEnemy = visibleEnemies[0];
if(targetEnemy->v.weaponmodel == ???)
{
    //do something about it
}

The ??? is what I want to know... I know it is an integer, but I have spent the last hours trying to find the match between that integer and the weapon. Does anyone know where it is? Or if it is another way of detecting the enemy's weapon?

Thanks,

Paulo

jeefo 10-06-2006 17:18

Re: Getting the enemy's weapon-help plz
 
weaponmodel field is a string, so you need to use a strcmp() stuff, so i advice you to use bits

if ((targetEnemy->v.weapons & (1 << CS_WEAPON_AWP)))
m_botHasAWP = true;

in this way =)

noGrip 10-06-2006 17:30

Re: Getting the enemy's weapon-help plz
 
Thanks for the help!
Where do you find the weapons name like CS_WEAPON_AWP? I'm looking specifically for the gun and shield. ( I want to throw them grenades :D )

jeefo 10-06-2006 17:54

Re: Getting the enemy's weapon-help plz
 
np =)

Weapons:
PHP Code:

enum eWeapon
{
   
WEAPON_P228         1,
   
WEAPON_SHIELDGUN    2,
   
WEAPON_SCOUT        3,
   
WEAPON_HEGRENADE    4,
   
WEAPON_XM1014       5,
   
WEAPON_C4           6,
   
WEAPON_MAC10        7,
   
WEAPON_AUG          8,
   
WEAPON_SMOKEGRENADE 9,
   
WEAPON_ELITE        10,
   
WEAPON_FIVESEVEN    11,
   
WEAPON_UMP45        12,
   
WEAPON_SG550        13,
   
WEAPON_GALIL        14,
   
WEAPON_FAMAS        15,
   
WEAPON_USP          16,
   
WEAPON_GLOCK18      17,
   
WEAPON_AWP          18,
   
WEAPON_MP5NAVY      19,
   
WEAPON_M249         20,
   
WEAPON_M3           21,
   
WEAPON_M4A1         22,
   
WEAPON_TMP          23,
   
WEAPON_G3SG1        24,
   
WEAPON_FLASHBANG    25,
   
WEAPON_DEAGLE       26,
   
WEAPON_SG552        27,
   
WEAPON_AK47         28,
   
WEAPON_KNIFE        29,
   
WEAPON_P90          30,
   
WEAPON_ARMOR        31,
   
WEAPON_ARMORHELM    32,
   
WEAPON_DEFUSER      33
}; 

WEAPON_SHIELDGUN - is not a weapon, it's just added as helper.
To check if bot has shield use:
PHP Code:

bool CBot::HasShield (void)
{
   
// this function returns true, if bot has a tactical shield
   
   
return (strncmp (STRING (pev->viewmodel), "models/shield/v_shield_"23) == 0);
}

bool CBot::IsShieldDrawn (void)
{
   
// this function returns true, is the tactical shield is drawn
   
   
if (!HasShield ())
      return 
false;

   return ((
pev->weaponanim == 6) || (pev->weaponanim == 7));


pev = entvars_t structure.

Whistler 11-06-2006 07:08

Re: Getting the enemy's weapon-help plz
 
well he wanted to get the current weapon which the enemy is using, which cannot be done using entvars_t::weapons ...

check for STRING(targetEnemy->v.viewmodel) may be a good idea for this. The values are usually "models/v_[weaponname].mdl" so just use strcmp to check it.


All times are GMT +2. The time now is 22:25.

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