.:: 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 ?!

Onno Kreuzinger 15-04-2004 15:46

Re: Sensing grenades in-flight
 
or an option like in word2k , edit-> insert content->unformated text, to paste from the clipboard (i just wanted to say even word 200 is too f**** up to allow "normal" copy&paste anymore, i hate that)
C U friday noon

stefanhendriks 15-04-2004 18:57

Re: Sensing grenades in-flight
 
When i copy stuff and i want to be sure it is not formatted or messed up in any way. I copy it, paste it into notepad. Then copy it from that to any document i want. It works great for me.

@$3.1415rin 15-04-2004 19:36

Re: Sensing grenades in-flight
 
I guess notepad is a simple edit field, therefore limited to 65kb on win9x machines ( old 16 bit stuff ). those wordpad or however called stuff is based on rtf windows, thus allowing to copy formatted text. when you paste your text to the notepad, only the text information data is requested from the clipboard, no rtf stuff

stefanhendriks 15-04-2004 21:42

Re: Sensing grenades in-flight
 
yes asp, notepad is that simple edit field :) I once tried VB (yuk) and i created my own notepad with it. :)

Anyway, i do not use wordpad, because it still does not erase the text format. As you said, notepad only requires text, therefor it works good for me.

Pierre-Marie Baty 16-04-2004 02:30

Re: Sensing grenades in-flight
 
To those who are still running the sock notepad:

replace it, guys. Replace it. I mean it. There are tons of free replacements for NotePad, full of kickass features. FYI I'm using an old version of EditPad. It has a multiple document interface, a powerful search/replace facility that can operate on all the open documents at once (that which no other editor I know are able to), unlimited text buffer, DOS/ANSI/UNIX/Mac text conversion. Lots of stuff. I can't live without it.

The newer versions of EditPad also do syntax highlighting and other stuff but I find them bloated. The version I use is the 3.2.1 Fr. I don't know if it's still available anywhere.

botman 16-04-2004 15:38

Re: Sensing grenades in-flight
 
Yeah, EditPad RULEZ! It loads up more quickly than any other text editor I've ever see (even quicker than Notepad). It minimizes itself to the system tray so that you can pop it up again instantly. It can be used as a hexadecimal editor of files. You can even do super-elite ROT-13 "encryption" to hide your source code from prying eyes! :)

botman


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

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