bad coding needs help. Can´t create counter inside weapon code. Created 5 years ago2019-08-16 15:42:49 UTC by abbadon abbadon

Created 5 years ago2019-08-16 15:42:49 UTC by abbadon abbadon

Posted 5 years ago2019-08-16 15:42:49 UTC Post #343026
This is the function I created to do this:

1. If Bot (m_pPlayer->pev->flags, FL_FAKECLIENT)...
2. Depletes its ammo (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0)
3. m_flFreeammotime (declered in weapons.h) increases its value 5 secs ( 8.0f )
4. Then if time (I think I wrote this right) is greater than m_flFreeammotime (m_flFreeammotime && gpGlobals->time > m_flFreeammotime)
5. Give some ammo to the bo (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]+=25;) , but not before 5 seconds have passed...

The function:
/================================================================================================ / Modulo para limitar la actividad de los Bots cuando se quedan sin munición y le regalamos un poco
//================================================================================================
if (FBitSet(m_pPlayer->pev->flags, FL_FAKECLIENT) && (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0))
{
m_flFreeammotime = gpGlobals->time + 8.0f;

}
if (FBitSet(m_pPlayer->pev->flags, FL_FAKECLIENT) && (m_flFreeammotime && gpGlobals->time > m_flFreeammotime))
{
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]+=25;
}

//================================================================================================

It does not work. Bots deplete their ammo and remain that way, no ammo is given to them. The "m_flFreeammotime && gpGlobals->time > m_flFreeammotime" it´s the same code ( using m_flFreezeTime instead) used to detect if that time (5 secs) has passed and let the bots move after firing the weapons, and it works!, I thought that using the same code will work too but it does not.

What I am doing wrong? :(
Posted 5 years ago2019-08-16 16:29:54 UTC Post #343028
It's probably hitting the first conditional constantly and keeps setting m_flFreeammotime to a time in the future. Try tracking whether that variable has been set, maybe add a condition m_flFreeammotime == 0 and then set it back to 0 when you've run the ammo reset code.

It looks like you're doing manually what the weapons code is doing automatically for reloads so maybe see if you can't just use that instead.
Posted 5 years ago2019-08-16 16:56:41 UTC Post #343029
I put m_flFreeammotime = 0 in the spawn method of the weapon to see if it works, but with no avail :( Also, I have tried to put the if (FBitSet(m_pPlayer->pev->flags, FL_FAKECLIENT) && (m_flFreeammotime && gpGlobals->time > m_flFreeammotime)) into the first "if" right under *m_flFreeammotime = gpGlobals->time + 8.0f; but it does not work either. :( . If I remove the m_flFreeammotime the Bots have this little ammount of ammo again available, but that´s not what I wanted, I want them to have that help after some time. I did this because sometimes the Bots don´t go close the reloader guys and remain helpless against the enemy because they are not reloaded, but without some handicap condition they last more than what´s intended to last.

This is my last version, don´t work either...


if (FBitSet(m_pPlayer->pev->flags, FL_FAKECLIENT) && (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0))
{
m_flFreeammotime = gpGlobals->time + 8.0f;

{
if (m_flFreeammotime && gpGlobals->time > m_flFreeammotime)
{
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]+=25;
m_flFreeammotime = 0;
}
}
}

EDIT: I´m a moron. Sorry, I´ll try THIS on the RELOAD function instead.... :\

Tried:


if (FBitSet(m_pPlayer->pev->flags, FL_FAKECLIENT) && (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0))
{
m_flNextPrimaryAttack = 5.0;
m_flNextSecondaryAttack = 5.0;
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]+=25;

}

Just to keep them from firing continuously after reload. But With no luck... No free ammo added...
Posted 5 years ago2019-08-16 21:43:37 UTC Post #343032
This is the actual code.
It is located into the primary and secondary fire function of the weapon. It works!, but the reload is inmediate, which is not the purpose of the code as you can see because I put into it two retardants for both primary and secondary fire.

//=====================================================================
// Modulo para limitar la actividad de los Bots cuando se quedan sin munición y le regalamos un poco.
// Module to limit the activity of the Bots when they run out of ammunition and we give the a little ammo.
//=====================================================================
if (FBitSet(m_pPlayer->pev->flags, FL_FAKECLIENT) && (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0))
{
m_flNextPrimaryAttack = 5.0;// Stop firing for a while
m_flNextSecondaryAttack = 5.0;// Stop firing for a while
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] += 25;//Don´t add so much ammo

}
//=========================================================================

Retardant works fine here:

if ((FBitSet(m_pPlayer->pev->flags, FL_FAKECLIENT))&&(m_iHeat>=200)){ m_flNextPrimaryAttack = 8.0f; }//Bots don´t fire for 5 secs if they overheat!!

Sure I am doing something wrong but again I´m lost.
Posted 5 years ago2019-08-16 22:51:27 UTC Post #343033
It's difficult to diagnose without knowing when, how, and where this code is executed.

May I suggest you put in code to write messages whenever the relevant functions are called. You could have the messages include the values of the of the variables. This should help you follow the flow of the code and figure out what's happening.

By retardant I assume you mean delay? A retardant is something that inhibits for example fire.
Posted 5 years ago2019-08-16 23:01:30 UTC Post #343035
May I suggest you put in code to write messages whenever the relevant functions are called. You could have the messages include the values of the of the variables. This should help you follow the flow of the code and figure out what's happening.
So much this, any time you are having issues with a block of code or function you need to find a way to visually show you exactly what is happening at every step of execution.
IMO even if you aren't having issues you should be doing this anyways just to make sure everything is actually working as intended.
Crollo CrolloTrollo
Posted 5 years ago2019-08-16 23:22:19 UTC Post #343036
Pretty much that. ^
Log to the console whenever you can or are having trouble.

Sometimes you can also use a debugger, for stuff that goes too fast or is too complicated to track via the console. (e.g. buncha nested for loops or a dozen variables you gotta keep tracking)
Admer456 Admer456If it ain't broken, don't fox it!
Posted 5 years ago2019-08-17 09:22:22 UTC Post #343037
Yes, I mean "delay", haha, my english sometime suck most than my coding!!

The code is executed right after when the primary or secondary fire is done, under the:

*m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;*

...part. So when a bullet is fired the code tells that if the player is a fake client (a bot) and ammo reaches zero, give it some little ammo applying some delay to preevnt the bot have "infinite" ammo (i did that part in a previous version of the bot simply adding that if its fakeclient just...

*m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]-=0;*

What I really want is to add a delay between the bot´s ammo reaches zero and the moment the code gives it some extra ammo.
Posted 5 years ago2019-08-19 21:17:54 UTC Post #343049
I remember Solokiller pointed me to add console messages for a block of code that´s not working, I did that part the first (now I add a console printing part in every new code I try ;) ). And... well I find a "dirty" fix. Now it´s kind of solved, it is not perfect but solves all. Thanks for all the solutions!! :P
You must be logged in to post a response.