Crowbar´s RELOAD code does not work.( No, it´s not a joke ). Created 5 years ago2018-11-25 19:14:24 UTC by abbadon abbadon

Created 5 years ago2018-11-25 19:14:24 UTC by abbadon abbadon

Posted 5 years ago2018-11-25 19:14:24 UTC Post #341325
I have a little problem with a code I have implemented on my MOD recently:

This is my crowbar code:

I have declared all variables:
void CCrowbar::Spawn( )
{
	Precache( );
	m_iId = WEAPON_CROWBAR;
	m_iClip = -1;
	m_iCall = 0;// NUEVO. Limitador del uso de boton de recarga
	FallInit();// get ready to fall down.
}
Added the secondary Ammo
int CCrowbar::GetItemInfo(ItemInfo *p)
{
	p->pszName = STRING(pev->classname);
	p->pszAmmo1 = NULL;
   	p->iMaxAmmo1 = -1;
	p->pszAmmo2 = "ARgrenades";
	p->iMaxAmmo2 = 10;
	p->iMaxClip = WEAPON_NOCLIP;
	p->iSlot = 0;
	p->iPosition = 0;
	p->iId = WEAPON_CROWBAR;
	p->iFlags = 0;//Nuevo
	p->iWeight = CROWBAR_WEIGHT;
	return 1;
}
Here´s the rest of the ammo part:
//=========================================================

int CCrowbar::SecondaryAmmoIndex( void )
{
	return m_iSecondaryAmmoType;
}

//=========================================================
And this is the reload function. It has no modifications different from the rest of weapons (and they work) :
void CCrowbar::Reload( void )
{

//========================================================================================================
// New RELOAD call. It will activates the monstermakers from distance.
//--------------------------------------------------------------------------------------------------------
// (c) Solokiller & Shepard62700FR
//=========================================================================================================

  	if ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= 100 || m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] <= 0 || !TriggerReleased /*Nuevo!!*/|| m_iCall >= 1 /*Nuevo!!*/ )
		return;

	//Limitador del uso del boton de recarga
	else if ( ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= 500) )
	{
		m_iCall -=1;
	}


		edict_t *pPlayer = m_pPlayer->edict( );

		CBaseEntity *pEntity = NULL;
		//Pass pEntity as the start entity to search through all entities properly. - Solokiller
		while ((pEntity = UTIL_FindEntityInSphere( pEntity, m_pPlayer->pev->origin, 500000.0f)) !=NULL)
		{
			//Check if the targetname matches the owning player's team to filter monstermakers. - Solokiller
			if ( FClassnameIs( pEntity->pev, "monstermaker" ) && FStrEq( STRING( pEntity->pev->targetname ), m_pPlayer->TeamID() ) )
				{
					pEntity->Use( m_pPlayer, m_pPlayer, USE_ON, 0.0f );

				}
		}

		ALERT( at_console, "RELOAD!!\n" );
        	m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] -= 1;
				TriggerReleased = FALSE;
			EMIT_SOUND(ENT(pev), CHAN_ITEM, "weapons/reload.wav", 1, ATTN_NORM);//Aqui va lo del sonido

			m_iCall +=1;//Nuevo


}
And in weapons.h I have done all stuf afaik:
class CCrowbar : public CBasePlayerWeapon
{
public:
	void Spawn( void );
	void Precache( void );
	int iItemSlot( void ) { return 1; }
	void EXPORT SwingAgain( void );
	void EXPORT Smack( void );
	int GetItemInfo(ItemInfo *p);

	void PrimaryAttack( void );
	int Swing( int fFirst );
	BOOL Deploy( void );
	void Holster( int skiplocal = 0 );
	int m_iSwing;
	TraceResult m_trHit;

	int m_iCall;

    // Añadida recarga al CROWBAR
	int SecondaryAmmoIndex( void );

	void Reload( void );

	 BOOL TriggerReleased;// Limitador de tiempo para recarga


	virtual BOOL UseDecrement( void )
	{
#if defined( CLIENT_WEAPONS )
		return TRUE;
#else
		return FALSE;
#endif
	}
private:

	float m_flFreezeTime;   // Freeze Player Timer
	unsigned short m_usCrowbar;
};
The weapon works flawlessly, sprites are shown, but the RELOAD does not work at all. I have compiled both hl.dll and client.dll with no problems at all. In the rest of weapons it works, but not in the Crowbar. I have added this code to make the BOTS can use the crowbar and call for RELOAD when they run out of ammo. Did I miss something? (apart of reading more C++ book, I know that, please be merciful... XD )

