void CWeaponG3SG1::G3SG1Fire(float flSpread) { CMomentumPlayer *pPlayer = GetPlayerOwner(); if (!pPlayer) return; // If we are not zoomed in, or we have very recently zoomed and are still transitioning, the bullet diverts more. if (pPlayer->GetFOV() == pPlayer->GetDefaultFOV() || (gpGlobals->curtime < m_zoomFullyActiveTime)) flSpread += 0.025; // Mark the time of this shot and determine the accuracy modifier based on the last shot fired... m_flAccuracy = 0.55 + (0.3) * (gpGlobals->curtime - m_flLastFire); if (m_flAccuracy > 0.98) m_flAccuracy = 0.98; m_flLastFire = gpGlobals->curtime; if (!CSBaseGunFire(flSpread, GetCSWpnData().m_flCycleTime, true)) return; // Adjust the punch angle. QAngle angle = pPlayer->GetPunchAngle(); angle.x -= SharedRandomFloat("G3SG1PunchAngleX", 0.75, 1.75) + (angle.x / 4); angle.y += SharedRandomFloat("G3SG1PunchAngleY", -0.75, 0.75); pPlayer->SetPunchAngle(angle); }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CWeaponDoubleShotgun::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) { return; } if (m_iClip1 >= 2) { // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(WPN_DOUBLE); pPlayer->DoMuzzleFlash(); SendWeaponAnim( ACT_VM_SECONDARYATTACK ); // Don't fire again until fire animation has completed m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); m_iClip1 -= 2; // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); FireBulletsInfo_t info( 40, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); info.m_pAttacker = pPlayer; // Fire the bullets, and force the first shot to be perfectly accuracy pPlayer->FireBullets( info ); QAngle punch; punch.Init( SharedRandomFloat( "shotgunpax", -2, -1 ), SharedRandomFloat( "shotgunpay", -2, 2 ), 0 ); pPlayer->ViewPunch( punch ); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } //m_bNeedPump = true; } else { if (m_bInReload) { Reload(); } else { StartReload(); } } }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CWeaponShotgun::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) { return; } // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(SINGLE); pPlayer->DoMuzzleFlash(); SendWeaponAnim( ACT_VM_PRIMARYATTACK ); // Don't fire again until fire animation has completed m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); m_iClip1 -= 1; // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); FireBulletsInfo_t info( 7, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); info.m_pAttacker = pPlayer; // Fire the bullets, and force the first shot to be perfectly accuracy pPlayer->FireBullets( info ); #ifdef SecobMod__Enable_Fixed_Multiplayer_AI #ifndef CLIENT_DLL // DM: Hellow? NPCs... look here! I'm shooting! pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 1.0 ); CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_SHOTGUN, 0.2 ); #endif #endif //SecobMod__Enable_Fixed_Multiplayer_AI QAngle punch; punch.Init( SharedRandomFloat( "shotgunpax", -2, -1 ), SharedRandomFloat( "shotgunpay", -2, 2 ), 0 ); pPlayer->ViewPunch( punch ); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } m_bNeedPump = true; }
//----------------------------------------------------------------------------- // Purpose: Add in a view kick for this weapon //----------------------------------------------------------------------------- void CWeaponCrowbar::AddViewKick( void ) { CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer == NULL ) return; QAngle punchAng; punchAng.x = SharedRandomFloat( "crowbarpax", 1.0f, 2.0f ); punchAng.y = SharedRandomFloat( "crowbarpay", -2.0f, -1.0f ); punchAng.z = 0.0f; pPlayer->ViewPunch( punchAng ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponPistol::AddViewKick( void ) { CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer == NULL ) return; QAngle viewPunch; viewPunch.x = SharedRandomFloat( "pistolpax", 0.25f, 0.5f ); viewPunch.y = SharedRandomFloat( "pistolpay", -.6f, .6f ); viewPunch.z = 0.0f; //Add it to the view punch pPlayer->ViewPunch( viewPunch ); }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CWeaponShotgun::SecondaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) { return; } pPlayer->m_nButtons &= ~IN_ATTACK2; // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(WPN_DOUBLE); pPlayer->DoMuzzleFlash(); SendWeaponAnim( ACT_VM_SECONDARYATTACK ); // Don't fire again until fire animation has completed m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); m_iClip1 -= 2; // Shotgun uses same clip for primary and secondary attacks // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); //Tony; does shotgun have a second anim? ToHL2MPPlayer(pPlayer)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); Vector vecSrc = pPlayer->Weapon_ShootPosition(); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); FireBulletsInfo_t info( 12, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); info.m_pAttacker = pPlayer; // Fire the bullets, and force the first shot to be perfectly accuracy pPlayer->FireBullets( info ); pPlayer->ViewPunch( QAngle(SharedRandomFloat( "shotgunsax", -5, 5 ),0,0) ); #ifdef HL2SB #ifndef CLIENT_DLL pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 1.0 ); CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_SHOTGUN, 0.2 ); #endif #endif if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } m_bNeedPump = true; #ifdef HL2SB #ifndef CLIENT_DLL gamestats->Event_WeaponFired( pPlayer, false, GetClassname() ); #endif #endif }
void CWeaponShotgun::AddViewKick( void ) { CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer == NULL ) return; QAngle viewPunch; viewPunch.x = SharedRandomFloat( "Shotgunpax", GetGEWpnData().Kick.x_min, GetGEWpnData().Kick.x_max ); viewPunch.y = SharedRandomFloat( "Shotgunpay", GetGEWpnData().Kick.y_min, GetGEWpnData().Kick.y_max ); viewPunch.z = 0.0f; //Add it to the view punch pPlayer->ViewPunch( viewPunch ); }
void CWeaponSubMachineGun::AddViewKick( void ) { #define EASY_DAMPEN 0.5f #define MAX_VERTICAL_KICK 1.0f //Degrees #define SLIDE_LIMIT 2.0f //Seconds //Get the view kick CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer == NULL ) return; DoMachineGunKick( pPlayer, EASY_DAMPEN, MAX_VERTICAL_KICK, m_fFireDuration, SLIDE_LIMIT ); // Add a view punch too QAngle viewPunch; viewPunch.x = SharedRandomFloat( "smg1pax", BALANCE_VALUE( Float, lfm_smg1_vx_min ), BALANCE_VALUE( Float, lfm_smg1_vx_max ) ); viewPunch.y = SharedRandomFloat( "smg1pay", BALANCE_VALUE( Float, lfm_smg1_vy_min ), BALANCE_VALUE( Float, lfm_smg1_vy_max ) ); viewPunch.z = 0.0f; pPlayer->ViewPunch( viewPunch ); }
int CWeaponCrowbar::WeaponMeleeAttack1Condition( float flDot, float flDist ) { // Attempt to lead the target (needed because citizens can't hit manhacks with the crowbar!) CAI_BaseNPC *pNPC = GetOwner()->MyNPCPointer(); CBaseEntity *pEnemy = pNPC->GetEnemy(); if (!pEnemy) return COND_NONE; Vector vecVelocity; vecVelocity = pEnemy->GetSmoothedVelocity( ); // Project where the enemy will be in a little while float dt = sk_crowbar_lead_time.GetFloat(); dt += SharedRandomFloat( "crowbarmelee1", -0.3f, 0.2f ); if ( dt < 0.0f ) dt = 0.0f; Vector vecExtrapolatedPos; VectorMA( pEnemy->WorldSpaceCenter(), dt, vecVelocity, vecExtrapolatedPos ); Vector vecDelta; VectorSubtract( vecExtrapolatedPos, pNPC->WorldSpaceCenter(), vecDelta ); if ( fabs( vecDelta.z ) > 70 ) { return COND_TOO_FAR_TO_ATTACK; } Vector vecForward = pNPC->BodyDirection2D( ); vecDelta.z = 0.0f; float flExtrapolatedDist = Vector2DNormalize( vecDelta.AsVector2D() ); if ((flDist > 64) && (flExtrapolatedDist > 64)) { return COND_TOO_FAR_TO_ATTACK; } float flExtrapolatedDot = DotProduct2D( vecDelta.AsVector2D(), vecForward.AsVector2D() ); if ((flDot < 0.7) && (flExtrapolatedDot < 0.7)) { return COND_NOT_FACING_ATTACK; } return COND_CAN_MELEE_ATTACK1; }
void CSDKPlayerShared::SetRecoil(float flRecoil) { m_flRecoilAccumulator = flRecoil * da_recoilmultiplier.GetFloat(); m_vecRecoilDirection.y = 1; m_vecRecoilDirection.x = SharedRandomFloat( "Recoil", -0.5f, 0.5f ); }
void CC4::PrimaryAttack() { bool PlaceBomb = false; CCSPlayer *pPlayer = GetPlayerOwner(); if ( !pPlayer ) return; int onGround = FBitSet( pPlayer->GetFlags(), FL_ONGROUND ); CBaseEntity *groundEntity = (onGround) ? pPlayer->GetGroundEntity() : NULL; if ( groundEntity ) { // Don't let us stand on players, breakables, or pushaway physics objects to plant if ( groundEntity->IsPlayer() || IsPushableEntity( groundEntity ) || #ifndef CLIENT_DLL IsBreakableEntity( groundEntity ) || #endif // !CLIENT_DLL IsPushAwayEntity( groundEntity ) ) { onGround = false; } } if( m_bStartedArming == false && m_bBombPlanted == false ) { if( pPlayer->m_bInBombZone && onGround ) { m_bStartedArming = true; m_fArmedTime = gpGlobals->curtime + WEAPON_C4_ARM_TIME; m_bBombPlacedAnimation = false; #if !defined( CLIENT_DLL ) // init the beep flags int i; for( i=0;i<NUM_BEEPS;i++ ) m_bPlayedArmingBeeps[i] = false; // freeze the player in place while planting pPlayer->SetMaxSpeed( 1 ); // player "arming bomb" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); pPlayer->SetNextAttack( gpGlobals->curtime ); IGameEvent * event = gameeventmanager->CreateEvent( "bomb_beginplant" ); if( event ) { event->SetInt("userid", pPlayer->GetUserID() ); event->SetInt("site", pPlayer->m_iBombSiteIndex ); event->SetInt( "priority", 8 ); gameeventmanager->FireEvent( event ); } #endif SendWeaponAnim( ACT_VM_PRIMARYATTACK ); FX_PlantBomb( pPlayer->entindex(), pPlayer->Weapon_ShootPosition() ); } else { if ( !pPlayer->m_bInBombZone ) { ClientPrint( pPlayer, HUD_PRINTCENTER, "#C4_Plant_At_Bomb_Spot"); } else { ClientPrint( pPlayer, HUD_PRINTCENTER, "#C4_Plant_Must_Be_On_Ground"); } m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; return; } } else { if ( !onGround || !pPlayer->m_bInBombZone ) { if( !pPlayer->m_bInBombZone ) { ClientPrint( pPlayer, HUD_PRINTCENTER, "#C4_Arming_Cancelled" ); } else { ClientPrint( pPlayer, HUD_PRINTCENTER, "#C4_Plant_Must_Be_On_Ground" ); } m_flNextPrimaryAttack = gpGlobals->curtime + 1.5; m_bStartedArming = false; #if !defined( CLIENT_DLL ) // release the player from being frozen, we've somehow left the bomb zone pPlayer->ResetMaxSpeed(); pPlayer->SetProgressBarTime( 0 ); //pPlayer->SetAnimation( PLAYER_HOLDBOMB ); IGameEvent * event = gameeventmanager->CreateEvent( "bomb_abortplant" ); if( event ) { event->SetInt("userid", pPlayer->GetUserID() ); event->SetInt("site", pPlayer->m_iBombSiteIndex ); event->SetInt( "priority", 8 ); gameeventmanager->FireEvent( event ); } #endif if(m_bBombPlacedAnimation == true) //this means the placement animation is canceled { SendWeaponAnim( ACT_VM_DRAW ); } else { SendWeaponAnim( ACT_VM_IDLE ); } return; } else { #ifndef CLIENT_DLL PlayArmingBeeps(); #endif if( gpGlobals->curtime >= m_fArmedTime ) //the c4 is ready to be armed { //check to make sure the player is still in the bomb target area PlaceBomb = true; } else if( ( gpGlobals->curtime >= (m_fArmedTime - 0.75) ) && ( !m_bBombPlacedAnimation ) ) { //call the c4 Placement animation m_bBombPlacedAnimation = true; SendWeaponAnim( ACT_VM_SECONDARYATTACK ); #if !defined( CLIENT_DLL ) // player "place" animation //pPlayer->SetAnimation( PLAYER_HOLDBOMB ); #endif } } } if ( PlaceBomb && m_bStartedArming ) { m_bStartedArming = false; m_fArmedTime = 0; if( pPlayer->m_bInBombZone ) { #if !defined( CLIENT_DLL ) CPlantedC4 *pC4 = CPlantedC4::ShootSatchelCharge( pPlayer, pPlayer->GetAbsOrigin(), pPlayer->GetAbsAngles() ); if ( pC4 ) { pC4->SetBombSiteIndex( pPlayer->m_iBombSiteIndex ); trace_t tr; UTIL_TraceEntity( pC4, GetAbsOrigin(), GetAbsOrigin() + Vector(0,0,-200), MASK_SOLID, this, COLLISION_GROUP_NONE, &tr ); pC4->SetAbsOrigin( tr.endpos ); CBombTarget *pBombTarget = (CBombTarget*)UTIL_EntityByIndex( pPlayer->m_iBombSiteIndex ); if ( pBombTarget ) { CBaseEntity *pAttachPoint = gEntList.FindEntityByName( NULL, pBombTarget->GetBombMountTarget() ); if ( pAttachPoint ) { pC4->SetAbsOrigin( pAttachPoint->GetAbsOrigin() ); pC4->SetAbsAngles( pAttachPoint->GetAbsAngles() ); pC4->SetParent( pAttachPoint ); } variant_t emptyVariant; pBombTarget->AcceptInput( "BombPlanted", pC4, pC4, emptyVariant, 0 ); } } IGameEvent * event = gameeventmanager->CreateEvent( "bomb_planted" ); if( event ) { event->SetInt("userid", pPlayer->GetUserID() ); event->SetInt("site", pPlayer->m_iBombSiteIndex ); event->SetInt("posx", pPlayer->GetAbsOrigin().x ); event->SetInt("posy", pPlayer->GetAbsOrigin().y ); event->SetInt( "priority", 8 ); gameeventmanager->FireEvent( event ); } // Fire a beep event also so the bots have a chance to hear the bomb event = gameeventmanager->CreateEvent( "bomb_beep" ); if ( event ) { event->SetInt( "entindex", entindex() ); gameeventmanager->FireEvent( event ); } pPlayer->SetProgressBarTime( 0 ); CSGameRules()->m_bBombDropped = false; CSGameRules()->m_bBombPlanted = true; // Play the plant sound. Vector plantPosition = pPlayer->GetAbsOrigin() + Vector( 0, 0, 5 ); CPASAttenuationFilter filter( plantPosition ); EmitSound( filter, entindex(), "c4.plant" ); // release the player from being frozen pPlayer->ResetMaxSpeed(); // No more c4! pPlayer->Weapon_Drop( this, NULL, NULL ); UTIL_Remove( this ); #endif //don't allow the planting to start over again next frame. m_bBombPlanted = true; return; } else { ClientPrint( pPlayer, HUD_PRINTCENTER, "#C4_Activated_At_Bomb_Spot" ); #if !defined( CLIENT_DLL ) //pPlayer->SetAnimation( PLAYER_HOLDBOMB ); // release the player from being frozen pPlayer->ResetMaxSpeed(); IGameEvent * event = gameeventmanager->CreateEvent( "bomb_abortplant" ); if( event ) { event->SetInt("userid", pPlayer->GetUserID() ); event->SetInt("site", pPlayer->m_iBombSiteIndex ); event->SetInt( "priority", 8 ); gameeventmanager->FireEvent( event ); } #endif m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; return; } } m_flNextPrimaryAttack = gpGlobals->curtime + 0.3; SetWeaponIdleTime( gpGlobals->curtime + SharedRandomFloat("C4IdleTime", 10, 15 ) ); }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CWeaponFreeze::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) { return; } // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(SINGLE); //pPlayer->DoMuzzleFlash(); SendWeaponAnim( ACT_VM_PRIMARYATTACK ); // Don't fire again until fire animation has completed m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); m_iClip1 -= 1; // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); ToHL2MPPlayer(pPlayer)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); FireBulletsInfo_t info( 7, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); info.m_pAttacker = pPlayer; // Fire the bullets, and force the first shot to be perfectly accuracy pPlayer->FireBullets( info ); QAngle punch; punch.Init( SharedRandomFloat( "shotgunpax", -2, -1 ), SharedRandomFloat( "shotgunpay", -2, 2 ), 0 ); pPlayer->ViewPunch( punch ); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } trace_t tr; // do the traceline UTIL_TraceLine( vecSrc, vecAiming, MASK_ALL, pPlayer,COLLISION_GROUP_NPC, &tr ); // do if statements to check what we hit ... add if player is human, etc, etc if ( tr.m_pEnt ) { // This will ignite the player tr.m_pEnt->SetAbsVelocity(0); tr.m_pEnt->Freeze(); tr.m_pEnt->SetGravity(2000000); } }
static int luasrc_SharedRandomFloat (lua_State *L) { lua_pushnumber(L, SharedRandomFloat(luaL_checkstring(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_optint(L, 4, 0))); return 1; }