FlacoBey

Untitled

Jul 2nd, 2019
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.92 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5.  
  6. #define MODEL_V_FIREAXE "models/weapons/melee/v_fireaxe.mdl"
  7. #define MODEL_V_FRYING_PAN "models/weapons/melee/v_frying_pan.mdl"
  8. #define MODEL_V_MACHETE "models/weapons/melee/v_machete.mdl"
  9. #define MODEL_V_BASEBALL_BAT "models/weapons/melee/v_bat.mdl"
  10. #define MODEL_V_CROWBAR "models/weapons/melee/v_crowbar.mdl"
  11. #define MODEL_V_CRICKET_BAT "models/weapons/melee/v_cricket_bat.mdl"
  12. #define MODEL_V_TONFA "models/weapons/melee/v_tonfa.mdl"
  13. #define MODEL_V_KATANA "models/weapons/melee/v_katana.mdl"
  14. #define MODEL_V_ELECTRIC_GUITAR "models/weapons/melee/v_electric_guitar.mdl"
  15. #define MODEL_V_GOLFCLUB "models/weapons/melee/v_golfclub.mdl"
  16. #define MODEL_V_SHIELD "models/weapons/melee/v_riotshield.mdl"
  17. #define MODEL_V_KNIFE "models/v_models/v_knife_t.mdl"
  18.  
  19. new g_PlayerSecondaryWeapons[MAXPLAYERS + 1];
  20.  
  21. public Plugin:myinfo =
  22. {
  23.     name        = "L4D2 Drop Secondary",
  24.     author      = "Jahze, Visor, NoBody",
  25.     version     = "1.5",
  26.     description = "Survivor players will drop their secondary weapon when they die",
  27.     url     = "https://github.com/Attano/Equilibrium"
  28. };
  29.  
  30. public OnPluginStart()
  31. {
  32.     HookEvent("round_start", EventHook:OnRoundStart, EventHookMode_PostNoCopy);
  33.     HookEvent("player_use", OnPlayerUse, EventHookMode_Post);
  34.     HookEvent("player_bot_replace", player_bot_replace);
  35.     HookEvent("bot_player_replace", bot_player_replace);
  36.     HookEvent("player_death", OnPlayerDeath, EventHookMode_Pre);
  37. }
  38.  
  39. public OnRoundStart()
  40. {
  41.     for (new i = 0; i <= MAXPLAYERS; i++)
  42.     {
  43.         g_PlayerSecondaryWeapons[i] = -1;
  44.     }
  45. }
  46.  
  47. public Action:OnPlayerUse(Handle:event, const String:name[], bool:dontBroadcast)
  48. {
  49.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  50.    
  51.     if(client == 0 || !IsClientInGame(client))
  52.     {
  53.         return;
  54.     }
  55.    
  56.     new weapon = GetPlayerWeaponSlot(client, 1);
  57.    
  58.     g_PlayerSecondaryWeapons[client] = (weapon == -1 ? weapon : EntIndexToEntRef(weapon));
  59. }
  60.  
  61. public Action:bot_player_replace(Handle:event, const String:name[], bool:dontBroadcast)
  62. {
  63.     new bot = GetClientOfUserId(GetEventInt(event, "bot"));
  64.     new client = GetClientOfUserId(GetEventInt(event, "player"));
  65.  
  66.     g_PlayerSecondaryWeapons[client] = g_PlayerSecondaryWeapons[bot];
  67.     g_PlayerSecondaryWeapons[bot] = -1;
  68. }
  69.  
  70. public Action:player_bot_replace(Handle:event, const String:name[], bool:dontBroadcast)
  71. {
  72.     new client = GetClientOfUserId(GetEventInt(event, "player"));
  73.     new bot = GetClientOfUserId(GetEventInt(event, "bot"));
  74.  
  75.     g_PlayerSecondaryWeapons[bot] = g_PlayerSecondaryWeapons[client];
  76.     g_PlayerSecondaryWeapons[client] = -1;
  77. }
  78.  
  79. public Action:OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  80. {
  81.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  82.    
  83.     if(client == 0 || !IsClientInGame(client))
  84.     {
  85.         return;
  86.     }
  87.    
  88.     new weapon = EntRefToEntIndex(g_PlayerSecondaryWeapons[client]);
  89.    
  90.     if(weapon == INVALID_ENT_REFERENCE)
  91.     {
  92.         return;
  93.     }
  94.  
  95.     if (weapon > 0)
  96.     {
  97.         new String:sWeapon[32];
  98.         new clip;
  99.         GetEdictClassname(weapon, sWeapon, 32);
  100.        
  101.         new index = CreateEntityByName(sWeapon);
  102.         new Float:origin[3];
  103.         new Float:ang[3];
  104.         if (StrEqual(sWeapon, "weapon_melee"))
  105.         {
  106.             new String:melee[150];
  107.             GetEntPropString(weapon , Prop_Data, "m_ModelName", melee, sizeof(melee));
  108.             if (StrEqual(melee, MODEL_V_FIREAXE))
  109.             {
  110.                 DispatchKeyValue(index, "melee_script_name", "fireaxe");
  111.             }
  112.             else if (StrEqual(melee, MODEL_V_FRYING_PAN))
  113.             {
  114.                 DispatchKeyValue(index, "melee_script_name", "frying_pan");
  115.             }
  116.             else if (StrEqual(melee, MODEL_V_MACHETE))
  117.             {
  118.                 DispatchKeyValue(index, "melee_script_name", "machete");
  119.             }
  120.             else if (StrEqual(melee, MODEL_V_BASEBALL_BAT))
  121.             {
  122.                 DispatchKeyValue(index, "melee_script_name", "baseball_bat");
  123.             }
  124.             else if (StrEqual(melee, MODEL_V_CROWBAR))
  125.             {
  126.                 DispatchKeyValue(index, "melee_script_name", "crowbar");
  127.             }
  128.             else if (StrEqual(melee, MODEL_V_CRICKET_BAT))
  129.             {
  130.                 DispatchKeyValue(index, "melee_script_name", "cricket_bat");
  131.             }
  132.             else if (StrEqual(melee, MODEL_V_TONFA))
  133.             {
  134.                 DispatchKeyValue(index, "melee_script_name", "tonfa");
  135.             }
  136.             else if (StrEqual(melee, MODEL_V_KATANA))
  137.             {
  138.                 DispatchKeyValue(index, "melee_script_name", "katana");
  139.             }
  140.             else if (StrEqual(melee, MODEL_V_ELECTRIC_GUITAR))
  141.             {
  142.                 DispatchKeyValue(index, "melee_script_name", "electric_guitar");
  143.             }
  144.             else if (StrEqual(melee, MODEL_V_GOLFCLUB))
  145.             {
  146.                 DispatchKeyValue(index, "melee_script_name", "golfclub");
  147.             }
  148.             else if (StrEqual(melee, MODEL_V_SHIELD))
  149.             {
  150.                 DispatchKeyValue(index, "melee_script_name", "riotshield");
  151.             }
  152.             else if (StrEqual(melee, MODEL_V_KNIFE))
  153.             {
  154.                 DispatchKeyValue(index, "melee_script_name", "knife");
  155.             }
  156.             else return;
  157.         }
  158.         else if (StrEqual(sWeapon, "weapon_chainsaw"))
  159.         {
  160.             clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  161.         }
  162.         else if (StrEqual(sWeapon, "weapon_pistol") && (GetEntProp(weapon, Prop_Send, "m_isDualWielding") > 0))
  163.         {
  164.             new indexC = CreateEntityByName(sWeapon);
  165.             GetClientEyePosition(client,origin);
  166.             GetClientEyeAngles(client, ang);
  167.             GetAngleVectors(ang, ang, NULL_VECTOR,NULL_VECTOR);
  168.             NormalizeVector(ang,ang);
  169.             ScaleVector(ang, 90.0);
  170.        
  171.             DispatchSpawn(indexC);
  172.             TeleportEntity(indexC, origin, NULL_VECTOR, ang);
  173.             ActivateEntity(indexC);
  174.         }
  175.         else if (StrEqual(sWeapon, "weapon_pistol_magnum"))
  176.         {
  177.             clip = GetEntProp(weapon, Prop_Send, "m_iClip1");
  178.         }
  179.  
  180.         RemovePlayerItem(client, weapon);
  181.        
  182.         GetClientEyePosition(client,origin);
  183.         GetClientEyeAngles(client, ang);
  184.         GetAngleVectors(ang, ang, NULL_VECTOR,NULL_VECTOR);
  185.         NormalizeVector(ang,ang);
  186.         ScaleVector(ang, 90.0);
  187.        
  188.         DispatchSpawn(index);
  189.         TeleportEntity(index, origin, NULL_VECTOR, ang);
  190.         ActivateEntity(index);
  191.  
  192.         if (StrEqual(sWeapon, "weapon_chainsaw") || StrEqual(sWeapon, "weapon_pistol") || StrEqual(sWeapon, "weapon_pistol_magnum"))
  193.         {
  194.             SetEntProp(index, Prop_Send, "m_iClip1", clip);
  195.         }
  196.     }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment