hl1 weapon coding bug Created 3 years ago2020-06-19 17:11:16 UTC by petergriffinxxxtentacion petergriffinxxxtentacion

Created 3 years ago2020-06-19 17:11:16 UTC by petergriffinxxxtentacion petergriffinxxxtentacion

Posted 3 years ago2020-06-19 17:11:16 UTC Post #344426
so i recently created a new hl1 weapon, and everything seems to work properly, but i have a strange bug that sometimes when i press the reload button the reload animation doesn't play and the weapon reloads. how do i fix that?
Posted 3 years ago2020-06-19 19:46:02 UTC Post #344427
It would be a lot easier if you post the code so we can help you.
Posted 3 years ago2020-06-19 21:12:20 UTC Post #344430
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "gamerules.h"

enum fuckfinger_e {
FUCKFINGER_IDLE = 0,
FUCKFINGER_SHOOT1,
FUCKFINGER_SHOOT2,
FUCKFINGER_RELOAD,
FUCKFINGER_RELOAD_NOSHOOT,
FUCKFINGER_DRAW,
FUCKFINGER_SHOOT_EMPTY,
FUCKFINGER_EMPTY_IDLE
};

LINK_ENTITY_TO_CLASS(weapon_fuckfinger, CFuckfinger);

void CFuckfinger::Spawn()
{
pev->classname = MAKE_STRING("weapon_fuckfinger");
Precache();
m_iId = WEAPON_FUCKFINGER;
SET_MODEL(ENT(pev), "models/w_fuckfinger.mdl");

m_iDefaultAmmo = FUCKFINGER_DEFAULT_GIVE;

FallInit();// get ready to fall
}

void CFuckfinger::Precache(void)
{
PRECACHE_MODEL("models/v_fuckfinger.mdl");
PRECACHE_MODEL("models/w_fuckfinger.mdl");
PRECACHE_MODEL("models/p_fuckfinger.mdl");

m_iShell = PRECACHE_MODEL("models/shell.mdl");// brass shell

PRECACHE_SOUND("items/9mmclip1.wav");

PRECACHE_SOUND("items/9mmclip1.wav");
PRECACHE_SOUND("items/9mmclip2.wav");
PRECACHE_SOUND("weapons/pl_gun3.wav");

m_usFireFuckfinger1 = PRECACHE_EVENT(1, "events/fuckfinger.sc");
m_usFireFuckfinger2 = PRECACHE_EVENT(1, "events/fuckfinger2.sc");
}

int CFuckfinger::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "ammo_45";
p->iMaxAmmo1 = _45_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = FUCKFINGER_MAX_CLIP;
p->iSlot = 1;
p->iPosition = 3;
p->iFlags = 0;
p->iId = m_iId = WEAPON_FUCKFINGER;
p->iWeight = FUCKFINGER_WEIGHT;

return 1;
}

BOOL CFuckfinger::Deploy()
{
return DefaultDeploy("models/v_fuckfinger.mdl", "models/p_fuckfinger.mdl", FUCKFINGER_DRAW, "onehanded");
}

void CFuckfinger::SecondaryAttack(void)
{

void;

}

void CFuckfinger::PrimaryAttack()
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3)
{
PlayEmptySound();
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.4;
return;
}

if (m_iClip <= 0)
{
if (!m_fFireOnEmpty)
Reload();
return;
}

m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;

m_iClip--;

int flags;
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
#else
flags = 0;
#endif

m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;

// player "shoot" animation
m_pPlayer->SetAnimation(PLAYER_ATTACK1);

Vector vecSrc = m_pPlayer->GetGunPosition();
Vector vecAiming = m_pPlayer->GetAutoaimVector(AUTOAIM_5DEGREES);

Vector vecDir;
vecDir = m_pPlayer->FireBulletsPlayer(1, vecSrc, vecAiming, VECTOR_CONE_FUCKFINGER, 8192, BULLET_PLAYER_45, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed);

PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usFireFuckfinger1, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0);

if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
// HEV suit - indicate out of ammo condition
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);

m_flNextPrimaryAttack = 0.4;
m_flTimeWeaponIdle = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
}

void CFuckfinger::Reload(void)
{
if (m_pPlayer->ammo_45 <= 0)
return;

int iResult;

if (m_iClip == 0)
iResult = DefaultReload(9, FUCKFINGER_RELOAD, 1.5);
else
iResult = DefaultReload(9, FUCKFINGER_RELOAD_NOSHOOT, 1.5);

if (iResult)
{
m_flTimeWeaponIdle + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
}
}

