.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   how to see if the player is "actually" shooting/reloading (http://forums.bots-united.com/showthread.php?t=2141)

Whistler 29-06-2004 14:43

how to see if the player is "actually" shooting/reloading
 
use if (pPlayer->v.oldbuttons & IN_ATTACK) (or IN_RELOAD) sometimes doesn't work correctly (eg, when the player has no ammo in clip but still pressing the mouse)

anyone has a better idea ? thanks.

botman 29-06-2004 14:44

Re: how to see if the player is "actually" shooting/reloading
 
Checking which animation they are playing?

botman

Pierre-Marie Baty 29-06-2004 15:18

Re: how to see if the player is "actually" shooting/reloading
 
yes, that would work. FoxBot does this (it's a TFC bot). The source code is available so you might want to give it a look :)

Cheeseh 29-06-2004 17:12

Re: how to see if the player is "actually" shooting/reloading
 
I've tried this myself but it doesn't always work. With my bots in SvenCoop I tried checking if the bots animation was the ACT_RELOAD animation, but no animations had that set as the animation activity... guess it depends on what MOD you use.

stefanhendriks 29-06-2004 17:35

Re: how to see if the player is "actually" shooting/reloading
 
for reloading, i guess you can simply check if a reload button is pressed, and then set a timer so you know the 'animation' is being played. it probably depends per mod, but hence i bet the avarage time taken to reload is 1 to 5 seconds (depending on the gun).

Pierre-Marie Baty 29-06-2004 20:53

Re: how to see if the player is "actually" shooting/reloading
 
@Cheeseh:
that's not what FoxBot does. FoxBot hooks the pfnPlaybackEvent() to check for player animations. To my knowledge this function is 100% reliable.

Whistler 01-07-2004 03:09

Re: how to see if the player is "actually" shooting/reloading
 
I beg your pardon ?
...from foxbot:
Code:

void pfnPlaybackEvent(int flags, const edict_t *pInvoker, unsigned short eventindex, float delay,
  float *origin, float *angles, float fparam1,float fparam2, int iparam1, int iparam2, int bparam1, int bparam2)
{
  if (debug_engine)
  {
          fp=fopen("bot.txt","a");
          fprintf(fp,"pfnPlaybackEvent: %d %x %d %f (%f %f %f) (%f %f %f) %f %f %d %d %d %d\n",
                  flags,
                  pInvoker,
                  eventindex,
                  delay,
                  (*(Vector *)origin).x,
                  (*(Vector *)origin).y,
                  (*(Vector *)origin).z,
                  (*(Vector *)angles).x,
                  (*(Vector *)angles).y,
                  (*(Vector *)angles).z,
                  fparam1,
                  fparam2,
                  iparam1,
                  iparam2,
                  bparam1,
                  bparam2
                  );
          fclose(fp);
          //delay=delay+2;
  }
  if(mr_meta) RETURN_META(MRES_HANDLED);
  (*g_engfuncs.pfnPlaybackEvent)(flags, pInvoker, eventindex, delay, origin, angles, fparam1, fparam2, iparam1, iparam2, bparam1, bparam2);
}

but I don't know whether this is good:

here I'm catching CurWeapon message sent to ALL clients (not just bots), and when ammo decreased means a bullet has fired:
Code:

bool CClient::MessageWrite(void *p) {
  static int iState, iId;

  int iMsgType = g_pServer->GetCurMsgType();
  int iMsgState = g_pServer->GetCurMsgState();

  if (iMsgType == g_General.GetUserMsgId("CurWeapon")) {
      if (iMsgState == 0)
        iState = *(int *)p; // get the state of the current weapon
      else if (iMsgState == 1)
        iId = *(int *)p; // get the weapon ID of current weapon
      else if (iMsgState == 2) {
        int iClip = *(int *)p; // get the ammo currently in the clip for this weapon
        if (iId >= 0 && iId < MAX_WEAPONS) {
            // Ammo amount decreased? Must have fired a bullet...
            if (iId == m_iCurrentWeaponId && iClip < m_rgAmmoInClip[iId])
              m_flLastShootTime = gpGlobals->time; // remember the last bullet time
            m_rgAmmoInClip[iId] = iClip;
            if (iState != 0)
              m_iCurrentWeaponId = iId;
        }
      }

and I use this to see if this client is shooting:
Code:

class CClient
{
public:
  .........
  inline bool  IsShooting(void)          { return m_flLastShootTime + 0.5 > gpGlobals->time; }


Pierre-Marie Baty 01-07-2004 13:22

Re: how to see if the player is "actually" shooting/reloading
 
eh? well, that changed, then.

I am positive they DID use pfnPlaybackEvent() and I recall Tom (RedFox) explaining me over there at botman's why it was just what I wanted and how to use this function to hook for various player animations.


All times are GMT +2. The time now is 01:52.

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