.:: 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 ::. > Cyborg Factory > RealBot > The RealBot 'Source'
The RealBot 'Source' Discuss things about the source code. You can here point out bugs, share ideas and code. Assign to become an 'official team member' and so on!

Reply
 
Thread Tools
UTIL_SelectItem
Old
  (#1)
dstruct2k
 
dstruct2k's Avatar
 
Status: Offline
Posts: 225
Join Date: Feb 2004
Default UTIL_SelectItem - 08-06-2004

For the reload code, I think I can finish it off with 3 UTIL_SelectItem calls... Assuming that "primary", "secondary", and "knife" are valid calls to the SelectItem function.


Does CS provide "primary" and "secondary" as selectable weapons, or would I have to use "UTIL_SelectItem(pEdict, "weapon_usp");" followed by "UTIL_SelectItem(pEdict, "weapon_glock18");" etc. Is there a shortcut?





(Please keep in mind, I am not a newb to programming, just to C++ and HL/Metamod. I understand code quickly, I just need help developing my first few ideas.)

Last edited by dstruct2k; 08-06-2004 at 23:43..
  
Reply With Quote
Re: UTIL_SelectItem
Old
  (#2)
dstruct2k
 
dstruct2k's Avatar
 
Status: Offline
Posts: 225
Join Date: Feb 2004
Default Re: UTIL_SelectItem - 08-06-2004

Nevermind, I'm looking at the cstrike Metamod ent list... No "weapon_primary"


Is there an equivilant function somewhere though? One that lets me call "weapon_primary" instead of EVERY weapon, one after another, until 1 works on the current bot?
  
Reply With Quote
Re: UTIL_SelectItem
Old
  (#3)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: UTIL_SelectItem - 09-06-2004

Well you can simplify this, in the cBot class i keep track of what primary and secondary weapon a bot has. So i think you can do this by doing:

Code:
UTIL_SelectItem (pEdict, UTIL_GiveWeaponName (iPrimaryWeapon));
 
// or for secondary
UTIL_SelectItem (pEdict, UTIL_GiveWeaponName (iSecondaryWeapon));
btw, i found these lines at bot.cpp around line 776... there the bot selects his weapon.


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: UTIL_SelectItem
Old
  (#4)
dstruct2k
 
dstruct2k's Avatar
 
Status: Offline
Posts: 225
Join Date: Feb 2004
Default Re: UTIL_SelectItem - 09-06-2004

Thanks! You're assisting one of the great newb programmers!
  
Reply With Quote
Re: UTIL_SelectItem
Old
  (#5)
dstruct2k
 
dstruct2k's Avatar
 
Status: Offline
Posts: 225
Join Date: Feb 2004
Default Re: UTIL_SelectItem - 09-06-2004

Alright so what I've done is...

In bot.cpp
Replaced
Code:
 // TODO
// The priority is:
// - primary
// - secondary
// - knife
With:
Code:
   if (FUNC_BotHasWeapon(this, UTIL_GiveWeaponName (iPrimaryWeapon)) &&	 // we have a primary
	   current_weapon.iId != UTIL_GiveWeaponName (iPrimaryWeapon) &&	  // that's not the current, empty gun
			 func_distance(pEdict->v.origin, v_enemy) > 600)		  // and we are not close enough to knife
   {
	UTIL_SelectItem (pEdict, UTIL_GiveWeaponName (iPrimaryWeapon));	  // select the primary
	return;
   }
   else
   {
	if (FUNC_BotHasWeapon(this, UTIL_GiveWeaponName (iSecondaryWeapon)) &&	// we have a secondary
		current_weapon.iId != UTIL_GiveWeaponName (iSecondaryWeapon) &&	 // that's not the current, empty gun
			  func_distance(pEdict->v.origin, v_enemy) > 600)		 // and we are not close enough to knife
	{
	 UTIL_SelectItem (pEdict, UTIL_GiveWeaponName (iSecondaryWeapon));	// select the secondary
	 return;
	}
	else
	{
	 if (FUNC_BotHasWeapon(this, CS_WEAPON_KNIFE) &&		 // we have a knife (for non-knife maps)
		 current_weapon.iId != CS_WEAPON_KNIFE)		  // that's not the current, empty knife (somehow, lol)
	 {
	  UTIL_SelectItem (pEdict, "weapon_knife");		 // slice and dice!
	  return;
	 }
	}
   }

EDIT:
Whoops. It doesn't compile. 9_9 Errors returned:
Code:
Compiling...
bot.cpp
bot.cpp(887) : error C2664: 'FUNC_BotHasWeapon' : cannot convert parameter 2 from 'char *' to 'int'
		This conversion requires a reinterpret_cast, a C-style cast or function-style cast
bot.cpp(888) : error C2446: '!=' : no conversion from 'char *' to 'int'
		This conversion requires a reinterpret_cast, a C-style cast or function-style cast
bot.cpp(888) : error C2040: '!=' : 'int' differs in levels of indirection from 'char *'
bot.cpp(896) : error C2664: 'FUNC_BotHasWeapon' : cannot convert parameter 2 from 'char *' to 'int'
		This conversion requires a reinterpret_cast, a C-style cast or function-style cast
bot.cpp(897) : error C2446: '!=' : no conversion from 'char *' to 'int'
		This conversion requires a reinterpret_cast, a C-style cast or function-style cast
bot.cpp(897) : error C2040: '!=' : 'int' differs in levels of indirection from 'char *'

Last edited by dstruct2k; 09-06-2004 at 02:24..
  
Reply With Quote
Re: UTIL_SelectItem
Old
  (#6)
dstruct2k
 
dstruct2k's Avatar
 
Status: Offline
Posts: 225
Join Date: Feb 2004
Default Re: UTIL_SelectItem - 09-06-2004

I think I need to put the results of "UTIL_GiveWeaponName (iPrimaryWeapon)" and "UTIL_GiveWeaponName (iSecondaryWeapon)" into variables, and call those variables in the BotHasWeapon function. I guess C++ doesn't like my function-within-a-function. 9_9


Actually, I just looked at what "UTIL_GiveWeaponName" gives, and I see that it gives the ENTITY names (weapon_knife), not the CS_WEAPON_KNIFE type names. Yay. Custom function time.







Oh no... I just looked over my code and saw spaces between UTIL_GiveWeaponName and the ()'s.... Oh no... That better not have been the fix...

Last edited by dstruct2k; 09-06-2004 at 06:37..
  
Reply With Quote
Re: UTIL_SelectItem
Old
  (#7)
dstruct2k
 
dstruct2k's Avatar
 
Status: Offline
Posts: 225
Join Date: Feb 2004
Default Re: UTIL_SelectItem - 09-06-2004

Found my bug. Too many uses of "GiveWeaponName".

New code:
Code:
   if (FUNC_BotHasWeapon(this, iPrimaryWeapon) &&   // we have a primary
	   current_weapon.iId != iPrimaryWeapon &&	  // that's not the current, empty gun
			 func_distance(pEdict->v.origin, v_enemy) > 600)		  // and we are not close enough to knife
   {
	UTIL_SelectItem(pEdict, UTIL_GiveWeaponName(iPrimaryWeapon));	  // select the primary
	return;
   }
   else
   {
	if (FUNC_BotHasWeapon(this, iSecondaryWeapon) &&	// we have a secondary
		current_weapon.iId != iSecondaryWeapon &&	 // that's not the current, empty gun
			  func_distance(pEdict->v.origin, v_enemy) > 600)		 // and we are not close enough to knife
	{
	 UTIL_SelectItem(pEdict, UTIL_GiveWeaponName(iSecondaryWeapon));	// select the secondary
	 return;
	}
	else
	{
	 if (FUNC_BotHasWeapon(this, CS_WEAPON_KNIFE) &&		 // we have a knife (for non-knife maps)
		 current_weapon.iId != CS_WEAPON_KNIFE)		  // that's not the current, empty knife (somehow, lol)
	 {
	  UTIL_SelectItem(pEdict, "weapon_knife");		 // slice and dice!
	  return;
	 }
	}
   }
  
Reply With Quote
Re: UTIL_SelectItem
Old
  (#8)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: UTIL_SelectItem - 09-06-2004

looks neat, i think you can even let out BotHasWeapon and make a check it is not < 0. As iSecondaryWeapon is checked on what weapon it has....

something like:

Code:
if (iSecondaryWeapon > -1 && current_Weapon.iId != iSecondaryWeapon) // we have a secondary weapon, but we do not hold it yet...
{
 // select
}
will work too


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: UTIL_SelectItem
Old
  (#9)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: UTIL_SelectItem - 11-06-2004

*Note

i have applied your code to the 'official code'. Thanks for the contribution! I hope you and evy will continue this way


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
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