.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Bot Coding
General Bot Coding See what a pain it is to get those little mechs shooting around

Reply
 
Thread Tools
Sensing grenades in-flight
Old
  (#1)
two_masks
Guest
 
Status:
Posts: n/a
Default Sensing grenades in-flight - 14-04-2004

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
  
Reply With Quote
Re: Sensing grenades in-flight
Old
  (#2)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Sensing grenades in-flight - 15-04-2004

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...



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Sensing grenades in-flight
Old
  (#3)
two_masks
Guest
 
Status:
Posts: n/a
Default Re: Sensing grenades in-flight - 15-04-2004

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
  
Reply With Quote
Re: Sensing grenades in-flight
Old
  (#4)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: Sensing grenades in-flight - 15-04-2004

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;
}


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: Sensing grenades in-flight
Old
  (#5)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Sensing grenades in-flight - 15-04-2004

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



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Sensing grenades in-flight
Old
  (#6)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: Sensing grenades in-flight - 15-04-2004

Uhm... could be me but shouldn't it check if its unequal to zero instead?

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

  
Reply With Quote
Re: Sensing grenades in-flight
Old
  (#7)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: Sensing grenades in-flight - 15-04-2004

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 )



Last edited by @$3.1415rin; 15-04-2004 at 15:07..
  
Reply With Quote
Re: Sensing grenades in-flight
Old
  (#8)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: Sensing grenades in-flight - 15-04-2004

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...
  
Reply With Quote
Re: Sensing grenades in-flight
Old
  (#9)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Sensing grenades in-flight - 15-04-2004

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...



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Sensing grenades in-flight
Old
  (#10)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: Sensing grenades in-flight - 15-04-2004

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


  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com