Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weapons sometimes simulate double fires #1691

Closed
jamoy1993 opened this issue Apr 28, 2016 · 6 comments
Closed

Weapons sometimes simulate double fires #1691

jamoy1993 opened this issue Apr 28, 2016 · 6 comments

Comments

@jamoy1993
Copy link

jamoy1993 commented Apr 28, 2016

This is an annoying bug i keep experiencing. With most automatic weapons, I experience a double-fire event. It fires a bullet twice and ejects a shell as if i was shooting a normal bullet. Except it doesn't take it out of the magazine? I have searched around and no one has encountered this bug. It's really annoying as it is not coming from the weapon cpp itself. However i did create a new fire event for the Glock to have a rapid secondary fire and that is working correctly. How ever it uses the exact same code that the primary slower rate of fire uses.

Has anyone got an idea on what may be causing this? I recompile cl and normal dlls every time i test. debug and dev mode are activated also.

`void CGlock::GlockFire( float flSpread , float flCycleTime, BOOL fUseAutoAim )
{
    if (m_iClip <= 0)
    {
        if (m_fFireOnEmpty)
        {
            PlayEmptySound();
            m_flNextPrimaryAttack = GetNextAttackDelay(0.2);
        }

        return;
    }

    m_iClip--;

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

    int flags;

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

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

    // silenced
    if (pev->body == 1)
    {
        m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
        m_pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;
    }
    else
    {
        // non-silenced
        m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
        m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
    }

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

    if ( fUseAutoAim )
    {
        vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
    }
    else
    {
        vecAiming = gpGlobals->v_forward;
    }

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

    PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), fUseAutoAim ? m_usFireGlock1 : m_usFireGlock2, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, ( m_iClip == 0 ) ? 1 : 0, 0 );

    m_flNextPrimaryAttack = m_flNextSecondaryAttack = GetNextAttackDelay(flCycleTime);

    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_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
`
//Auto glock events
void EV_FireGlockAuto(event_args_t *args)
{
    int idx;
    vec3_t origin;
    vec3_t angles;
    vec3_t velocity;

    vec3_t ShellVelocity;
    vec3_t ShellOrigin;
    int shell;
    vec3_t vecSrc, vecAiming;
    vec3_t vecSpread;
    vec3_t up, right, forward;

    idx = args->entindex;
    VectorCopy(args->origin, origin);
    VectorCopy(args->angles, angles);
    VectorCopy(args->velocity, velocity);

    AngleVectors(angles, forward, right, up);

    shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shell.mdl");// brass shell

    if (EV_IsLocal(idx))
    {
        // Add muzzle flash to current weapon model
        EV_MuzzleFlash();
        gEngfuncs.pEventAPI->EV_WeaponAnimation(GLOCK_SHOOT, 2);

        V_PunchAxis(0, -2.0);
    }

    EV_GetDefaultShellInfo(args, origin, velocity, ShellVelocity, ShellOrigin, forward, right, up, 24, -6.5, 3);

    EV_EjectBrass(ShellOrigin, ShellVelocity, angles[YAW], shell, TE_BOUNCE_SHELL);

    gEngfuncs.pEventAPI->EV_PlaySound(idx, origin, CHAN_WEAPON, "weapons/Glock/GlockAuto.wav", gEngfuncs.pfnRandomFloat(0.92, 1.0), ATTN_NORM, 0, 98 + gEngfuncs.pfnRandomLong(0, 3));

    EV_GetGunPosition(args, vecSrc, origin);

    VectorCopy(forward, vecAiming);

    EV_HLDM_FireBullets(idx, forward, right, up, 1, vecSrc, vecAiming, 8192, BULLET_PLAYER_9MM, 0, &tracerCount[idx - 1], args->fparam1, args->fparam2);

}
@jamoy1993
Copy link
Author

This even happens with a fresh copy of the source code. Is this a bug in this version of the source code?

@SamVanheer
Copy link

Sounds to me like the event is firing twice. Does your code check if g_runfuncs is 1 before running client side simulation? If not, it could be triggering events during a second run of the same frame.

You could try using event_api_s::EV_KillEvents to remove any pending events for the weapon from the event queue. If the event is already in the queue multiple times when the first one is executed, that will remove them and stop the double fire. You'll still have to figure out where the event is coming from, but you'll know that that's what's happening.

@YaLTeR
Copy link

YaLTeR commented May 2, 2016

I had this happenning in the latest Steam version, no idea what it's about thought.

@JoelTroch
Copy link
Contributor

I have already reported that issue (see #1621), I think it's related to "client prediction" because if you disable "CLIENT_WEAPONS" in both projects; you won't see that issue.

@agrastiOs
Copy link

@kisak-valve Duplicate of #1621.

@kisak-valve
Copy link
Member

Thanks @agrastiOs, closing as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants