SHARE
TWEET

Untitled

a guest Oct 10th, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma semicolon 1
  2. #pragma newdecls required
  3.  
  4. #include <sourcemod>
  5. #include <sdktools>
  6. #include <sdkhooks>
  7.  
  8. int g_iAmmo[2048 + 1][10];
  9.  
  10. static const int g_iAmmoLimits[] =
  11. {
  12.     210,
  13.     330,
  14.     332,
  15.     210,
  16.     50,
  17.     48,
  18.     125,
  19.     180,
  20.     48,
  21.     50,
  22.     90,
  23.     150,
  24.     100,
  25.     45,
  26.     210,
  27.     190,
  28.     8
  29. };
  30.  
  31. static const char gWeapons[][] =
  32. {
  33.     "weapon_rifle",
  34.     "weapon_smg_mp5",
  35.     "weapon_smg",
  36.     "weapon_smg_silenced",
  37.     "weapon_shotgun_chrome",
  38.     "weapon_pumpshotgun",
  39.     "weapon_hunting_rifle",
  40.     "weapon_rifle_m60",
  41.     "weapon_autoshotgun",
  42.     "weapon_shotgun_spas",
  43.     "weapon_sniper_military",
  44.     "weapon_rifle_ak47",
  45.     "weapon_rifle_desert",
  46.     "weapon_sniper_awp",
  47.     "weapon_rifle_sg552",
  48.     "weapon_sniper_scout",
  49.     "weapon_grenade_launcher"
  50. };
  51.  
  52. public void OnPluginStart()
  53. {
  54.     HookEvent("upgrade_pack_used", eEvent);
  55. }
  56.  
  57. public void eEvent(Event event, const char[] name, bool dontBroadcast)
  58. {
  59.     int client = GetClientOfUserId(event.GetInt("userid"));
  60.    
  61.     if (!client || !IsClientInGame(client))
  62.         return;
  63.    
  64.     int iEntity = event.GetInt("upgradeid");
  65.    
  66.     if (!IsValidEntity(iEntity))
  67.         return;
  68.    
  69.     float vOrigin[3], vAngles[3]; vAngles[0] = 89.0;
  70.     int iTarget;
  71.    
  72.     bool bSwitch;
  73.  
  74.     GetClientAbsOrigin(client,vOrigin);
  75.    
  76.     int iAmmo = CreateEntityByName("weapon_ammo_spawn");
  77.    
  78.     DispatchSpawn(iAmmo);
  79.     DispatchKeyValueVector(iAmmo, "origin", vOrigin);
  80.     AcceptEntityInput(iEntity, "kill");
  81.    
  82.     g_iAmmo[iAmmo][1] = 600;
  83.     g_iAmmo[iAmmo][2] = 360;
  84.     g_iAmmo[iAmmo][3] = 160;
  85.     g_iAmmo[iAmmo][4] = 80;
  86.     g_iAmmo[iAmmo][5] = 84;
  87.     g_iAmmo[iAmmo][6] = 84;
  88.     g_iAmmo[iAmmo][7] = 240;
  89.     g_iAmmo[iAmmo][8] = 16;
  90.     g_iAmmo[iAmmo][9] = 360;
  91.    
  92.     Handle hRayTrace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceFilter, iAmmo);
  93.    
  94.     if(TR_DidHit(hRayTrace))
  95.     {
  96.         TR_GetEndPosition(vOrigin, hRayTrace);
  97.         iTarget = TR_GetEntityIndex(hRayTrace);
  98.     }
  99.    
  100.     char szClass2[36];
  101.     GetEntityClassname(iTarget, szClass2, sizeof szClass2);
  102.     if (IsValidEntity(iTarget) && iTarget > MaxClients)
  103.     {
  104.         char szClass[36];
  105.         GetEntityClassname(iTarget, szClass, sizeof szClass);
  106.        
  107.         if (strcmp(szClass, "func_elevator") == 0 || strcmp(szClass, "func_tracktrain") == 0)
  108.             bSwitch = true;
  109.     }
  110.        
  111.     delete hRayTrace;
  112.    
  113.     if (bSwitch)
  114.     {
  115.         SetVariantString("!activator");
  116.         AcceptEntityInput(iAmmo, "SetParent", iTarget);
  117.     }
  118. }
  119.  
  120. public bool TraceFilter(int entity, int contentsMask, int iEntity)
  121. {
  122.     if (entity > MaxClients && entity != iEntity)
  123.         return true;
  124.     return false;
  125. }
  126.  
  127. public void OnEntityCreated(int entity, const char[] clsname)
  128. {
  129.     if (!IsValidEntity(entity) || strcmp(clsname, "weapon_ammo_spawn") != 0)
  130.         return;
  131.    
  132.     g_iAmmo[entity][1] = GetRandomInt(0, 600);
  133.     g_iAmmo[entity][2] = GetRandomInt(0, 360);
  134.     g_iAmmo[entity][3] = GetRandomInt(0, 160);
  135.     g_iAmmo[entity][4] = GetRandomInt(0, 80);
  136.     g_iAmmo[entity][5] = GetRandomInt(0, 84);
  137.     g_iAmmo[entity][6] = GetRandomInt(0, 84);
  138.     g_iAmmo[entity][7] = GetRandomInt(0, 240);
  139.     g_iAmmo[entity][8] = GetRandomInt(0, 16);
  140.     g_iAmmo[entity][9] = GetRandomInt(0, 360);
  141.     SDKHook(entity, SDKHook_Use, OnPlayerUse);
  142. }
  143.  
  144. public Action OnPlayerUse(int iTarget, int client, int caller, UseType type, float value)
  145. {
  146.     if (!client || !IsClientInGame(client))
  147.         return;
  148.    
  149.     if (!IsValidEntity(iTarget))
  150.         return;
  151.        
  152.     int iAmmoSave[2];
  153.     iSaveAmmo(client, iAmmoSave);
  154.    
  155.     char szBuffer[36];
  156.     GetEntityClassname(iTarget, szBuffer, sizeof szBuffer);
  157.    
  158.     if (strcmp(szBuffer, "weapon_ammo_spawn") != 0)
  159.         return;
  160.    
  161.     int iWeapon = GetPlayerWeaponSlot(client, 0);
  162.    
  163.     if (!IsValidEntity(iWeapon))
  164.         return;
  165.  
  166.     int iBits = iBitsWeapon(iWeapon);
  167.     int iMaxAmmo = iAmmoBits(iWeapon);
  168.     int iBitsType = GetEntProp(iWeapon, Prop_Data, "m_iPrimaryAmmoType");
  169.    
  170.     if (iBitsType == INVALID_ENT_REFERENCE || iBits <= 0)
  171.         return;
  172.    
  173.     if (iMaxAmmo == GetEntProp(iWeapon, Prop_Send, "m_iClip1") + GetEntProp(client, Prop_Send, "m_iAmmo", _, iBitsType))
  174.     {
  175.         PrintHintText(client, "Нельзя унести больше.");
  176.         return;
  177.     }
  178.    
  179.     if (g_iAmmo[iTarget][iBits] > 0)
  180.     {
  181.         int iResult = iMaxAmmo - (GetEntProp(iWeapon, Prop_Send, "m_iClip1") + GetEntProp(client, Prop_Send, "m_iAmmo", _, iBitsType));
  182.  
  183.         g_iAmmo[iTarget][iBits] -= iResult;
  184.         int iTotal = GetEntProp(client, Prop_Send, "m_iAmmo", _, iBitsType) + iResult;
  185.         SetEntProp(client, Prop_Send, "m_iAmmo", iTotal, _, iBitsType);
  186.        
  187.         if (g_iAmmo[iTarget][iBits] < 0)
  188.         {
  189.             int iDelete = iTotal + g_iAmmo[iTarget][iBits];
  190.             SetEntProp(client, Prop_Send, "m_iAmmo", iDelete, _, iBitsType);
  191.  
  192.             DataPack dPack;
  193.        
  194.             CreateDataTimer(0.01, tFix, dPack, TIMER_DATA_HNDL_CLOSE);
  195.             dPack.WriteCell(GetClientUserId(client));
  196.             dPack.WriteCell(iDelete);
  197.             dPack.WriteCell(iBitsType);
  198.            
  199.             PrintHintText(client, "Последние.");
  200.             g_iAmmo[iTarget][iBits] = 0;
  201.         }
  202.         else
  203.             PrintHintText(client, "Подобрано патронов %i, осталось %i", iResult, g_iAmmo[iTarget][iBits]);
  204.     }
  205.     else
  206.     {
  207.         DataPack dPack;
  208.        
  209.         CreateDataTimer(0.01, tReset, dPack, TIMER_DATA_HNDL_CLOSE);
  210.  
  211.         dPack.WriteCell(GetClientUserId(client));
  212.         dPack.WriteCell(EntIndexToEntRef(iWeapon));
  213.         dPack.WriteCell(iAmmoSave[0]);
  214.         dPack.WriteCell(iAmmoSave[1]);
  215.        
  216.         PrintHintText(client, "Нет патронов вашего калибра.");
  217.     }
  218. }
  219.  
  220. public Action tFix (Handle timer, DataPack dPack)
  221. {
  222.     dPack.Reset();
  223.     int client = GetClientOfUserId(dPack.ReadCell());
  224.     int iTotal = dPack.ReadCell();
  225.     int iBitsType = dPack.ReadCell();
  226.    
  227.     if (client > 0 && client <= MaxClients && IsClientInGame(client))
  228.     {
  229.         SetEntProp(client, Prop_Send, "m_iAmmo", iTotal, _, iBitsType);
  230.     }
  231. }
  232.  
  233. public Action tReset (Handle timer, DataPack dPack)
  234. {
  235.     dPack.Reset();
  236.     int client = GetClientOfUserId(dPack.ReadCell());
  237.     int iWeapon = EntRefToEntIndex(dPack.ReadCell());
  238.     int iAmmo = dPack.ReadCell();
  239.     int iClip = dPack.ReadCell();
  240.    
  241.     if (!IsValidEntity(iWeapon) || client <= 0 || client > MaxClients || !IsClientInGame(client))
  242.         return;
  243.    
  244.     iResetAmmo(client, iAmmo, iClip, iWeapon);
  245. }
  246.  
  247. void iResetAmmo(int client, int iAmmo, int iClip, int iWeapon)
  248. {
  249.     int iBits;
  250.    
  251.     if(IsValidEntity(iWeapon))
  252.     {
  253.         iBits = GetEntProp(iWeapon, Prop_Data, "m_iPrimaryAmmoType");  
  254.        
  255.         if (iBits <= 0)
  256.             return;
  257.        
  258.         SetEntProp(client, Prop_Send, "m_iAmmo", iAmmo, _, iBits);
  259.         SetEntProp(iWeapon, Prop_Send, "m_iClip1", iClip);
  260.     }
  261. }
  262.  
  263. stock void iSaveAmmo (int client, int array[2])
  264. {
  265.     int iWeapon = GetPlayerWeaponSlot(client, 0);
  266.    
  267.     int iBits, iAmmo, iClip;
  268.    
  269.     if(IsValidEntity(iWeapon))
  270.     {
  271.         iBits = GetEntProp(iWeapon, Prop_Data, "m_iPrimaryAmmoType");  
  272.        
  273.         if (iBits <= 0)
  274.             return;
  275.        
  276.         iAmmo = GetEntProp(client, Prop_Send, "m_iAmmo", _, iBits);
  277.         iClip = GetEntProp(iWeapon, Prop_Send, "m_iClip1");
  278.        
  279.         array[0] = iAmmo;
  280.         array[1] = iClip;
  281.     }
  282. }
  283.  
  284. stock int iBitsWeapon (int iWeapon)
  285. {
  286.     char szBuffer[36];
  287.     GetEntityClassname(iWeapon, szBuffer, sizeof szBuffer);
  288.    
  289.     if (strcmp(szBuffer, "weapon_smg_silenced") == 0)
  290.         return 9;
  291.     else if (StrContains(szBuffer, "weapon_smg") != -1)
  292.         return 1;
  293.     else if (strcmp(szBuffer, "weapon_rifle") == 0 || strcmp(szBuffer, "weapon_rifle_sg552") == 0 || strcmp(szBuffer, "weapon_sniper_scout") == 0)
  294.         return 2;
  295.     else if (strcmp(szBuffer, "weapon_rifle_desert") == 0 || strcmp(szBuffer, "weapon_sniper_military") == 0 || strcmp(szBuffer, "weapon_rifle_m60") == 0)
  296.         return 3;  
  297.     else if (strcmp(szBuffer, "weapon_sniper_awp") == 0)
  298.         return 4;  
  299.     else if (strcmp(szBuffer, "weapon_pumpshotgun") == 0 || strcmp(szBuffer, "weapon_autoshotgun") == 0)
  300.         return 5;  
  301.     else if (strcmp(szBuffer, "weapon_shotgun_chrome") == 0 || strcmp(szBuffer, "weapon_shotgun_spas") == 0)
  302.         return 6;
  303.     else if (strcmp(szBuffer, "weapon_hunting_rifle") == 0 || strcmp(szBuffer, "weapon_rifle_ak47") == 0)
  304.         return 7;
  305.     else if (strcmp(szBuffer, "weapon_grenade_launcher") == 0)
  306.         return 8;
  307.     return INVALID_ENT_REFERENCE;
  308. }
  309.  
  310. stock int iAmmoBits (int iWeapon)
  311. {
  312.     char szBuffer[36];
  313.     GetEntityClassname(iWeapon, szBuffer, sizeof szBuffer);
  314.    
  315.     for (int i; i < sizeof g_iAmmoLimits; i++)
  316.         if (strcmp(szBuffer, gWeapons[i]) == 0)
  317.             return g_iAmmoLimits[i];
  318.     return INVALID_ENT_REFERENCE;
  319. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top