FlacoBey

Untitled

Feb 16th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.77 KB | None | 0 0
  1. #pragma semicolon 1
  2. #include <sourcemod>
  3. #include <sdktools>
  4.  
  5. #define PLUGIN_VERSION "0.0.1"
  6. #define DEFAULT_FLAGS FCVAR_PLUGIN|FCVAR_NOTIFY
  7. #undef REQUIRE_EXTENSIONS
  8. #define WEAPON_LENGTH 19
  9. #define DEBUG 0
  10. new m_debug = 0;
  11.  
  12. static const    ASSAULT_RIFLE_OFFSET_IAMMO      = 12;
  13. static const    SMG_OFFSET_IAMMO                = 20;
  14. static const    PUMPSHOTGUN_OFFSET_IAMMO        = 28;
  15. static const    AUTO_SHOTGUN_OFFSET_IAMMO       = 32;
  16. static const    HUNTING_RIFLE_OFFSET_IAMMO      = 36;
  17. static const    MILITARY_SNIPER_OFFSET_IAMMO    = 40;
  18. static const    GRENADE_LAUNCHER_OFFSET_IAMMO   = 68;
  19.  
  20. new Handle:smgClip;
  21. new Handle:smgSilencedClip;
  22. new Handle:smgMp5Clip;
  23. new Handle:pumpClip;
  24. new Handle:chromeClip;
  25. new Handle:huntClip;
  26. new Handle:rifleClip;
  27. new Handle:rifleAk47Clip;
  28. new Handle:rifleDesertClip;
  29. new Handle:rifleSg552Clip;
  30. new Handle:militaryClip;
  31. new Handle:awpClip;
  32. new Handle:scoutClip;
  33. new Handle:granedeClip;
  34. new Handle:m60Clip;
  35. new Handle:autoClip;
  36. new Handle:spasClip;
  37. new Handle:pistolClip;
  38. new Handle:magnumClip;
  39. //faster reload
  40. new Handle:g_h_reload_rate;
  41. new Float:g_fl_reload_rate;
  42. new g_iNextPAttO        = -1;
  43. new g_iActiveWO         = -1;
  44. new g_iPlayRateO        = -1;
  45. new g_iNextAttO         = -1;
  46. new g_iTimeIdleO        = -1;
  47. new g_iVMStartTimeO     = -1;
  48. new g_iViewModelO       = -1;
  49. //new CountTimer = 1;
  50. new ValueLastClip[MAXPLAYERS+1];
  51. new ValueLastAmmo[MAXPLAYERS+1];
  52. new ValueNewClip[MAXPLAYERS+1];
  53. new ClipOffset[MAXPLAYERS+1];
  54. new Handle:TimerPlayerReload[MAXPLAYERS+1];
  55. new weaponClipSize[WEAPON_LENGTH] = {};
  56. /*
  57. new nextPrimaryAttack = -1;
  58. new nextAttack =  -1;
  59. new timeIdle =  -1;
  60. new reloadState =  -1;
  61. */
  62.  
  63. new const String:weaponsClass[WEAPON_LENGTH][] = {
  64.     {"weapon_smg"}, {"weapon_smg_silenced"}, {"weapon_smg_mp5"}, {"weapon_pumpshotgun"}, {"weapon_shotgun_chrome"}, {"weapon_hunting_rifle"},
  65.     {"weapon_rifle"}, {"weapon_rifle_ak47"}, {"weapon_rifle_desert"}, {"weapon_rifle_sg552"}, {"weapon_sniper_military"},
  66.     {"weapon_sniper_scout"}, {"weapon_sniper_awp"}, {"weapon_grenade_launcher"}, {"weapon_rifle_m60"},
  67.     {"weapon_autoshotgun"}, {"weapon_shotgun_spas"}, {"weapon_pistol"}, {"weapon_pistol_magnum"}
  68. };
  69.  
  70. public Plugin:myinfo =
  71. {
  72.     name = "L4D2 Realistic Reload",
  73.     author = "ghosthunterfool",
  74.     description = "Realistic Reloading",
  75.     version = PLUGIN_VERSION,
  76.     url = "http://forums.alliedmods.net/showthread.php?p=1020236"
  77. }
  78.  
  79. public OnPluginStart()
  80. {
  81.     // Requires Left 4 Dead 2
  82.     decl String:game_name[64];
  83.     GetGameFolderName(game_name, sizeof(game_name));
  84.     if (!StrEqual(game_name, "left4dead2", false))
  85.         SetFailState("Plugin supports Left 4 Dead 2 only.");
  86.    
  87.     CreateConVar("l4d2_gun_version", PLUGIN_VERSION, " Version of L4D2 Gun Control on this server ", DEFAULT_FLAGS|FCVAR_SPONLY|FCVAR_DONTRECORD);
  88.     smgClip = CreateConVar("l4d2_smg_clip", "32", "Max clip size", DEFAULT_FLAGS);
  89.     smgSilencedClip = CreateConVar("l4d2_smg_silenced_clip", "25", "Max clip size", DEFAULT_FLAGS);
  90.     smgMp5Clip = CreateConVar("l4d2_smg_mp5_clip", "30", "Max clip size", DEFAULT_FLAGS);
  91.     pumpClip = CreateConVar("l4d2_pump_shotie_clip", "5", "Max clip size", DEFAULT_FLAGS);
  92.     chromeClip = CreateConVar("l4d2_chrome_clip", "5", "Max clip size", DEFAULT_FLAGS);
  93.     huntClip = CreateConVar("l4d2_hunting_clip", "10", "Max clip size", DEFAULT_FLAGS);
  94.     rifleClip = CreateConVar("l4d2_rifle_clip", "30", "Max clip size", DEFAULT_FLAGS);
  95.     rifleAk47Clip = CreateConVar("l4d2_ak47_clip", "30", "Max clip size", DEFAULT_FLAGS);
  96.     rifleDesertClip = CreateConVar("l4d2_desert_clip", "30", "Max clip size", DEFAULT_FLAGS);
  97.     rifleSg552Clip = CreateConVar("l4d2_sg552_clip", "30", "Max clip size", DEFAULT_FLAGS);
  98.     militaryClip = CreateConVar("l4d2_military_clip", "20", "Max clip size", DEFAULT_FLAGS);
  99.     awpClip = CreateConVar("l4d2_awp_clip", "10", "Max clip size", DEFAULT_FLAGS);
  100.     scoutClip = CreateConVar("l4d2_scout_clip", "10", "Max clip size", DEFAULT_FLAGS);
  101.     granedeClip = CreateConVar("l4d2_granede_clip", "1", "Max clip size", DEFAULT_FLAGS);
  102.     m60Clip = CreateConVar("l4d2_m60_clip", "200", "Max clip size", DEFAULT_FLAGS);
  103.     autoClip = CreateConVar("l4d2_autoshot_clip", "5", "Max clip size", DEFAULT_FLAGS);
  104.     spasClip = CreateConVar("l4d2_spas_clip", "7", "Max clip size", DEFAULT_FLAGS);
  105.     pistolClip = CreateConVar("l4d2_pistol_clip", "15", "Max clip size", DEFAULT_FLAGS);
  106.     magnumClip = CreateConVar("l4d2_magnum_clip", "8", "Max clip size", DEFAULT_FLAGS);
  107.     g_h_reload_rate = CreateConVar(
  108.         "l4d_powerups_weaponreload_rate",
  109.         "0.8",
  110.         "The interval incurred by reloading is multiplied by this value (clamped between 0.2 < 0.9)",
  111.         FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.2, true, 0.9);
  112.     HookConVarChange(g_h_reload_rate, Convar_Reload);
  113.     g_fl_reload_rate = 0.8;
  114.    
  115.    
  116.     g_iPlayRateO        =   FindSendPropInfo("CBaseCombatWeapon","m_flPlaybackRate");
  117.     g_iTimeIdleO        =   FindSendPropInfo("CTerrorGun","m_flTimeWeaponIdle");
  118.     g_iNextAttO         =   FindSendPropInfo("CTerrorPlayer","m_flNextAttack");
  119.     g_iNextPAttO        =   FindSendPropInfo("CBaseCombatWeapon","m_flNextPrimaryAttack");
  120.     g_iVMStartTimeO     =   FindSendPropInfo("CTerrorViewModel","m_flLayerStartTime");
  121.     g_iViewModelO       =   FindSendPropInfo("CTerrorPlayer","m_hViewModel");
  122.     g_iActiveWO         =   FindSendPropInfo("CBaseCombatCharacter","m_hActiveWeapon");
  123.    
  124.     HookEvent("weapon_fire", Event_Weapon_Fired);
  125.     HookEvent("item_pickup", Event_Weapon_Pickup);
  126.     HookEvent("weapon_reload", Event_Weapon_Reload,  EventHookMode_Pre);
  127.     HookEvent("ammo_pickup", Event_AmmoPickUp);
  128.    
  129.     AutoExecConfig(true, "l4d2_gun");
  130. }
  131.  
  132. public OnMapStart()
  133. {
  134.     for(new i=1; i <= MaxClients; i++)
  135.     {
  136.         ValueLastClip[i] = 0;
  137.         ValueLastAmmo[i] = 0;
  138.         ValueNewClip[i] = 0;
  139.         ClipOffset[i] = 0;
  140.         TimerPlayerReload[i] = INVALID_HANDLE;
  141.     }
  142. }
  143.  
  144. public Convar_Reload (Handle:convar, const String:oldValue[], const String:newValue[])
  145. {
  146.     new Float:flF=StringToFloat(newValue);
  147.     if (flF<0.02)
  148.         flF=0.02;
  149.     else if (flF>0.9)
  150.         flF=0.9;
  151.     g_fl_reload_rate = flF;
  152. }
  153.  
  154. public Action:Event_Weapon_Fired(Handle:event, const String:name[], bool:dontBroadcast)
  155. {
  156.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  157.     //new h_mPrimary = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
  158.     new h_mPrimary = GetPlayerWeaponSlot(client, 0);
  159.     if(!IsValidEntity(h_mPrimary) || IsFakeClient(client)) return Plugin_Handled;
  160.    
  161.     new String:classname[256];
  162.     GetEntityClassname(h_mPrimary, classname, sizeof(classname));
  163.     if((StrContains(classname, "weapon_smg", false) != -1) ||
  164.     (StrContains(classname, "weapon_smg_silenced", false) != -1) ||
  165.     (StrContains(classname, "weapon_smg_mp5", false) != -1))
  166.     {
  167.         ClipOffset[client] = SMG_OFFSET_IAMMO;
  168.        
  169.     }
  170.     else if((StrContains(classname, "weapon_pumpshotgun", false) != -1) ||
  171.     (StrContains(classname, "weapon_shotgun_chrome", false) != -1))
  172.     {
  173.         ClipOffset[client] = PUMPSHOTGUN_OFFSET_IAMMO;
  174.     }
  175.     else if((StrContains(classname, "weapon_rifle", false) != -1) ||
  176.     (StrContains(classname, "weapon_rifle_ak47", false) != -1) ||
  177.     (StrContains(classname, "weapon_rifle_desert", false) != -1) ||
  178.     (StrContains(classname, "weapon_rifle_sg552", false) != -1)
  179.     )
  180.     {
  181.         ClipOffset[client] = ASSAULT_RIFLE_OFFSET_IAMMO;
  182.     }
  183.     else if((StrContains(classname, "weapon_autoshotgun", false) != -1) ||
  184.     (StrContains(classname, "weapon_shotgun_spas", false) != -1))
  185.     {
  186.         ClipOffset[client] = AUTO_SHOTGUN_OFFSET_IAMMO;
  187.     }
  188.     else if(StrContains(classname, "weapon_hunting_rifle", false) != -1)
  189.     {
  190.         ClipOffset[client] = HUNTING_RIFLE_OFFSET_IAMMO;
  191.     }
  192.     else if((StrContains(classname, "weapon_sniper_military", false) != -1) ||
  193.     (StrContains(classname, "weapon_sniper_scout", false) != -1) ||
  194.     (StrContains(classname, "weapon_sniper_awp", false) != -1))
  195.     {
  196.         ClipOffset[client] = MILITARY_SNIPER_OFFSET_IAMMO;
  197.     }
  198.     else if(StrContains(classname, "weapon_grenade_launcher", false) != -1)
  199.     {
  200.         ClipOffset[client] = GRENADE_LAUNCHER_OFFSET_IAMMO;
  201.     }
  202.    
  203.     new iAmmoOffset = FindDataMapOffs(client, "m_iAmmo");
  204.     ValueLastAmmo[client] = GetEntData(client, (iAmmoOffset + ClipOffset[client]));
  205.     ValueLastClip[client] = GetEntProp(h_mPrimary, Prop_Data, "m_iClip1", 1);
  206.     ValueLastClip[client] = ValueLastClip[client] - 1;
  207.  
  208.     if(m_debug == 1)
  209.     {
  210.         PrintToChatAll("Event Weapon Fired");
  211.         PrintToChatAll("ValueLastAmmo: %d", ValueLastAmmo[client]);
  212.         PrintToChatAll("ValueLastClip: %d", ValueLastClip[client]);
  213.         PrintToChatAll("---------------------------");
  214.     }
  215.     return Plugin_Handled;
  216. }
  217.  
  218. public Action:Event_AmmoPickUp(Handle:event, const String:name[], bool:dontBroadcast)
  219. {
  220.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  221.     //new h_mPrimary = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
  222.     new h_mPrimary = GetPlayerWeaponSlot(client, 0);
  223.     if(!IsValidEntity(h_mPrimary) || IsFakeClient(client)) return Plugin_Handled;
  224.    
  225.     new String:classname[256];
  226.     GetEntityClassname(h_mPrimary, classname, sizeof(classname));
  227.     if((StrContains(classname, "weapon_smg", false) != -1) ||
  228.     (StrContains(classname, "weapon_smg_silenced", false) != -1) ||
  229.     (StrContains(classname, "weapon_smg_mp5", false) != -1))
  230.     {
  231.         ClipOffset[client] = SMG_OFFSET_IAMMO;
  232.     }
  233.     else if((StrContains(classname, "weapon_pumpshotgun", false) != -1) ||
  234.     (StrContains(classname, "weapon_shotgun_chrome", false) != -1))
  235.     {
  236.         ClipOffset[client] = PUMPSHOTGUN_OFFSET_IAMMO;
  237.     }
  238.     else if((StrContains(classname, "weapon_rifle", false) != -1) ||
  239.     (StrContains(classname, "weapon_rifle_ak47", false) != -1) ||
  240.     (StrContains(classname, "weapon_rifle_desert", false) != -1) ||
  241.     (StrContains(classname, "weapon_rifle_sg552", false) != -1)
  242.     )
  243.     {
  244.         ClipOffset[client] = ASSAULT_RIFLE_OFFSET_IAMMO;
  245.     }
  246.     else if((StrContains(classname, "weapon_autoshotgun", false) != -1) ||
  247.     (StrContains(classname, "weapon_shotgun_spas", false) != -1))
  248.     {
  249.         ClipOffset[client] = AUTO_SHOTGUN_OFFSET_IAMMO;
  250.     }
  251.     else if(StrContains(classname, "weapon_hunting_rifle", false) != -1)
  252.     {
  253.         ClipOffset[client] = HUNTING_RIFLE_OFFSET_IAMMO;
  254.     }
  255.     else if((StrContains(classname, "weapon_sniper_military", false) != -1) ||
  256.     (StrContains(classname, "weapon_sniper_scout", false) != -1) ||
  257.     (StrContains(classname, "weapon_sniper_awp", false) != -1))
  258.     {
  259.         ClipOffset[client] = MILITARY_SNIPER_OFFSET_IAMMO;
  260.     }
  261.     else if(StrContains(classname, "weapon_grenade_launcher", false) != -1)
  262.     {
  263.         ClipOffset[client] = GRENADE_LAUNCHER_OFFSET_IAMMO;
  264.     }
  265.    
  266.     new iAmmoOffset = FindDataMapOffs(client, "m_iAmmo");
  267.     ValueLastAmmo[client] = GetEntData(client, (iAmmoOffset + ClipOffset[client]));
  268.  
  269.     if(m_debug == 1) PrintToChatAll("Event Ammo Pickup");
  270.     return Plugin_Handled;
  271. }
  272.  
  273. public Action:Event_Weapon_Pickup(Handle:event, const String:name[], bool:dontBroadcast)
  274. {
  275.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  276.     //new h_mPrimary = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
  277.     new h_mPrimary = GetPlayerWeaponSlot(client, 0);
  278.     if(!IsValidEntity(h_mPrimary) || IsFakeClient(client)) return Plugin_Handled;
  279.    
  280.     new String:classname[256];
  281.     GetEntityClassname(h_mPrimary, classname, sizeof(classname));
  282.     if((StrContains(classname, "weapon_smg", false) != -1) ||
  283.     (StrContains(classname, "weapon_smg_silenced", false) != -1) ||
  284.     (StrContains(classname, "weapon_smg_mp5", false) != -1))
  285.     {
  286.         ClipOffset[client] = SMG_OFFSET_IAMMO;
  287.     }
  288.     else if((StrContains(classname, "weapon_pumpshotgun", false) != -1) ||
  289.     (StrContains(classname, "weapon_shotgun_chrome", false) != -1))
  290.     {
  291.         ClipOffset[client] = PUMPSHOTGUN_OFFSET_IAMMO;
  292.     }
  293.     else if((StrContains(classname, "weapon_rifle", false) != -1) ||
  294.     (StrContains(classname, "weapon_rifle_ak47", false) != -1) ||
  295.     (StrContains(classname, "weapon_rifle_desert", false) != -1) ||
  296.     (StrContains(classname, "weapon_rifle_sg552", false) != -1)
  297.     )
  298.     {
  299.         ClipOffset[client] = ASSAULT_RIFLE_OFFSET_IAMMO;
  300.     }
  301.     else if((StrContains(classname, "weapon_autoshotgun", false) != -1) ||
  302.     (StrContains(classname, "weapon_shotgun_spas", false) != -1))
  303.     {
  304.         ClipOffset[client] = AUTO_SHOTGUN_OFFSET_IAMMO;
  305.     }
  306.     else if(StrContains(classname, "weapon_hunting_rifle", false) != -1)
  307.     {
  308.         ClipOffset[client] = HUNTING_RIFLE_OFFSET_IAMMO;
  309.     }
  310.     else if((StrContains(classname, "weapon_sniper_military", false) != -1) ||
  311.     (StrContains(classname, "weapon_sniper_scout", false) != -1) ||
  312.     (StrContains(classname, "weapon_sniper_awp", false) != -1))
  313.     {
  314.         ClipOffset[client] = MILITARY_SNIPER_OFFSET_IAMMO;
  315.     }
  316.     else if(StrContains(classname, "weapon_grenade_launcher", false) != -1)
  317.     {
  318.         ClipOffset[client] = GRENADE_LAUNCHER_OFFSET_IAMMO;
  319.     }
  320.    
  321.     new iAmmoOffset = FindDataMapOffs(client, "m_iAmmo");
  322.     ValueLastAmmo[client] = GetEntData(client, (iAmmoOffset + ClipOffset[client]));
  323.     ValueLastClip[client] = GetEntProp(h_mPrimary, Prop_Data, "m_iClip1", 1);
  324.  
  325.     if(m_debug == 1)
  326.     {
  327.         PrintToChatAll("Event weapon pickup");
  328.         PrintToChatAll("ValueLastAmmo: %d", ValueLastAmmo[client]);
  329.         PrintToChatAll("ValueLastClip: %d", ValueLastClip[client]);
  330.         PrintToChatAll("---------------------------");
  331.     }
  332.     return Plugin_Handled;
  333. }
  334.  
  335. public Action:Event_Weapon_Reload(Handle:event, const String:name[], bool:dontBroadcast)
  336. {
  337.     updateConVar();
  338.    
  339.     new String:classname[256];
  340.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  341.     //new ActiveWeapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
  342.     new ActiveWeapon = GetPlayerWeaponSlot(client, 0);
  343.     new iAmmoOffset = FindDataMapOffs(client, "m_iAmmo");
  344.  
  345.     GetEntityClassname(ActiveWeapon, classname, sizeof(classname));
  346.     for(new i=0; i < sizeof(weaponsClass); i++)
  347.     {
  348.         if((StrContains(classname, weaponsClass[i], false) != -1))
  349.         {
  350.             ValueNewClip[client] = weaponClipSize[i];
  351.             if(m_debug == 1)
  352.             {
  353.                 PrintToChatAll( "---------------------------");
  354.                 PrintToChatAll("what weapon we reloading");
  355.                 PrintToChatAll("clipSet: %s", weaponsClass[i]);
  356.                 PrintToChatAll("clipSet: %d", weaponClipSize[i]);
  357.                 PrintToChatAll("---------------------------");
  358.             }
  359.         }
  360.     }
  361.  
  362.    
  363.     // what is our clip offset
  364.     if((StrContains(classname, "weapon_smg", false) != -1) ||
  365.     (StrContains(classname, "weapon_smg_silenced", false) != -1) ||
  366.     (StrContains(classname, "weapon_smg_mp5", false) != -1))
  367.     {
  368.         ClipOffset[client] = SMG_OFFSET_IAMMO; 
  369.     }
  370.     else if((StrContains(classname, "weapon_pumpshotgun", false) != -1) ||
  371.     (StrContains(classname, "weapon_shotgun_chrome", false) != -1))
  372.     {
  373.         ClipOffset[client] = PUMPSHOTGUN_OFFSET_IAMMO;
  374.        
  375.     }
  376.     else if((StrContains(classname, "weapon_rifle", false) != -1) ||
  377.     (StrContains(classname, "weapon_rifle_ak47", false) != -1) ||
  378.     (StrContains(classname, "weapon_rifle_desert", false) != -1) ||
  379.     (StrContains(classname, "weapon_rifle_sg552", false) != -1)
  380.     )
  381.     {
  382.         ClipOffset[client] = ASSAULT_RIFLE_OFFSET_IAMMO;
  383.        
  384.     }
  385.     else if((StrContains(classname, "weapon_autoshotgun", false) != -1) ||
  386.     (StrContains(classname, "weapon_shotgun_spas", false) != -1))
  387.     {
  388.         ClipOffset[client] = AUTO_SHOTGUN_OFFSET_IAMMO;
  389.     }
  390.     else if(StrContains(classname, "weapon_hunting_rifle", false) != -1)
  391.     {
  392.         ClipOffset[client] = HUNTING_RIFLE_OFFSET_IAMMO;
  393.        
  394.     }
  395.     else if((StrContains(classname, "weapon_sniper_military", false) != -1) ||
  396.     (StrContains(classname, "weapon_sniper_scout", false) != -1) ||
  397.     (StrContains(classname, "weapon_sniper_awp", false) != -1))
  398.     {
  399.         ClipOffset[client] = MILITARY_SNIPER_OFFSET_IAMMO;
  400.        
  401.     }
  402.     else if(StrContains(classname, "weapon_grenade_launcher", false) != -1)
  403.     {
  404.         ClipOffset[client] = GRENADE_LAUNCHER_OFFSET_IAMMO;
  405.     }
  406.  
  407.     // we have zero stock ammo but we just pick from the ammo pile
  408.     if(ValueLastAmmo[client] <= 0) ValueLastAmmo[client] = GetEntData(client, (iAmmoOffset + ClipOffset[client]));
  409.    
  410.    
  411.     if((ValueLastClip[client] < ValueNewClip[client]))
  412.     {
  413.        
  414.         TimerPlayerReload[client] = CreateTimer(0.1, Timer_InsertClip, client, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  415.         if(ValueLastClip[client]>=1){
  416.             AdrenReload(client);
  417.         }
  418.     }
  419.     return Plugin_Continue;
  420. }
  421. public Action:Timer_InsertClip(Handle:timer, any:client)
  422. {
  423.     //new ActiveWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  424.     new ActiveWeapon = GetPlayerWeaponSlot(client, 0);
  425.    
  426.     if((GetEntProp(ActiveWeapon, Prop_Data, "m_bInReload") == 0))
  427.     {
  428.         KillTimer(TimerPlayerReload[client]);
  429.  
  430.         new clipSet = ValueNewClip[client];
  431.        
  432.         // total clip to subtract from our total stock ammo
  433.         new clip =  (clipSet - ValueLastClip[client]);
  434.        
  435.         new clip2 = (ValueLastAmmo[client] + ValueLastClip[client]);
  436.        
  437.         // incase we run low on stock ammo
  438.         //
  439.        
  440.         // balance of our ammo
  441.         new ammo = (ValueLastAmmo[client] - clip);
  442.        
  443.         // not sure why i need this but i still put him here xD
  444.         if(ammo <= 0) ammo = 0;
  445.        
  446.        
  447.        
  448.         if(m_debug == 1)
  449.         {
  450.             PrintToChatAll("clipSet: %i", clipSet);
  451.             PrintToChatAll("clip: %i", clip);
  452.             PrintToChatAll("clip2: %i", clip2);
  453.             PrintToChatAll("ammo: %i", ammo);
  454.         }
  455.         //if(ValueLastClip[client]>=1 && ActiveWeapon == GetPlayerWeaponSlot(client, 1)){
  456.         //  SetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1", clipSet+1);
  457.         //}
  458.         if(ValueLastClip[client]>=1 && ActiveWeapon == GetPlayerWeaponSlot(client, 0) && (ClipOffset[client] == SMG_OFFSET_IAMMO || ClipOffset[client] == ASSAULT_RIFLE_OFFSET_IAMMO
  459.         || ClipOffset[client] == HUNTING_RIFLE_OFFSET_IAMMO || ClipOffset[client] == MILITARY_SNIPER_OFFSET_IAMMO))
  460.         {
  461.             if(clip2 < clipSet) clipSet = clip2;
  462.             new iAmmoOffset = FindDataMapOffs(client, "m_iAmmo");
  463.             //SetEntData(client, (iAmmoOffset + ClipOffset[client]), ammo);
  464.             //SetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_iClip1", clipSet);
  465.             SetEntData(client, (iAmmoOffset + ClipOffset[client]), ammo-1);
  466.             SetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_iClip1", clipSet+1);
  467.         }
  468.         if(m_debug == 1)
  469.         {
  470.             PrintToChatAll("ValueLastClip[client]: %d", ValueLastClip[client]);
  471.             //PrintToChatAll("Count stoped at: %i", CountTimer);
  472.         }
  473.        
  474.        
  475.         return;
  476.     }
  477.  
  478.  
  479. }
  480.  
  481.  
  482. updateConVar()
  483. {
  484.     weaponClipSize[0] = GetConVarInt(smgClip);
  485.     weaponClipSize[1] = GetConVarInt(smgSilencedClip);
  486.     weaponClipSize[2] = GetConVarInt(smgMp5Clip);
  487.     weaponClipSize[3] = GetConVarInt(pumpClip);
  488.     weaponClipSize[4] = GetConVarInt(chromeClip);
  489.     weaponClipSize[5] = GetConVarInt(huntClip);
  490.     weaponClipSize[6] = GetConVarInt(rifleClip);
  491.     weaponClipSize[7] = GetConVarInt(rifleAk47Clip);
  492.     weaponClipSize[8] = GetConVarInt(rifleDesertClip);
  493.     weaponClipSize[9] = GetConVarInt(rifleSg552Clip);
  494.     weaponClipSize[10] = GetConVarInt(militaryClip);
  495.     weaponClipSize[11] = GetConVarInt(scoutClip);
  496.     weaponClipSize[12] = GetConVarInt(awpClip);
  497.     weaponClipSize[13] = GetConVarInt(granedeClip);
  498.     weaponClipSize[14] = GetConVarInt(m60Clip);
  499.     weaponClipSize[15] = GetConVarInt(autoClip);
  500.     weaponClipSize[16] = GetConVarInt(spasClip);
  501.     weaponClipSize[17] = GetConVarInt(magnumClip);
  502.     weaponClipSize[18] = GetConVarInt(pistolClip);
  503. }
  504. // ////////////////////////////////////////////////////////////////////////////
  505. //On the start of a reload
  506. AdrenReload (client)
  507. {
  508.     if (GetClientTeam(client) == 2)
  509.     {
  510.         #if DEBUG
  511.         PrintToChatAll("\x03Client \x01%i\x03; start of reload detected",client );
  512.         #endif
  513.         new iEntid = GetEntDataEnt2(client, g_iActiveWO);
  514.         if (IsValidEntity(iEntid)==false) return;
  515.    
  516.         decl String:stClass[32];
  517.         GetEntityNetClass(iEntid,stClass,32);
  518.         #if DEBUG
  519.         PrintToChatAll("\x03-class of gun: \x01%s",stClass );
  520.         #endif
  521.  
  522.         //for non-shotguns
  523.         if (StrContains(stClass,"shotgun",false) == -1)
  524.         {
  525.             MagStart(iEntid, client);
  526.             return;
  527.         }
  528.     }
  529. }
  530. // ////////////////////////////////////////////////////////////////////////////
  531. //called for mag loaders
  532. MagStart (iEntid, client)
  533. {
  534.     #if DEBUG
  535.     PrintToChatAll("\x05-magazine loader detected,\x03 gametime \x01%f", GetGameTime());
  536.     #endif
  537.     new Float:flGameTime = GetGameTime();
  538.     new Float:flNextTime_ret = GetEntDataFloat(iEntid,g_iNextPAttO);
  539.     #if DEBUG
  540.     PrintToChatAll("\x03- pre, gametime \x01%f\x03, retrieved nextattack\x01 %i %f\x03, retrieved time idle \x01%i %f",
  541.         flGameTime,
  542.         g_iNextAttO,
  543.         GetEntDataFloat(client,g_iNextAttO),
  544.         g_iTimeIdleO,
  545.         GetEntDataFloat(iEntid,g_iTimeIdleO)
  546.         );
  547.     #endif
  548.  
  549.     //this is a calculation of when the next primary attack will be after applying reload values
  550.     //NOTE: at this point, only calculate the interval itself, without the actual game engine time factored in
  551.     new Float:flNextTime_calc = ( flNextTime_ret - flGameTime ) * g_fl_reload_rate ;
  552.     //we change the playback rate of the gun, just so the player can "see" the gun reloading faster
  553.     SetEntDataFloat(iEntid, g_iPlayRateO, 1.0/g_fl_reload_rate, true);
  554.     //create a timer to reset the playrate after time equal to the modified attack interval
  555.     CreateTimer( flNextTime_calc, Timer_MagEnd, iEntid);
  556.     //experiment to remove double-playback bug
  557.     new Handle:hPack = CreateDataPack();
  558.     WritePackCell(hPack, client);
  559.     //this calculates the equivalent time for the reload to end
  560.     new Float:flStartTime_calc = flGameTime - ( flNextTime_ret - flGameTime ) * ( 1 - g_fl_reload_rate ) ;
  561.     WritePackFloat(hPack, flStartTime_calc);
  562.     //now we create the timer that will prevent the annoying double playback
  563.     if ( (flNextTime_calc - 0.4) > 0 )
  564.         CreateTimer( flNextTime_calc - 0.4 , Timer_MagEnd2, hPack);
  565.     //and finally we set the end reload time into the gun so the player can actually shoot with it at the end
  566.     flNextTime_calc += flGameTime;
  567.     SetEntDataFloat(iEntid, g_iTimeIdleO, flNextTime_calc, true);
  568.     SetEntDataFloat(iEntid, g_iNextPAttO, flNextTime_calc, true);
  569.     SetEntDataFloat(client, g_iNextAttO, flNextTime_calc, true);
  570.     #if DEBUG
  571.     PrintToChatAll("\x03- post, calculated nextattack \x01%f\x03, gametime \x01%f\x03, retrieved nextattack\x01 %i %f\x03, retrieved time idle \x01%i %f",
  572.         flNextTime_calc,
  573.         flGameTime,
  574.         g_iNextAttO,
  575.         GetEntDataFloat(client,g_iNextAttO),
  576.         g_iTimeIdleO,
  577.         GetEntDataFloat(iEntid,g_iTimeIdleO)
  578.         );
  579.     #endif
  580. }
  581.  
  582. // ////////////////////////////////////////////////////////////////////////////
  583. //this resets the playback rate on non-shotguns
  584. public Action:Timer_MagEnd (Handle:timer, any:iEntid)
  585. {
  586.     KillTimer(timer);
  587.     if (IsServerProcessing()==false)
  588.         return Plugin_Stop;
  589.  
  590.     #if DEBUG
  591.     PrintToChatAll("\x03Reset playback, magazine loader");
  592.     #endif
  593.  
  594.     if (iEntid <= 0
  595.         || IsValidEntity(iEntid)==false)
  596.         return Plugin_Stop;
  597.  
  598.     SetEntDataFloat(iEntid, g_iPlayRateO, 1.0, true);
  599.  
  600.     return Plugin_Stop;
  601. }
  602.  
  603. public Action:Timer_MagEnd2 (Handle:timer, Handle:hPack)
  604. {
  605.     KillTimer(timer);
  606.     if (IsServerProcessing()==false)
  607.     {
  608.         CloseHandle(hPack);
  609.         return Plugin_Stop;
  610.     }
  611.  
  612.     #if DEBUG
  613.     PrintToChatAll("\x03Reset playback, magazine loader");
  614.     #endif
  615.  
  616.     ResetPack(hPack);
  617.     new iCid = ReadPackCell(hPack);
  618.     new Float:flStartTime_calc = ReadPackFloat(hPack);
  619.     CloseHandle(hPack);
  620.  
  621.     if (iCid <= 0
  622.         || IsValidEntity(iCid)==false
  623.         || IsClientInGame(iCid)==false)
  624.         return Plugin_Stop;
  625.  
  626.     //experimental, remove annoying double-playback
  627.     new iVMid = GetEntDataEnt2(iCid,g_iViewModelO);
  628.     SetEntDataFloat(iVMid, g_iVMStartTimeO, flStartTime_calc, true);
  629.  
  630.     #if DEBUG
  631.     PrintToChatAll("\x03- end mag loader, icid \x01%i\x03 starttime \x01%f\x03 gametime \x01%f", iCid, flStartTime_calc, GetGameTime());
  632.     #endif
  633.  
  634.     return Plugin_Stop;
  635. }
Advertisement
Add Comment
Please, Sign In to add comment