.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Sensing grenades in-flight (http://forums.bots-united.com/showthread.php?t=1377)

two_masks 14-04-2004 23:44

Sensing grenades in-flight
 
How can I get my bot to "sense" grenades (i.e. how can I get the edict of the grenade) that are thrown into its vicinity? FindEntityInSphere doesn't seem to detect them, or perhaps I'm just not using it correctly. Any tips?

-JB

Pierre-Marie Baty 15-04-2004 01:22

Re: Sensing grenades in-flight
 
Grenade entities are class-named "grenade", simply that :)

There are several ways to detect them, but this one will work:
Code:

  edict_t *pGrenade = NULL;

  // is there an armed grenade near here?
  while (!FNullEnt (pGrenade = UTIL_FindEntityInSphere (pGrenade, pPlayer->v_origin, 300)))
  {
          if (strcmp ("grenade", STRING (pGrenade->v.classname)) == 0)
                continue; // discard entity if it is NOT an armed grenade
 
          // do stuff with grenade (check if bot can see it and check the grenade's velocity...


two_masks 15-04-2004 03:40

Re: Sensing grenades in-flight
 
Thanks so much Pierre-Marie- you're great! Now another question...

How do grenades indicate that they've detonated? I need to be able to detect this so my bots don't think they last forever. Thanks!

-JB

stefanhendriks 15-04-2004 10:53

Re: Sensing grenades in-flight
 
Well i identify grenades like this, i don't even care about detonated or not right now.

Code:

edict_t *pent = NULL;
        while ((pent = UTIL_FindEntityByClassname (pent, "grenade")) != NULL)
        {
        if (UTIL_GetGrenadeType (pent) == ... any type you want ...) // see below
        {

// do what you want
        }
        }

and here the grenadetype thingy:

Code:

//////////////////////////////////
// UTIL_getGrenadeType function // - Stefan
//////////////////////////////////
int
UTIL_GetGrenadeType (edict_t * pEntity)
{
  char model_name[32];
  strcpy (model_name, STRING (pEntity->v.model));
  if (strcmp (model_name, "models/w_hegrenade.mdl") == 0)
        return 1;  // He grenade
  if (strcmp (model_name, "models/w_flashbang.mdl") == 0)
        return 2;  // FlashBang
  if (strcmp (model_name, "models/w_smokegrenade.mdl") == 0)
        return 3;  // SmokeGrenade
  if (strcmp (model_name, "models/w_c4.mdl") == 0)
        return 4;  // C4 Explosive
  return 0;
}


Pierre-Marie Baty 15-04-2004 11:32

Re: Sensing grenades in-flight
 
Think about it two_masks: if you make your bot care for grenades each frame and react accordingly, when the grenade has detonated the bot won't be able to detect it anymore since it doesn't exist anymore right ? Hence the bot won't react to it anymore...

I think you're trying to solve an unexistent problem perhaps :)

Rick 15-04-2004 11:54

Re: Sensing grenades in-flight
 
Uhm... could be me but shouldn't it check if its unequal to zero instead?

if (strcmp ("grenade", STRING (pGrenade->v.classname)) != 0)


@$3.1415rin 15-04-2004 12:03

Re: Sensing grenades in-flight
 
strcmp returns zero if the strings are equal. so
Code:

if (strcmp (model_name, "models/w_hegrenade.mdl") == 0)
        return 1; // He grenade

is right. ( use ! instead of == 0 and you save at least 2 chars :P )

Rick 15-04-2004 12:15

Re: Sensing grenades in-flight
 
I was refering to PMB's post...And i find == 0 more clear then ! sometimes, dunno why 9_9

Oh and it seems that Im not the only one who had some problems the the text between the code tags...

Pierre-Marie Baty 15-04-2004 14:16

Re: Sensing grenades in-flight
 
This is because Aspirin copy and pasted the code, and when you copy-paste coloured code the formatting tags are copied as well ; plus if you enclose them between code tags, the formatting tags are disabled and then they show up...

it's a bit of a PITA I concede. Someone's gotta have a look in the PHP files again...

@$3.1415rin 15-04-2004 15:09

Re: Sensing grenades in-flight
 
ok, marked the text and clicked on those 2 'A's ... so more a user fault, maybe we should just add some notes about this on the reply page ?!


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

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