Advertisement
FlacoBey

Untitled

Jun 14th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.80 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <l4d_stocks>
  4.  
  5. #define MAXEDICTS 2048
  6. #define MAXENTITIES 4096
  7.  
  8. #define NETPROP_PLAYER_ACTIVEWEAPON "m_hActiveWeapon"
  9. #define NETPROP_PLAYER_VIEWMODEL "m_hViewModel"
  10. #define NETPROP_PLAYER_NEXTATTACK "m_flNextAttack"
  11.  
  12. #define NETPROP_WEAPON_INRELOAD "m_bInReload"
  13. #define NETPROP_WEAPON_NEXTPRIMARYATTACK "m_flNextPrimaryAttack"
  14. #define NETPROP_WEAPON_TIMEWEAPONIDLE "m_flTimeWeaponIdle"
  15. #define NETPROP_WEAPON_SHOTGUN_RELOADSTATE "m_reloadState"
  16. #define NETPROP_WEAPON_SHOTGUN_RELOADANIMSTATE "m_reloadAnimState"
  17. #define NETPROP_WEAPON_SHOTGUN_RELOADNUMSHELLS "m_reloadNumShells"
  18. #define NETPROP_WEAPON_SHOTGUN_SHELLSINSERTED "m_shellsInserted"
  19.  
  20. #define NETPROP_VIEWMODEL_LAYERSEQUENCE "m_nLayerSequence"
  21. #define NETPROP_VIEWMODEL_LAYERSTARTTIME "m_flLayerStartTime"
  22. #define NETPROP_VIEWMODEL_LAYER "m_nLayer"
  23.  
  24. #define SHOVE_SOUND_NAME_SEARCH "Swish"
  25. #define SHOVE_DURATION 0.4
  26.  
  27. new bool:g_InReload[MAXPLAYERS + 1]
  28.  
  29. public OnPluginStart()
  30. {
  31.     HookEvent("weapon_reload", WeaponReload_Event)
  32.     AddNormalSoundHook(ShoveSoundHook)
  33. }
  34.  
  35. public OnClientDisconnect(client)
  36. {
  37.     g_InReload[client] = false
  38. }
  39.  
  40. public Action:ShoveSoundHook(clients[64], &numClients, String:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
  41. {
  42.     if (entity <= 0 || entity > MaxClients || !g_InReload[entity])
  43.     {
  44.         return Plugin_Continue
  45.     }
  46.    
  47.     if (StrContains(sample, SHOVE_SOUND_NAME_SEARCH) == -1)
  48.     {
  49.         return Plugin_Continue
  50.     }
  51.    
  52.     new activeWeapon = GetEntPropEnt(entity, Prop_Send, NETPROP_PLAYER_ACTIVEWEAPON)
  53.     if (activeWeapon <= 0 || activeWeapon > MAXENTITIES)
  54.     {
  55.         g_InReload[entity] = false
  56.         return Plugin_Continue
  57.     }
  58.    
  59.     new L4D2WeaponId:weaponId = L4D2_GetWeaponId(activeWeapon)
  60.    
  61.     if (!IsReloadableWeapon(weaponId))
  62.     {
  63.         g_InReload[entity] = false
  64.         return Plugin_Continue
  65.     }
  66.    
  67.     new bool:isShotgun = IsWeaponAShotgun(weaponId)
  68.    
  69.     if (GetEntProp(activeWeapon, Prop_Send, NETPROP_WEAPON_INRELOAD) == 0)
  70.     {
  71.         g_InReload[entity] = false
  72.         return Plugin_Continue
  73.     }
  74.    
  75.     g_InReload[entity] = false
  76.     SetEntProp(activeWeapon, Prop_Send, NETPROP_WEAPON_INRELOAD, 0)
  77.     ChangeEdictState(activeWeapon, FindDataMapInfo(activeWeapon, NETPROP_WEAPON_INRELOAD))
  78.     SetPlayerNextPrimaryAttack(entity, GetGameTime() + SHOVE_DURATION)
  79.    
  80.     if (isShotgun)
  81.     {
  82.         SetEntProp(activeWeapon, Prop_Send, NETPROP_WEAPON_SHOTGUN_RELOADSTATE, 0)
  83.         SetEntProp(activeWeapon, Prop_Send, NETPROP_WEAPON_SHOTGUN_RELOADANIMSTATE, 0)
  84.         SetEntProp(activeWeapon, Prop_Send, NETPROP_WEAPON_SHOTGUN_RELOADNUMSHELLS, 0)
  85.         SetEntProp(activeWeapon, Prop_Send, NETPROP_WEAPON_SHOTGUN_SHELLSINSERTED, 0)
  86.     }
  87.    
  88.     new viewModel = GetEntPropEnt(entity, Prop_Send, NETPROP_PLAYER_VIEWMODEL)
  89.    
  90.     if (viewModel > 0 && viewModel <= MAXENTITIES && IsValidEntity(viewModel))
  91.     {
  92.         SetEntProp(viewModel, Prop_Send, NETPROP_VIEWMODEL_LAYER, 0)
  93.     }
  94.  
  95.     return Plugin_Continue
  96. }
  97.  
  98. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seed, mouse[2])
  99. {
  100.     if (!g_InReload[client])
  101.     {
  102.         return Plugin_Continue
  103.     }
  104.    
  105.     new activeWeapon = GetEntPropEnt(client, Prop_Send, NETPROP_PLAYER_ACTIVEWEAPON)
  106.     if (activeWeapon <= 0 || activeWeapon > MAXENTITIES)
  107.     {
  108.         g_InReload[client] = false
  109.         return Plugin_Continue
  110.     }
  111.    
  112.     new L4D2WeaponId:weaponId = L4D2_GetWeaponId(activeWeapon)
  113.    
  114.     if (!IsReloadableWeapon(weaponId))
  115.     {
  116.         g_InReload[client] = false
  117.         return Plugin_Continue
  118.     }
  119.    
  120.     if (GetEntProp(activeWeapon, Prop_Send, NETPROP_WEAPON_INRELOAD) == 0)
  121.     {
  122.         g_InReload[client] = false
  123.         return Plugin_Continue
  124.     }
  125.    
  126.     if (weapon > 0)
  127.     {
  128.         g_InReload[client] = false
  129.         return Plugin_Continue
  130.     }
  131.    
  132.     return Plugin_Continue
  133. }
  134.  
  135. public WeaponReload_Event(Handle:event, const String:name[], bool:dontBroadcast)
  136. {
  137.     new client = GetClientOfUserId(GetEventInt(event, "userid"))
  138.    
  139.     if (client <= 0 || client > MaxClients || !IsClientInGame(client))
  140.     {
  141.         return
  142.     }
  143.    
  144.     new weapon = GetEntPropEnt(client, Prop_Send, NETPROP_PLAYER_ACTIVEWEAPON)
  145.    
  146.     if (weapon <= 0 || weapon > MAXENTITIES || !IsValidEntity(weapon))
  147.     {
  148.         return
  149.     }
  150.    
  151.     new L4D2WeaponId:weaponId = L4D2_GetWeaponId(weapon)
  152.    
  153.     if (!IsReloadableWeapon(weaponId))
  154.     {
  155.         return
  156.     }
  157.    
  158.     g_InReload[client] = true
  159. }
  160.  
  161. stock SetPlayerNextPrimaryAttack(client, Float:time)
  162. {
  163.     new weapon = GetEntPropEnt(client, Prop_Send, NETPROP_PLAYER_ACTIVEWEAPON)
  164.    
  165.     if (weapon <= 0 || weapon > MAXENTITIES || !IsValidEntity(weapon))
  166.     {
  167.         return
  168.     }
  169.    
  170.     SetEntPropFloat(weapon, Prop_Send, NETPROP_WEAPON_NEXTPRIMARYATTACK, time)
  171.     SetEntPropFloat(weapon, Prop_Send, NETPROP_WEAPON_TIMEWEAPONIDLE, time)
  172.     SetEntPropFloat(client, Prop_Send, NETPROP_PLAYER_NEXTATTACK, time)
  173. }
  174.  
  175. bool:IsReloadableWeapon(L4D2WeaponId:weaponId)
  176. {
  177.     if (weaponId == L4D2WeaponId_Pistol ||
  178.         weaponId == L4D2WeaponId_Smg ||
  179.         weaponId == L4D2WeaponId_Pumpshotgun ||
  180.         weaponId == L4D2WeaponId_Autoshotgun ||
  181.         weaponId == L4D2WeaponId_Rifle ||
  182.         weaponId == L4D2WeaponId_HuntingRifle ||
  183.         weaponId == L4D2WeaponId_SmgSilenced ||
  184.         weaponId == L4D2WeaponId_ShotgunChrome ||
  185.         weaponId == L4D2WeaponId_RifleDesert ||
  186.         weaponId == L4D2WeaponId_SniperMilitary ||
  187.         weaponId == L4D2WeaponId_ShotgunSpas ||
  188.         weaponId == L4D2WeaponId_GrenadeLauncher ||
  189.         weaponId == L4D2WeaponId_RifleAK47 ||
  190.         weaponId == L4D2WeaponId_PistolMagnum ||
  191.         weaponId == L4D2WeaponId_SmgMP5 ||
  192.         weaponId == L4D2WeaponId_RifleSG552 ||
  193.         weaponId == L4D2WeaponId_SniperAWP ||
  194.         weaponId == L4D2WeaponId_SniperScout)
  195.     {
  196.         return true
  197.     }
  198.    
  199.     return false
  200. }
  201.  
  202. bool:IsWeaponAShotgun(L4D2WeaponId:weaponId)
  203. {
  204.     if (weaponId == L4D2WeaponId_Pumpshotgun ||
  205.         weaponId == L4D2WeaponId_Autoshotgun ||
  206.         weaponId == L4D2WeaponId_ShotgunChrome ||
  207.         weaponId == L4D2WeaponId_ShotgunSpas)
  208.     {
  209.         return true
  210.     }
  211.    
  212.     return false
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement