FlacoBey

Untitled

May 31st, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 23.78 KB | None | 0 0
  1.  
  2. #include <sourcemod>
  3. #include <sdktools>
  4. #include <sdkhooks>
  5.  
  6. #pragma semicolon 1
  7. #pragma newdecls required
  8.  
  9. HintIndex[2048+1];
  10. HintEntity[2048+1];
  11.  
  12. PistolIndex[2048+1][2];
  13. TempPistolArray[2];
  14.  
  15. static int PistolClip;
  16. static int PistolAmmo;
  17. static int DualPistolClip;
  18. static int DualPistolAmmo;
  19. static int MagnumClip;
  20. static int MagnumAmmo;
  21.  
  22. bool bWeaponDrop;
  23. bool bMissionLost;
  24. bool bReloading[2048+1];
  25. bool bPickedUp[MAXPLAYERS+1];
  26. bool bUpdateHud[MAXPLAYERS+1];
  27.  
  28. ConVar PistolHud;
  29. ConVar PistolAmmoClip;
  30. ConVar PistolAmmoReserve;
  31. ConVar MagnumAmmoClip;
  32. ConVar MagnumAmmoReserve;
  33.  
  34. static const char Slot0Class[5][32] = {"rifle", "smg", "shotgun", "sniper", "grenade_launcher"};
  35. static const char Slot1Class[3][32] = {"pistol", "pistol_magnum", "melee"};
  36. static const char Slot2Class[3][32] = {"molotov", "pipe_bomb", "vomitjar"};
  37. static const char Slot3Class[4][32] = {"first_aid_kit", "defibrillator", "upgradepack_incendiary", "upgradepack_explosive"};
  38. static const char Slot4Class[2][32] = {"pain_pills", "adrenaline"};
  39.  
  40. public void OnPluginStart()
  41. {
  42.     //PistolResetClip = CreateConVar("l4d_pistol_reset_clip", "1", "1=Set Pistol Clip To 0 When Reloading", FCVAR_NOTIFY);
  43.     PistolAmmoClip = CreateConVar("l4d_pistol_ammo_clip", "15", "Pistol ammo clip amount", FCVAR_NOTIFY);
  44.     PistolAmmoReserve = CreateConVar("l4d_pistol_ammo_reserve", "75", "Pistol ammo reserve amount", FCVAR_NOTIFY);
  45.     MagnumAmmoClip = CreateConVar("l4d_magnum_ammo_clip", "8", "Magnum ammo clip amount", FCVAR_NOTIFY);
  46.     MagnumAmmoReserve = CreateConVar("l4d_magnum_ammo_reserve", "88", "Magnum ammo reserve amount", FCVAR_NOTIFY);
  47.     PistolHud = CreateConVar("l4d_pistol_hud", "1", "0=Disable Pistol Hud, 1=Enable Pistol Hud", FCVAR_NOTIFY);
  48.  
  49.     HookEvent("round_start", eRoundStart, EventHookMode_PostNoCopy);
  50.     HookEvent("mission_lost", eMissionLost, EventHookMode_PostNoCopy);
  51.  
  52.     HookEvent("player_team", ePlayerTeam);
  53.     HookEvent("bot_player_replace", ePlayerBotReplace);
  54.     HookEvent("player_bot_replace", eBotPlayerReplace);
  55.  
  56.     HookEvent("player_use", ePlayerUse);
  57.     HookEvent("weapon_fire", eWeaponFire);
  58.  
  59.     AutoExecConfig(true, "l4d_pistol_reloading");
  60.  
  61.     PistolClip = GetConVarInt(PistolAmmoClip);
  62.     PistolAmmo = GetConVarInt(PistolAmmoReserve);
  63.     DualPistolClip = (PistolClip * 2);
  64.     DualPistolAmmo = (PistolAmmo * 2);
  65.     MagnumClip = GetConVarInt(MagnumAmmoClip);
  66.     MagnumAmmo = GetConVarInt(MagnumAmmoReserve);
  67.  
  68.     SetConVarInt(FindConVar("ammo_pistol_max"), 1);
  69.  
  70.     for (int i = 1; i <= MaxClients; i++)
  71.     {
  72.         if(IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2)
  73.         {
  74.             OnClientPutInServer(i);
  75.         }
  76.     }
  77. }
  78.  
  79. public void OnClientPutInServer(int client)
  80. {
  81.     DestroyHintEntity(client);
  82.     CreateHintEntity(client);
  83.  
  84.     SDKHook(client, SDKHook_WeaponDrop, OnWeaponDrop);
  85.     SDKHook(client, SDKHook_PostThinkPost, OnPostThinkPost);
  86.  
  87.     if(GetConVarInt(PistolHud) == 1 && !IsFakeClient(client))
  88.     {
  89.         SDKHook(client, SDKHook_WeaponSwitchPost, OnWeaponSwitchPost);
  90.     }
  91. }
  92.  
  93. public Action OnPostThinkPost(int client)
  94. {
  95.     if(IsValidClient(client))
  96.     {
  97.         int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  98.  
  99.         if(weapon > -1)
  100.         {
  101.             char sWeapon[32];
  102.             GetEntityClassname(weapon, sWeapon, sizeof(sWeapon));
  103.  
  104.             if(StrContains(sWeapon, "pistol") > -1)
  105.             {
  106.                 if(bReloading[weapon])
  107.                 {
  108.                     int InReload = GetEntProp(weapon, Prop_Data, "m_bInReload");
  109.  
  110.                     if(!InReload)
  111.                     {
  112.                         bReloading[weapon] = false;
  113.                         DisplayInstructorHint(client, 1, 0.0, 0.0, true, false, 0, "", "", "", true, {255, 25, 25});
  114. /*
  115.                         if(StrEqual(sWeapon, "weapon_pistol") && GetEntProp(weapon, Prop_Send, "m_isDualWielding") > 0)
  116.                         {
  117.                             SetEntProp(weapon, Prop_Data, "m_iClip1", DualPistolClip);
  118.                             SetEntProp(weapon, Prop_Send, "m_iClip1", DualPistolClip);
  119.  
  120.                             int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  121.                             if(AmmoType == -1)
  122.                                 return;
  123.  
  124.                             //int Clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  125.                             int Ammo = GetEntProp(client, Prop_Data, "m_iAmmo", _, AmmoType);
  126.  
  127.                             SetEntProp(client, Prop_Send, "m_iAmmo", (Ammo - DualPistolClip), _, AmmoType);
  128.                         }
  129.                         else if(StrEqual(sWeapon, "weapon_pistol"))
  130.                         {
  131.                             SetEntProp(weapon, Prop_Data, "m_iClip1", PistolClip);
  132.                             SetEntProp(weapon, Prop_Send, "m_iClip1", PistolClip);
  133.  
  134.                             int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  135.                             if(AmmoType == -1)
  136.                                 return;
  137.  
  138.                             //int Clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  139.                             int Ammo = GetEntProp(client, Prop_Data, "m_iAmmo", _, AmmoType);
  140.  
  141.                             SetEntProp(client, Prop_Send, "m_iAmmo", (Ammo - PistolClip), _, AmmoType);
  142.                         }
  143.                         else if(StrEqual(sWeapon, "weapon_pistol_magnum"))
  144.                         {
  145.                             SetEntProp(weapon, Prop_Data, "m_iClip1", MagnumClip);
  146.                             SetEntProp(weapon, Prop_Send, "m_iClip1", MagnumClip);
  147.  
  148.                             int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  149.                             if(AmmoType == -1)
  150.                                 return;
  151.  
  152.                             //int Clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  153.                             int Ammo = GetEntProp(client, Prop_Data, "m_iAmmo", _, AmmoType);
  154.  
  155.                             SetEntProp(client, Prop_Send, "m_iAmmo", (Ammo - MagnumClip), _, AmmoType);
  156.                         }
  157. */
  158.                     }
  159.                 }
  160. /*
  161.                 if(StrEqual(sWeapon, "weapon_pistol") && GetEntProp(weapon, Prop_Send, "m_isDualWielding") > 0) //DONT TRACK DUALIES THIS WAY
  162.                     return;
  163.  
  164.                 int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  165.  
  166.                 if(AmmoType > -1)
  167.                 {
  168.                     PistolIndex[weapon][0] = GetEntProp(weapon, Prop_Send, "m_iClip1");
  169.                     PistolIndex[weapon][1] = GetEntProp(client, Prop_Data, "m_iAmmo", _, AmmoType);
  170.                 }
  171. */
  172.             }
  173.         }
  174.     }
  175. }
  176.  
  177. public Action OnWeaponDrop(int client, int weapon)
  178. {
  179.     if(IsValidClient(client) && IsValidEntity(weapon))
  180.     {
  181.         char sWeapon[32];
  182.         GetEntityClassname(weapon, sWeapon, sizeof(sWeapon));
  183.  
  184.         int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  185.  
  186.         if(AmmoType > -1)
  187.         {
  188.             int Clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  189.             int Ammo = GetEntProp(client, Prop_Data, "m_iAmmo", _, AmmoType);
  190.  
  191.             if(StrEqual(sWeapon, "weapon_pistol") && GetEntProp(weapon, Prop_Send, "m_isDualWielding") > 0)
  192.             {
  193.                 if(IsOdd(Clip + Ammo))
  194.                 {
  195.                     PistolIndex[weapon][0] = (Clip / 2);
  196.                     PistolIndex[weapon][1] = ((Ammo / 2) + 1);
  197.  
  198.                     TempPistolArray[0] = (Clip / 2);
  199.                     TempPistolArray[1] = (Ammo / 2);
  200.                 }
  201.                 else
  202.                 {
  203.                     PistolIndex[weapon][0] = (Clip / 2);
  204.                     PistolIndex[weapon][1] = (Ammo / 2);
  205.  
  206.                     TempPistolArray[0] = (Clip / 2);
  207.                     TempPistolArray[1] = (Ammo / 2);
  208.                 }
  209.  
  210.                 bWeaponDrop = true;
  211.             }
  212.         }
  213.     }
  214.  
  215.     return Plugin_Continue;
  216. }
  217.  
  218. public void OnEntityCreated(int entity, const char[] classname)
  219. {
  220.     if(classname[0] != 'w' || StrContains(classname, "weapon_", false) != 0)
  221.         return;
  222.  
  223.     if(StrContains(classname, "pistol") > -1)
  224.     {
  225.         if(StrContains(classname, "spawn") == -1)
  226.             SDKHook(entity, SDKHook_SpawnPost, OnSpawnPost);
  227.  
  228.         if(StrEqual(classname, "weapon_pistol"))
  229.         {
  230.             if(bWeaponDrop)
  231.             {
  232.                 bWeaponDrop = false;
  233.  
  234.                 PistolIndex[entity][0] = TempPistolArray[0];
  235.                 PistolIndex[entity][1] = TempPistolArray[1];
  236.             }
  237.             else
  238.             {
  239.                 PistolIndex[entity][0] = PistolClip;
  240.                 PistolIndex[entity][1] = PistolAmmo;
  241.             }
  242.         }
  243.         else if(StrEqual(classname, "weapon_pistol_magnum"))
  244.         {
  245.             PistolIndex[entity][0] = MagnumClip;
  246.             PistolIndex[entity][1] = MagnumAmmo;
  247.         }
  248.     }
  249. }
  250.  
  251. public void OnSpawnPost(int entity)
  252. {
  253.     if(IsValidEntity(entity))
  254.     {
  255.         SDKUnhook(entity, SDKHook_SpawnPost, OnSpawnPost);
  256.         SDKHook(entity, SDKHook_ReloadPost, OnReloadPost);
  257.     }
  258. }
  259.  
  260. public void OnReloadPost(int weapon, bool bSuccessful)
  261. {
  262.     if(bSuccessful)
  263.         bReloading[weapon] = true;
  264. }
  265.  
  266. public void ePlayerUse(Event event, const char[] name, bool dontBroadcast)
  267. {
  268.     int client = GetClientOfUserId(event.GetInt("userid"));
  269.     int entity = event.GetInt("targetid");
  270.  
  271.     if(IsValidClient(client) && GetClientTeam(client) == 2 && IsValidEntity(entity))
  272.     {
  273.         char sWeapon[32];
  274.         GetEntityClassname(entity, sWeapon, sizeof(sWeapon));
  275.  
  276.         int weapon = GetPlayerWeaponSlot(client, 1);
  277.  
  278.         char sSlot[32];
  279.  
  280.         if(StrEqual(sWeapon, "weapon_ammo_spawn"))
  281.         {
  282.             if(weapon > -1)
  283.             {
  284.                 GetEntityClassname(weapon, sSlot, sizeof(sSlot));
  285.  
  286.                 if(StrContains(sSlot, "pistol") > -1)
  287.                 {
  288.                     int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  289.                     if (AmmoType == -1)
  290.                         return;
  291.  
  292.                     int Clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  293.                     int Ammo = GetEntProp(client, Prop_Data, "m_iAmmo", _, AmmoType);
  294.  
  295.                     float cPos[3];
  296.                     GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", cPos);
  297.  
  298.                     float aPos[3];
  299.                     GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", aPos);
  300.  
  301.                     if(GetVectorDistance(cPos, aPos) <= 96)
  302.                     {
  303.                         if(StrEqual(sSlot, "weapon_pistol") && GetEntProp(weapon, Prop_Send, "m_isDualWielding") > 0)
  304.                         {
  305.                             if (Ammo >= DualPistolAmmo && Clip == DualPistolClip)
  306.                                 return;
  307.                             else if (Ammo > DualPistolAmmo && Clip <= DualPistolClip)
  308.                                 return;
  309.  
  310.                             SetEntProp(weapon, Prop_Send, "m_iClip1", 0);
  311.                             SetEntProp(client, Prop_Send, "m_iAmmo", DualPistolAmmo + DualPistolClip, _, AmmoType);
  312.  
  313.                             ClientCommand(client, "play items/itempickup.wav");
  314.                         }
  315.                         else if(StrEqual(sSlot, "weapon_pistol"))
  316.                         {
  317.                             if (Ammo >= PistolAmmo && Clip == PistolClip)
  318.                                 return;
  319.                             else if (Ammo > PistolAmmo && Clip <= PistolClip)
  320.                                 return;
  321.  
  322.                             SetEntProp(weapon, Prop_Send, "m_iClip1", 0);
  323.                             SetEntProp(client, Prop_Send, "m_iAmmo", PistolAmmo + PistolClip, _, AmmoType);
  324.  
  325.                             ClientCommand(client, "play items/itempickup.wav");
  326.                         }
  327.                         else if(StrEqual(sSlot, "weapon_pistol_magnum"))
  328.                         {
  329.                             if (Ammo >= MagnumAmmo && Clip == MagnumClip)
  330.                                 return;
  331.                             else if (Ammo > MagnumAmmo && Clip <= MagnumClip)
  332.                                 return;
  333.  
  334.                             SetEntProp(weapon, Prop_Send, "m_iClip1", 0);
  335.                             SetEntProp(client, Prop_Send, "m_iAmmo", MagnumAmmo + MagnumClip, _, AmmoType);
  336.  
  337.                             ClientCommand(client, "play items/itempickup.wav");
  338.                         }
  339.                     }
  340.                 }
  341.             }
  342.         }
  343.         else if(StrContains(sWeapon, "spawn") > -1)
  344.         {
  345.             char sModel[64];
  346.             GetEntPropString(entity, Prop_Data, "m_ModelName", sModel, sizeof(sModel));
  347.  
  348.             if(StrContains(sModel, "w_pistol_A") > -1 || StrContains(sModel, "w_desert_eagle") > -1)
  349.             {
  350.                 int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  351.                 if (AmmoType == -1)
  352.                     return;
  353.  
  354.                 if(weapon > -1)
  355.                 {
  356.                     //int Clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  357.                     //int Ammo = GetEntProp(client, Prop_Data, "m_iAmmo", _, AmmoType);
  358.  
  359.                     GetEntityClassname(weapon, sSlot, sizeof(sSlot));
  360.  
  361.                     if(StrEqual(sSlot, "weapon_pistol") && GetEntProp(weapon, Prop_Send, "m_isDualWielding") > 0)
  362.                     {
  363.                         SetEntProp(weapon, Prop_Data, "m_iClip1", DualPistolClip);
  364.                         SetEntProp(weapon, Prop_Send, "m_iClip1", DualPistolClip);
  365.                         SetEntProp(client, Prop_Send, "m_iAmmo", DualPistolAmmo, _, AmmoType);
  366.  
  367.                         //DO ACCEPTENTITYINPUT KILL HERE WITH PROPER CHECKING
  368.                     }
  369.                     else if(StrEqual(sSlot, "weapon_pistol"))
  370.                     {
  371.                         SetEntProp(weapon, Prop_Data, "m_iClip1", PistolClip);
  372.                         SetEntProp(weapon, Prop_Send, "m_iClip1", PistolClip);
  373.                         SetEntProp(client, Prop_Send, "m_iAmmo", PistolAmmo, _, AmmoType);
  374.                     }
  375.                     else if(StrEqual(sSlot, "weapon_pistol_magnum"))
  376.                     {
  377.                         SetEntProp(weapon, Prop_Data, "m_iClip1", MagnumClip);
  378.                         SetEntProp(weapon, Prop_Send, "m_iClip1", MagnumClip);
  379.                         SetEntProp(client, Prop_Send, "m_iAmmo", MagnumAmmo, _, AmmoType);
  380.                     }
  381.                 }
  382.             }
  383.         }
  384.         else if(StrContains(sWeapon, "pistol") > -1)
  385.         {
  386.             bUpdateHud[client] = true;
  387.  
  388.             int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  389.             if (AmmoType == -1)
  390.                 return;
  391.  
  392.             if(weapon > -1)
  393.             {
  394.                 //int Clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  395.                 //int Ammo = GetEntProp(client, Prop_Data, "m_iAmmo", _, AmmoType);
  396.  
  397.                 GetEntityClassname(weapon, sSlot, sizeof(sSlot));
  398.  
  399.                 if(StrEqual(sSlot, "weapon_pistol") && GetEntProp(weapon, Prop_Send, "m_isDualWielding") > 0)
  400.                 {
  401.                     SetEntProp(weapon, Prop_Data, "m_iClip1", (PistolIndex[weapon][0] + PistolIndex[entity][0]));
  402.                     SetEntProp(weapon, Prop_Send, "m_iClip1", (PistolIndex[weapon][0] + PistolIndex[entity][0]));
  403.                     SetEntProp(client, Prop_Send, "m_iAmmo", (PistolIndex[weapon][1] + PistolIndex[entity][1]), _, AmmoType);
  404.  
  405.                     //DO ACCEPTENTITYINPUT KILL HERE WITH PROPER CHECKING
  406.                 }
  407.                 else if(StrEqual(sSlot, "weapon_pistol"))
  408.                 {
  409.                     SetEntProp(weapon, Prop_Data, "m_iClip1", PistolIndex[weapon][0]);
  410.                     SetEntProp(weapon, Prop_Send, "m_iClip1", PistolIndex[weapon][0]);
  411.                     SetEntProp(client, Prop_Send, "m_iAmmo", PistolIndex[weapon][1], _, AmmoType);
  412.                 }
  413.                 else if(StrEqual(sSlot, "weapon_pistol_magnum"))
  414.                 {
  415.                     SetEntProp(weapon, Prop_Data, "m_iClip1", PistolIndex[weapon][0]);
  416.                     SetEntProp(weapon, Prop_Send, "m_iClip1", PistolIndex[weapon][0]);
  417.                     SetEntProp(client, Prop_Send, "m_iAmmo", PistolIndex[weapon][1], _, AmmoType);
  418.                 }
  419.             }
  420.             else
  421.             {
  422.                 SetEntProp(weapon, Prop_Data, "m_iClip1", PistolIndex[weapon][0]);
  423.                 SetEntProp(weapon, Prop_Send, "m_iClip1", PistolIndex[weapon][0]);
  424.                 SetEntProp(client, Prop_Send, "m_iAmmo", PistolIndex[weapon][1], _, AmmoType);
  425.             }
  426.         }
  427.     }
  428. }
  429.  
  430. //HUD SETUP//
  431. public void eWeaponFire(Event event, const char[] name, bool dontBroadcast)
  432. {
  433.     if(GetConVarInt(PistolHud) == 1)
  434.     {
  435.         int client = GetClientOfUserId(event.GetInt("userid"));
  436.  
  437.         if(IsValidClient(client))
  438.         {
  439.             char sClsName[32];
  440.             event.GetString("weapon", sClsName, sizeof(sClsName));
  441.  
  442.             if(StrContains(sClsName, "pistol") > -1)
  443.                 bUpdateHud[client] = true;
  444.         }
  445.     }
  446. }
  447.  
  448. public Action OnWeaponSwitchPost(int client, int weapon)
  449. {
  450.     if(IsValidClient(client) && GetClientTeam(client) == 2 && IsValidEntity(weapon))
  451.     {
  452.         weapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
  453.  
  454.         if(IsValidEntity(weapon))
  455.         {
  456.             char sClsName[32];
  457.             GetEntityClassname(weapon, sClsName, sizeof(sClsName));
  458.  
  459.             if(StrContains(sClsName, "pistol") > -1)
  460.             {
  461.                 CreateHintEntity(client);
  462.                 bUpdateHud[client] = true;
  463.             }
  464.             else
  465.             {
  466.                 DestroyHintEntity(client);
  467.             }
  468.         }
  469.     }
  470. }
  471.  
  472. public void eRoundStart (Handle event, const char[] name, bool dontBroadcast)
  473. {
  474.     if(GetConVarInt(PistolHud) != 1)
  475.         return;
  476.  
  477.     if(bMissionLost)
  478.     {
  479.         for(int i = 1; i <= MaxClients; i++)
  480.         {
  481.             if(IsValidClient(i) && GetClientTeam(i) != 3)
  482.             {
  483.                 if(IsValidEntRef(HintIndex[i]))
  484.                 {
  485.                     AcceptEntityInput(HintIndex[i], "Kill");
  486.                     HintIndex[i] = -1;
  487.                 }
  488.  
  489.                 HintEntity[i] = CreateEntityByName("env_instructor_hint");
  490.  
  491.                 if(HintEntity[i] < 0)
  492.                     return;
  493.  
  494.                 DispatchSpawn(HintEntity[i]);
  495.  
  496.                 HintIndex[i] = EntIndexToEntRef(HintEntity[i]);
  497.             }
  498.         }
  499.     }
  500.  
  501.     bMissionLost = false;
  502. }
  503.  
  504. public void eMissionLost(Handle event, const char[] name, bool dontBroadcast)
  505. {
  506.     if(GetConVarInt(PistolHud) == 1)
  507.         bMissionLost = true;
  508. }
  509.  
  510. public void eBotPlayerReplace(Event event, const char[] name, bool dontBroadcast)
  511. {
  512.     if(GetConVarInt(PistolHud) == 1)
  513.     {
  514.         int bot = GetClientOfUserId(GetEventInt(event, "bot"));
  515.         int player = GetClientOfUserId(GetEventInt(event, "player"));
  516.  
  517.         DestroyHintEntity(player);
  518.         CreateHintEntity(bot);
  519.     }
  520. }
  521.  
  522. public void ePlayerBotReplace(Handle event, const char[] name, bool dontBroadcast)
  523. {
  524.     if(GetConVarInt(PistolHud) == 1)
  525.     {
  526.         int bot = GetClientOfUserId(GetEventInt(event, "bot"));
  527.         int player = GetClientOfUserId(GetEventInt(event, "player"));
  528.  
  529.         DestroyHintEntity(bot);
  530.         CreateHintEntity(player);
  531.     }
  532. }
  533.  
  534. public Action ePlayerTeam(Handle event, const char[] sEventName, bool bDontBroadcast)
  535. {
  536.     if(GetConVarInt(PistolHud) != 1)
  537.         return;
  538.  
  539.     int team = GetEventInt(event, "team");
  540.     int oldteam = GetEventInt(event, "oldteam");
  541.     int disconnect = GetEventBool(event, "disconnect");
  542.     int client = GetClientOfUserId(GetEventInt(event, "userid"));
  543.  
  544.     if(!IsValidClient(client))
  545.         return;
  546.  
  547.     switch(oldteam)
  548.     {
  549.         case 0:
  550.         {
  551.  
  552.         }
  553.         case 1:
  554.         {
  555.  
  556.         }
  557.         case 2:
  558.         {
  559.             DestroyHintEntity(client);
  560.         }
  561.         case 3:
  562.         {
  563.  
  564.         }
  565.     }
  566.  
  567.     switch(team)
  568.     {
  569.         case 0:
  570.         {
  571.  
  572.         }
  573.         case 1:
  574.         {
  575.  
  576.         }
  577.         case 2:
  578.         {
  579.             CreateHintEntity(client);
  580.         }
  581.         case 3:
  582.         {
  583.  
  584.         }
  585.     }
  586.  
  587.     if(disconnect)
  588.     {
  589.  
  590.     }
  591. }
  592.  
  593. void DestroyHintEntity(int client)
  594. {
  595.     if(IsValidEntRef(HintIndex[client]))
  596.     {
  597.         AcceptEntityInput(HintIndex[client], "Kill");
  598.         HintIndex[client] = -1;
  599.     }
  600. }
  601.  
  602. void CreateHintEntity(int client)
  603. {
  604.     if(IsValidEntRef(HintIndex[client]))
  605.     {
  606.         AcceptEntityInput(HintIndex[client], "Kill");
  607.         HintIndex[client] = -1;
  608.     }
  609.  
  610.     HintEntity[client] = CreateEntityByName("env_instructor_hint");
  611.  
  612.     if(HintEntity[client] < 0)
  613.         return;
  614.  
  615.     DispatchSpawn(HintEntity[client]);
  616.  
  617.     HintIndex[client] = EntIndexToEntRef(HintEntity[client]);
  618. }
  619.  
  620. public void OnGameFrame()
  621. {
  622.     if(!IsServerProcessing())
  623.         return;
  624.  
  625.     for(int i = 1; i <= MaxClients; i++)
  626.     {
  627.         if(IsValidClient(i) && GetClientTeam(i) == 2 && IsPlayerAlive(i))
  628.         {
  629.             bPickedUp[i] = false; //FIXES ONPLAYER USE REPETETIVE PICKUP
  630.  
  631.             if(!IsFakeClient(i) && bUpdateHud[i])
  632.             {
  633.                 bUpdateHud[i] = false;
  634.  
  635.                 if(GetConVarInt(PistolHud) == 1)
  636.                 {
  637.                     int weapon = GetEntPropEnt(i, Prop_Data, "m_hActiveWeapon");
  638.  
  639.                     if(weapon > -1)
  640.                     {
  641.                         char sClsName[32];
  642.                         GetEntityClassname(weapon, sClsName, sizeof(sClsName));
  643.  
  644.                         if(StrContains(sClsName, "pistol") > -1)
  645.                         {
  646.                             DisplayInstructorHint(i, 1, 0.0, 0.0, true, false, 0, "", "", "", true, {255, 25, 25});
  647.  
  648.                             int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  649.  
  650.                             if(AmmoType > -1)
  651.                             {
  652.                                 PistolIndex[weapon][0] = GetEntProp(weapon, Prop_Send, "m_iClip1");
  653.                                 PistolIndex[weapon][1] = GetEntProp(i, Prop_Data, "m_iAmmo", _, AmmoType);
  654.                             }
  655.                         }
  656.                     }
  657.                 }
  658.             }
  659.             else if(IsFakeClient(i))
  660.             {
  661.                 int weapon = GetEntPropEnt(i, Prop_Data, "m_hActiveWeapon");
  662.  
  663.                 if(IsValidEntity(weapon))
  664.                 {
  665.                     char sClsName[32];
  666.                     GetEntityClassname(weapon, sClsName, sizeof(sClsName));
  667.  
  668.                     if(StrContains(sClsName, "pistol") > -1)
  669.                     {
  670.                         int AmmoType = GetEntProp(weapon, Prop_Data, "m_iPrimaryAmmoType");
  671.  
  672.                         if(AmmoType > -1)
  673.                         {
  674.                             int Clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  675.                             int Ammo = GetEntProp(i, Prop_Data, "m_iAmmo", _, AmmoType);
  676.  
  677.                             if(Ammo <= 0 && Clip <= 1)
  678.                             {
  679.                                 if(StrEqual(sClsName, "weapon_pistol"))
  680.                                 {
  681.                                     if(GetEntProp(weapon, Prop_Send, "m_isDualWielding") > 0)
  682.                                     {
  683.                                         SetEntProp(weapon, Prop_Send, "m_iClip1", 0);
  684.                                         SetEntProp(i, Prop_Send, "m_iAmmo", DualPistolClip, _, AmmoType);
  685.                                     }
  686.                                     else
  687.                                     {
  688.                                         SetEntProp(weapon, Prop_Send, "m_iClip1", 0);
  689.                                         SetEntProp(i, Prop_Send, "m_iAmmo", PistolClip, _, AmmoType);
  690.                                     }
  691.                                 }
  692.                                 else if(StrEqual(sClsName, "weapon_pistol_magnum"))
  693.                                 {
  694.                                     SetEntProp(weapon, Prop_Send, "m_iClip1", 0);
  695.                                     SetEntProp(i, Prop_Send, "m_iAmmo", MagnumClip, _, AmmoType);
  696.                                 }
  697.                             }
  698.                         }
  699.                     }
  700.                 }
  701.             }
  702.         }
  703.     }
  704. }
  705.  
  706. stock void DisplayInstructorHint(int target, int iTimeout, float fHeight, float fRange, bool bFollow, bool bShowOffScreen, int flag, char[] sIconOnScreen, char[] sIconOffScreen, char[] sCmd, bool bShowTextAlways, int iColor[3])
  707. {
  708.     if(!IsValidEntity(target) || !IsValidEntity(HintEntity[target]))
  709.         return;
  710.  
  711.     char sBuffer[32];
  712.  
  713.     for(int i = 1; i <= MaxClients; i++)
  714.     {
  715.         if(IsValidClient(i) && !IsFakeClient(i) && GetClientTeam(i) == 2 && IsPlayerAlive(i))
  716.         {
  717.             if(i == target)
  718.             {
  719.                 FormatEx(sBuffer, sizeof(sBuffer), "pistol_%d", target);
  720.                 DispatchKeyValue(target, "targetname", sBuffer);
  721.                 DispatchKeyValue(HintEntity[target], "hint_target", sBuffer);
  722.                 DispatchKeyValue(HintEntity[target], "hint_replace_key", sBuffer);
  723.  
  724.                 DispatchKeyValue(HintEntity[target], "hint_instance_type", "2");
  725.                 DispatchKeyValue(HintEntity[target], "hint_display_limit", "0");
  726.                 DispatchKeyValue(HintEntity[target], "hint_suppress_rest", "1");
  727.                 DispatchKeyValue(HintEntity[target], "hint_auto_start", "false");
  728.                 DispatchKeyValue(HintEntity[target], "hint_local_player_only", "false");
  729.                 DispatchKeyValue(HintEntity[target], "hint_allow_nodraw_target", "true");
  730.  
  731.                 int Weapon = GetEntPropEnt(i, Prop_Data, "m_hActiveWeapon");
  732.  
  733.                 if (Weapon == -1)
  734.                     return;
  735.  
  736.                 char sWeapon[32];
  737.                 GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
  738.  
  739.                 char Message[48];
  740.  
  741.                 int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");
  742.  
  743.                 if (AmmoType == -1)
  744.                     return;
  745.  
  746.                 int Clip = GetEntProp(Weapon, Prop_Data, "m_iClip1");
  747.                 int Ammo = GetEntProp(i, Prop_Send, "m_iAmmo", _, AmmoType);
  748.  
  749.                 if (StrEqual(sWeapon, "weapon_pistol", false))
  750.                 {
  751.                     if(GetEntProp(Weapon, Prop_Send, "m_isDualWielding") > 0)
  752.                     {
  753.                         if (Ammo == 0 && Clip <= 1)
  754.                             Format(Message, sizeof(Message), "EMPTY");
  755.                         else if (Ammo == (DualPistolAmmo + DualPistolClip) && Clip < 1)
  756.                             Format(Message, sizeof(Message), "RELOAD");
  757.                         else
  758.                             Format(Message, sizeof(Message), "%d/%d", Clip, Ammo);
  759.                     }
  760.                     else
  761.                     {
  762.                         if (Ammo == 0 && Clip <= 1)
  763.                             Format(Message, sizeof(Message), "EMPTY");
  764.                         else if (Ammo == (PistolAmmo + PistolClip) && Clip < 1)
  765.                             Format(Message, sizeof(Message), "RELOAD");
  766.                         else
  767.                             Format(Message, sizeof(Message), "%d/%d", Clip, Ammo);
  768.                     }
  769.                 }
  770.                 else if (StrEqual(sWeapon, "weapon_pistol_magnum", false))
  771.                 {
  772.                     if (Ammo == 0 && Clip <= 1)
  773.                         Format(Message, sizeof(Message), "EMPTY");
  774.                     else if (Ammo == (MagnumAmmo + MagnumClip) && Clip < 1)
  775.                         Format(Message, sizeof(Message), "RELOAD");
  776.                     else
  777.                         Format(Message, sizeof(Message), "%d/%d", Clip, Ammo);
  778.                 }
  779.                 else
  780.                     Format(Message, sizeof(Message), "%d/%d", Clip, Ammo);
  781.  
  782.                 DispatchKeyValue(HintEntity[target], "hint_caption", Message);
  783.                 DispatchKeyValue(HintEntity[target], "hint_activator_caption", Message);
  784.                 DispatchKeyValue(HintEntity[target], "hint_color", "100 255 100");
  785.  
  786.                 AcceptEntityInput(HintEntity[target], "ShowHint", i);
  787. /*
  788.                 FormatEx(sBuffer, sizeof(sBuffer), "OnUser1 self:ShowHint");
  789.                 SetVariantString(sBuffer);
  790.                 AcceptEntityInput(HintEntity[target], "AddOutput");
  791.                 AcceptEntityInput(HintEntity[target], "FireUser1");
  792. */
  793.             }
  794.         }
  795.     }
  796. }
  797.  
  798. stock int DetectSlot(char[] sClassName)
  799. {
  800.     for (int i = 0; i < sizeof(Slot0Class); i++)
  801.     {
  802.         if (StrContains(sClassName, Slot0Class[i]) > -1)
  803.             return 0;
  804.     }
  805.  
  806.     for (int i = 0; i < sizeof(Slot1Class); i++)
  807.     {
  808.         if (StrContains(sClassName, Slot1Class[i]) > -1)
  809.             return 1;
  810.     }
  811.  
  812.     for (int i = 0; i < sizeof(Slot2Class); i++)
  813.     {
  814.         if (StrContains(sClassName, Slot2Class[i]) > -1)
  815.             return 2;
  816.     }
  817.  
  818.     for (int i = 0; i < sizeof(Slot3Class); i++)
  819.     {
  820.         if (StrContains(sClassName, Slot3Class[i]) > -1)
  821.             return 3;
  822.     }
  823.  
  824.     for (int i = 0; i < sizeof(Slot4Class); i++)
  825.     {
  826.         if (StrContains(sClassName, Slot4Class[i]) > -1)
  827.             return 4;
  828.     }
  829.  
  830.     return -1;
  831. }
  832.  
  833.  
  834. stock int GetEntityInArray(int entity)
  835. {
  836.     if(IsValidEntity(entity))
  837.     {
  838.         for(int i = MAXPLAYERS; i <= 2048; i++)
  839.         {
  840.             if(!IsValidEntity(i))
  841.                 continue;
  842.  
  843.             if(PistolIndex[entity][0] == PistolIndex[i][0])
  844.                 return i;
  845.             else
  846.                 continue;
  847.         }
  848.     }
  849.  
  850.     return -1;
  851. }
  852.  
  853. stock bool IsValidClient(int client)
  854. {
  855.     return (client > 0 && client <= MaxClients && IsClientInGame(client));
  856. }
  857.  
  858. stock bool IsValidEntRef(int iEntRef)
  859. {
  860.     int iEntity = EntRefToEntIndex(iEntRef);
  861.     return (iEntRef && iEntity != INVALID_ENT_REFERENCE && IsValidEntity(iEntity));
  862. }
  863.  
  864. stock bool IsEven(int number)
  865. {
  866.     return (number & 1) == 0;
  867. }
  868.  
  869. stock bool IsOdd(int number)
  870. {
  871.     return (number & 1) == 1;
  872. }
Advertisement
Add Comment
Please, Sign In to add comment