FlacoBey

Untitled

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