void CFuckfinger::WeaponIdle(void)
{
ResetEmptySound();

m_pPlayer->GetAutoaimVector(AUTOAIM_10DEGREES);

if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
return;

// only idle if the slid isn't back
if (m_iClip != 0)
{
int iAnim;
float flRand = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 0, 1);

if (flRand <= 0.5)
{
iAnim = FUCKFINGER_IDLE;
m_flTimeWeaponIdle + 70.0 / 30.0;
}
else if (flRand <= 0.7)
{
iAnim = FUCKFINGER_IDLE;
m_flTimeWeaponIdle + 60.0 / 16.0;
}
else
{
iAnim = FUCKFINGER_IDLE;
m_flTimeWeaponIdle + 88.0 / 30.0;
}
SendWeaponAnim(iAnim, 1);
}
}

class CFuckfingerAmmo : public CBasePlayerAmmo
{
void Spawn(void)
{
Precache();
SET_MODEL(ENT(pev), "models/w_9mmarclip.mdl");
CBasePlayerAmmo::Spawn();
}
void Precache(void)
{
PRECACHE_MODEL("models/w_9mmarclip.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
}
BOOL AddAmmo(CBaseEntity *pOther)
{
if (pOther->GiveAmmo(AMMO_FUCKFINGERCLIP_GIVE, "ammo_45", _45_MAX_CARRY) != -1)
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS(ammo_fuckfingerclip, CFuckfingerAmmo);
Posted 3 years ago2020-06-19 21:28:31 UTC Post #344431
i also have a bug in which the weapon doesn't play the idle animation, but when i press the reload key or the right mouse key the idle animation plays.
Posted 3 years ago2020-06-20 12:29:28 UTC Post #344439
Okay, there are some stuff I've noticed about your weapon code. First, the secondary attack:
void CFuckfinger::SecondaryAttack(void)
{

void;

}
If your weapon does not have a secondary attack, then it is useless to override it in your weapon class, also that void; thingy is useless (maybe you meant return;?)

Now onto the reload:
void CFuckfinger::Reload(void)
{
    // Ammo check and actual reload code here

    if (iResult)
    {
        m_flTimeWeaponIdle + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
    }
}
The problem here is that you calculate the next weapon idle time but you never assign the result, you missed a m_flTimeWeaponIdle =

And finally the weapon idle code :
void CFuckfinger::WeaponIdle(void)
{
    // Reset empty sound, autoaim and "time to idle check" code here

    if (m_iClip != 0)
    {
        int iAnim;
        float flRand = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 0, 1);

        if (flRand <= 0.5)
        {
            iAnim = FUCKFINGER_IDLE;
            m_flTimeWeaponIdle + 70.0 / 30.0;
        }
        else if (flRand <= 0.7)
        {
            iAnim = FUCKFINGER_IDLE;
            m_flTimeWeaponIdle + 60.0 / 16.0;
        }
        else
        {
            iAnim = FUCKFINGER_IDLE;
            m_flTimeWeaponIdle + 88.0 / 30.0;
        }
        SendWeaponAnim(iAnim, 1);
    }
}
There are 3 problems here, the first one is the identical to the reload problem (you calculate the next idle times but you never assign them). The second problem is that you forgot UTIL_WeaponTimeBase() in the calculation which is the current game time. And the final problem is that you are randomly picking one of 3 possibles scenarios but all of them play the same idle animation (the idle time being the only difference). You could simplify your WeaponIdle function to something like this:
void CFuckfinger::WeaponIdle()
{
    ResetEmptySound();
    m_pPlayer->GetAutoaimVector(AUTOAIM_10DEGREES);

    // Play idle animation only if it is time to do so and the clip/magazine isn't empty
    if ( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() || m_iClip <= 0 )
        return;

    SendWeaponAnim( FUCKFINGER_IDLE );
    m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 3.0f; // Assuming your idle animation duration is 3 seconds
}
Next time when you post code here, post it in a code block so that's it's easier for everyone to read, see the formatting help wiki page for details.
Posted 3 years ago2020-06-26 16:01:46 UTC Post #344468
thanks! now my problem is fixed, sorry for my late response i've been busy with other things.
You must be logged in to post a response.