.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   YaPB (http://forums.bots-united.com/forumdisplay.php?f=55)
-   -   YaPB 1.0.0.0 modification problem (http://forums.bots-united.com/showthread.php?t=7298)

Serious Sam 17-09-2009 13:16

YaPB 1.0.0.0 modification problem
 
I tried to change the weapon prefs configuration from the standart cfg file to a executable cvar, so that the bot could have different weapon prefs for each map, using the amx mod x feature to execute map specific cvars.

First, I deleted in the botweapons.cfg everything after "# Weapon Priorities for a Normal Standard Bot" and in server.cfg I added the following lines with default weapon prefs for maps that dont have any specific prefs set

Code:

yapb_norwepprefs "0,2,1,5,6,3,4,25,19,18,20,21,8,10,12,7,11,13,9,22,24,23,14,16,17,15"
yapb_agrwepprefs "0,1,2,4,5,6,3,18,19,25,20,21,17,15,14,16,23,24,22,7,8,10,12,9,13,11"
yapb_defwepprefs "0,2,1,4,3,5,6,8,7,12,10,11,9,13,22,24,23,16,14,25,15,17,18,21,20,19"

Then I made the following changes to dllapi.cpp :

after the
Code:

cvar_t g_cvarBotBuy = {"yapb_botbuy", "1"};
line I added these:
Code:

cvar_t g_cvarNWP = {"yapb_norwepprefs", "0,2,1,5,6,3,4,25,19,18,20,21,8,10,12,7,11,13,9,22,24,23,14,16,17,15"};
cvar_t g_cvarAWP = {"yapb_agrwepprefs", "0,1,2,4,5,6,3,18,19,25,20,21,17,15,14,16,23,24,22,7,8,10,12,9,13,11"};
cvar_t g_cvarDWP = {"yapb_defwepprefs", "0,2,1,4,3,5,6,8,7,12,10,11,9,13,22,24,23,16,14,25,15,17,18,21,20,19"};

after the
Code:

CVAR_REGISTER(&g_cvarBotBuy);
line I added these:
Code:

  CVAR_REGISTER(&g_cvarNWP);
  CVAR_REGISTER(&g_cvarAWP);
  CVAR_REGISTER(&g_cvarDWP);

I replaced this code:
Code:

        else
        {
            if (FStrEq(szBuffer, "[NORMAL]"))
              ptrWeaponPrefs = NormalWeaponPrefs;
            else if (FStrEq(szBuffer, "[AGRESSIVE]"))
              ptrWeaponPrefs = AgressiveWeaponPrefs;
            else if (FStrEq(szBuffer, "[DEFENSIVE]"))
              ptrWeaponPrefs = DefensiveWeaponPrefs;
            else
            {
              pszStart = szBuffer;
              for (i = 0; i < NUM_WEAPONS; i++)
              {
                  pszEnd = strchr(pszStart, ',');
                  *ptrWeaponPrefs++ = atoi(pszStart);
                  pszStart = pszEnd + 1;
              }
            }
        }

with this:
Code:

            pszStart = (char *)CVAR_GET_STRING(g_cvarNWP.name);
            ptrWeaponPrefs = NormalWeaponPrefs;
            for (i = 0; i < NUM_WEAPONS; i++)
            {
                pszEnd = strchr(pszStart, ',');
                *ptrWeaponPrefs++ = atoi(pszStart);
                pszStart = pszEnd + 1;
            }

            pszStart = (char *)CVAR_GET_STRING(g_cvarAWP.name);
            ptrWeaponPrefs = AgressiveWeaponPrefs;
            for (i = 0; i < NUM_WEAPONS; i++)
            {
                pszEnd = strchr(pszStart, ',');
                *ptrWeaponPrefs++ = atoi(pszStart);
                pszStart = pszEnd + 1;
            }

            pszStart = (char *)CVAR_GET_STRING(g_cvarDWP.name);
            ptrWeaponPrefs = DefensiveWeaponPrefs;
            for (i = 0; i < NUM_WEAPONS; i++)
            {
                pszEnd = strchr(pszStart, ',');
                *ptrWeaponPrefs++ = atoi(pszStart);
                pszStart = pszEnd + 1;
            }

At this point I thought I was ready, the code compiled with no errors or warnings, the game started with no problems, I tested it out on cs_mansion, in the amx config file for cs_mansion I added the new cvars and gave the bots prefs so that all personalities should prefer ak-47 and m4a1, but when I tested it in game, they still were buying according to their default prefs. When I checked the new cvars in the console, they were set the way they should, which makes the problem somewhere in the code, which is not suprising knowing that I'm not good with programing.

So, if someone can help, please do :helpsmilie:

Whistler 18-09-2009 05:55

Re: YaPB 1.0.0.0 modification problem
 
looks like the cvar is set AFTER the prefs are read into the arrays.
a better way may be changing the buy code to use the cvars instead of the arrays.

Serious Sam 18-09-2009 16:50

Re: YaPB 1.0.0.0 modification problem
 
Ok, but, even if this is possible, I cant quite get it right.
In function "void CBaseBot::BuyStuff()" that is in bot_ai.cpp after the line
Code:

int* ptrWeaponTab = ptrWeaponPrefs[m_ucPersonality] + NUM_WEAPONS;
I added
Code:

int i;
  char *pszStart;
  char *pszEnd;
  switch (m_ucPersonality)
  {
        case PERSONALITY_NORMAL:
            pszStart = (char *)CVAR_GET_STRING("sb_norwepprefs");
            for (i = 0; i < NUM_WEAPONS; i++)
            {
                pszEnd = strchr(pszStart, ',');
                *ptrWeaponTab++ = atoi(pszStart);
                pszStart = pszEnd + 1;
            }
            break;

        case PERSONALITY_AGRESSIVE:
            pszStart = (char *)CVAR_GET_STRING("sb_agrwepprefs");
            for (i = 0; i < NUM_WEAPONS; i++)
            {
                pszEnd = strchr(pszStart, ',');
                *ptrWeaponTab++ = atoi(pszStart);
                pszStart = pszEnd + 1;
            }
            break;

        case PERSONALITY_DEFENSIVE:
            pszStart = (char *)CVAR_GET_STRING("sb_defwepprefs");
            for (i = 0; i < NUM_WEAPONS; i++)
            {
                pszEnd = strchr(pszStart, ',');
                *ptrWeaponTab++ = atoi(pszStart);
                pszStart = pszEnd + 1;
            }
            break;

  }

and the result is that when a bot tries to buy a weapon the game crashes with runtime error

Whistler 22-09-2009 09:56

Re: YaPB 1.0.0.0 modification problem
 
try adding "ptrWeaponTab = ptrWeaponPrefs[m_ucPersonality] + NUM_WEAPONS;" after the stuff you added, as your code changed the ptrWeaponTab pointer which will be used later.

Serious Sam 22-09-2009 15:46

Re: YaPB 1.0.0.0 modification problem
 
It doesnt work, I still get the runtime error when bots try to buy. Looks like I might have to scrap this idea and try to make it read the weapon prefs for the different maps from the botweapons.cfg file, but for that Ill need to find a function in the hlsdk that returns the current map name, and it also won't be nicer than the cvar idea.


All times are GMT +2. The time now is 09:02.

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