.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   The RealBot 'Source' (http://forums.bots-united.com/forumdisplay.php?f=52)
-   -   UTIL_SelectItem (http://forums.bots-united.com/showthread.php?t=1908)

dstruct2k 08-06-2004 23:39

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

dstruct2k 08-06-2004 23:44

Re: UTIL_SelectItem
 
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?

stefanhendriks 09-06-2004 00:04

Re: UTIL_SelectItem
 
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.

dstruct2k 09-06-2004 01:47

Re: UTIL_SelectItem
 
Thanks! You're assisting one of the great newb programmers! :D

dstruct2k 09-06-2004 02:15

Re: UTIL_SelectItem
 
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 *'


dstruct2k 09-06-2004 06:33

Re: UTIL_SelectItem
 
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...

dstruct2k 09-06-2004 07:02

Re: UTIL_SelectItem
 
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;
        }
        }
  }


stefanhendriks 09-06-2004 09:28

Re: UTIL_SelectItem
 
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 :)

stefanhendriks 11-06-2004 16:06

Re: UTIL_SelectItem
 
*Note

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


All times are GMT +2. The time now is 18:16.

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