Thanks in anticipation. :)
Posted 5 years ago2018-11-25 20:47:35 UTC Post #341327
Oh I forgot to say that I add this
	//Always run Reload() when the reload key is pressed. - Solokiller
	 virtual bool ShouldReload() { return true; }
to the CCrowbar part in weapons.ha (posted old code, sorry).

And in weapons.cpp on itempostframe function
	else if ( m_pPlayer->pev->button & IN_RELOAD && ( ShouldReload() || ( iMaxClip() != WEAPON_NOCLIP ) ) && !m_fInReload )
	{
		// reload when reload is pressed, or if no buttons are down and weapon is empty.
		Reload();
BTW: Commenting iMaxClip() != WEAPON_NOCLIP also does not work... :(

One more question, could it be caused because the model has not the RELOAD animation and because it has no event asociated? (I think it is 5004 or something like that).

Another curious thing: if I put +RELOAD in the console while using the CROWBAR the reload call does not work, BUT, when I switch to another weapon then it works automatically and makes its stuff ... O_o
Posted 5 years ago2018-11-27 22:33:59 UTC Post #341337
Whatever. I have decided to take a different method of approaching what I am looking for. Finally I have achieved that the Bots use the melee weapon without problems, this is the code:
//=============================================================================================
// WEAPON URAKEN/CROWBAR I cannot make the bot use this weapon!!! I suck in coding...4-May-2015
// GOT IT!! 24-November-2018 but with Issues...
//=============================================================================================

if (pev->weapons & (1<<WEAPON_CROWBAR))

  {
      if (((distance <= 62) && (bot_skill <= 5 ) &&(weapon_choice == 0) && (weapon_choice == WEAPON_CROWBAR)
            || ( primary_ammo[WEAPON_TWOHAND]   <=0 )
            || ( primary_ammo[WEAPON_SHORYUKEN] <=0 )
            || ( primary_ammo[WEAPON_SIEGE]     <=0 )
            || ( primary_ammo[WEAPON_MJOLNIR]   <=0 )
            || ( primary_ammo[WEAPON_SHREDDER]  <=0 ) ))
  {

          new_weapon = weapon_ptr[WEAPON_CROWBAR];
         {
         // check if the bot isn't already using this item...
         if (m_pActiveItem != new_weapon)
             SelectItem("weapon_crowbar");  // select the crowbar
             pev->button |= IN_ATTACK;  // use primary attack (whack! whack!)
            // set next time to shoot
            f_shoot_time = gpGlobals->time
                + 0.1
                + RANDOM_FLOAT(primary_fire_delay[WEAPON_CROWBAR][bot_skill][0],primary_fire_delay[WEAPON_CROWBAR][bot_skill][1]);//ese punto y coma lo debo quitar si descomento el "-" y lo que va detrás
                //- RANDOM_FLOAT(secondary_fire_delay[WEAPON_CROWBAR][bot_skill][0],secondary_fire_delay[WEAPON_CROWBAR][bot_skill][1]);
            return TRUE;
         }

    }



   }
//========================================================================================
What I'm trying to do now is that somehow the code does not activate automatically and first make it happen after a while to re-select the weapons that use ammunition and try to activate the recharge through them.

I tried to enter a check code of the secondary ammunition and that from it I would re-select a projectile weapon, activate the recharge and then return to the melee weapon, but without success.

The projectile weapons has this check for primary ammo, and it sometimes work, others don´t. But that´s because the very firing code, something on which I must work harder. BUt what is true is that once the URAKEN is selected, bots cannot detect that they ran out of ammo and don´t try to reload using the projectile weapons.

How could it be done ?, or if there is a better method to achieve the same. Honestly to methe code above described seems a bit tricky ...
Posted 5 years ago2018-11-28 07:57:26 UTC Post #341339
Well, I am putting so much confidence on the Bot's habilities, what I'll try is to think it from the point of view of a tool maker, putting the task of deciding this process on the weapon's part. I will tell you later what happen.

Edit: well, all is fixed now. Of course there are things still undone, as the fact that one of the weapons is not still used by the Bots, but I know now exactly what to do. The approach was wrong from the beggining, and one of the causes of this bad approach was to take too much seriously the Bot, as I said before. This Bot (Bot #10) is very simple, please, don´t get me wrong, working 10 hours a day for 30 years could not make me do something similar, but the bot is simple in therms of features. It is oriented to be used as a standalone comrade in classic Half-Life deathmatch. It can pick weapons and navigate maps that are not very complex, even it can use health rechargers and jump and crouch, but my mistake was to try to make them more than that.

What I should do first is to think on the way the things work in real life, that is, what´s overheating, cooling itself, and is able to be reloaded?, the weapon, right?, so I decided to put all the conditions on the weapon. Can the weapon overheat?, well, let´s put conditions for the REAL player and for the FAKE player, can it reload?, ok, put some if statements and make them so the FAKE PLAYER receive this or that thing that, combined with the Bot code make things happen as I wanted.

Finally I hace added this two lines of code (forgive me if the code sucks, is dirty, makes your eyes bleed, etc. PLEASE :walter: ):

`void CShoryuken::Reload( void )
{
Cooldown(); // Shepard : Cool down our weapon (if we can)
//========================================================================================================
// New RELOAD call. It will activates the monstermakers from distance.
//--------------------------------------------------------------------------------------------------------
// Concept code first version (c) Angel Ramos (Not Implemented) Based on satchel.cpp code
// Code second version advices(c) Shepard62700FR (Not implemented)
// Concept code third version (c) Solokiller (implemented)
// First code based on Solokiller´s advices (implemented, not working)
// Non working RELOAD key Fix (c) Shepard62700FR
// Last version (c) Solokiller Working!!
// Last fixes (c) Angel Ramos ( Limited number of reloads, added Triggerreleased part so button only works
// on "semi", because, before, all "ammo" was depleted when the button "R"
// was pressed because the call was continuous)
//=========================================================================================================

if ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= 100 || m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] <= 0 || !TriggerReleased || m_iCall >= 1 )

return;

else if ( ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= 500) )
{
m_iCall -=1;
}
edict_t *pPlayer = m_pPlayer->edict( );

CBaseEntity *pEntity = NULL;
//Pass pEntity as the start entity to search through all entities properly. - Solokiller
while ((pEntity = UTIL_FindEntityInSphere( pEntity, m_pPlayer->pev->origin, 500000.0f)) !=NULL)
{
//Check if the targetname matches the owning player's team to filter monstermakers. - Solokiller
if ( FClassnameIs( pEntity->pev, "monstermaker" ) && FStrEq( STRING( pEntity->pev->targetname ), m_pPlayer->TeamID() ) )
{
pEntity->Use( m_pPlayer, m_pPlayer, USE_ON, 0.0f );
}
}

ALERT( at_console, "RELOAD!!\n" );
m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] -= 1;
TriggerReleased = FALSE;
EMIT_SOUND(ENT(pev), CHAN_ITEM, "weapons/reload.wav", 1, ATTN_NORM);//Aqui va lo del sonido
m_iCall +=1;//Nuevo

if (FBitSet(m_pPlayer->pev->flags, FL_FAKECLIENT) && ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )) { m_iCall += 0;
m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] -= 0; m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] += 20; }
if (FBitSet(m_pPlayer->pev->flags, FL_FAKECLIENT) && ( m_iCall =1 )) { m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= 600; }
}`

It's so coarse that I'm ashamed to put it here, but, well, I'm not able to do it better, and, hey, it works ... :crowbar:

Now the Bot, when it uses a projectile weapon and can Reload (m_iCall = 0) but its ammo is depleted(m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0), and because sometimes it is like if they cannot decide to use the reload function I decided to give them a bit of ammo (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] += 20) to let them still try to reload. If all goes right, they´ll use the reload button, and that´s when they receive +1 m_iCall and their ammo was depleted instantly (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= 600) so they must use the URAKEN weapon. When the Bot is reloaded, m_iCall is set to zero again, they can reload, and have new fresh ammo to fight.

:nuts:

Thanks for reading!! ;)

BTW: I´m again working on ZWC.
User posted image
Posted 5 years ago2018-12-01 00:52:07 UTC Post #341365
Yeah putting bot-specific logic in the weapon class is probably not the best approach.
I think botman's bots have some edge cases in the shooting code though - there are no checks on the minimum amount of ammo required to shoot.
Posted 5 years ago2018-12-01 00:55:40 UTC Post #341366
Yes!, I have all his Bot´s source, and I decided to use Bot #10 code to make the code for my Bot. Basically is a moving turret. Now I am working on the FEMP countermeasure. The bot have used it two or three time in all this years of development, but I am sure I will find how to make it choose this weapon. :)
You must be logged in to post a response.