FlacoBey

Untitled

Feb 18th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.23 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5.  
  6. #define PLUGIN_VERSION "1.0"
  7. #define CVAR_FLAGS                                  FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_REPLICATED
  8. #define MODEL_V_FIREAXE "models/weapons/melee/v_fireaxe.mdl"
  9. #define MODEL_V_FRYING_PAN "models/weapons/melee/v_frying_pan.mdl"
  10. #define MODEL_V_MACHETE "models/weapons/melee/v_machete.mdl"
  11. #define MODEL_V_BASEBALL_BAT "models/weapons/melee/v_bat.mdl"
  12. #define MODEL_V_CROWBAR "models/weapons/melee/v_crowbar.mdl"
  13. #define MODEL_V_CRICKET_BAT "models/weapons/melee/v_cricket_bat.mdl"
  14. #define MODEL_V_TONFA "models/weapons/melee/v_tonfa.mdl"
  15. #define MODEL_V_KATANA "models/weapons/melee/v_katana.mdl"
  16. #define MODEL_V_ELECTRIC_GUITAR "models/weapons/melee/v_electric_guitar.mdl"
  17. #define MODEL_V_GOLFCLUB "models/weapons/melee/v_golfclub.mdl"
  18.  
  19. public Plugin:myinfo =
  20. {
  21.     name = "[L4D2] Drop weapon when punched",
  22.     author = "cheewongken",
  23.     description = "Survivors will drop their weapon when they get punched by a tank.",
  24.     version = PLUGIN_VERSION,
  25.     url = "http://www.sourcemod.net/"
  26. };
  27.  
  28. new TanksInGame;
  29. new GivenGun[MAXPLAYERS+1];
  30. new Handle:c_dwp_enabled = INVALID_HANDLE;
  31. new Handle:c_dwp_drop_incapped = INVALID_HANDLE;
  32. new Handle:c_dwp_drop_melee = INVALID_HANDLE;
  33. new Handle:c_dwp_give_pistol = INVALID_HANDLE;
  34. new Handle:c_dwp_drop_chainsaw = INVALID_HANDLE;
  35.  
  36. public OnPluginStart()
  37. {
  38.     decl String:game_name[64];
  39.     GetGameFolderName(game_name, sizeof(game_name));
  40.     if (!StrEqual(game_name, "left4dead2", false))
  41.     {      
  42.         SetFailState("[SM] Plugin supports Left 4 Dead 2 only.");
  43.     }
  44.    
  45.     CreateConVar("l4d2_dwp_version", PLUGIN_VERSION, "Version of [L4D2] Drop weapon when punched", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  46.     HookEvent("round_start", RoundR, EventHookMode_Pre);
  47.     HookEvent("round_end", RoundR, EventHookMode_Pre);
  48.     HookEvent("tank_spawn", TankSpawned);
  49.     HookEvent("player_hurt", PlayerHit);
  50.     HookEvent("tank_killed", TankKilled);
  51.     HookEvent("player_incapacitated_start", PlayerIncapped);
  52.     HookEvent("item_pickup", Event_Pickup);
  53.    
  54.     c_dwp_enabled = CreateConVar("l4d2_dwp_enabled", "1", "Is plugin enabled? 1=Yes, 0=No", CVAR_FLAGS);
  55.     c_dwp_drop_incapped = CreateConVar("l4d2_dwp_drop_when_incapped", "0", "Will you drop weapon if you get incapped? 1=Yes, 0=No", CVAR_FLAGS);
  56.     c_dwp_drop_melee = CreateConVar("l4d2_dwp_drop_melee", "1", "Will you drop melee weapon if you get hit? 1=Yes, 0=No", CVAR_FLAGS);
  57.     c_dwp_give_pistol = CreateConVar("l4d2_dwp_give_pistol", "1", "Will you get a pistol if you drop your melee weapon? 1=Yes, 0=No", CVAR_FLAGS);
  58.     c_dwp_drop_chainsaw = CreateConVar("l4d2_dwp_drop_chainsaw", "1", "Will you drop chainsaw if you get hit? 1=Yes, 0=No", CVAR_FLAGS);
  59.     AutoExecConfig(true, "l4d2_drop_when_punched");
  60. }
  61.  
  62. public Action:RoundR(Handle:event, String:event_name[], bool:dontBroadcast)
  63. {
  64.     TanksInGame = 0;
  65. }
  66.  
  67. public Action:TankSpawned(Handle:event, String:event_name[], bool:dontBroadcast)
  68. {
  69.     TanksInGame++;
  70. }
  71.  
  72. public Action:TankKilled(Handle:event, String:event_name[], bool:dontBroadcast)
  73. {
  74.     TanksInGame--;
  75.     if (TanksInGame == 0)
  76.     {
  77.         new client = Misc_GetAnyClient();
  78.         if (client > 0)
  79.         {
  80.             for (new i = 1; i <= MaxClients; i++)
  81.             {
  82.                 if (IsClientInGame(i) && GetClientTeam(i) == 2)
  83.                 {
  84.                     GivenGun[i] = 0;
  85.                 }
  86.             }
  87.         }
  88.     }
  89. }
  90.  
  91. Misc_GetAnyClient()
  92. {
  93.     for (new i = 1; i <= MaxClients; i++)
  94.     {
  95.         if (IsClientInGame(i))
  96.         {
  97.             return i;
  98.         }
  99.     }
  100.     return 0;
  101. }
  102.  
  103. public Action:PlayerHit(Handle:event, String:event_name[], bool:dontBroadcast)
  104. {
  105.     if (TanksInGame != 0)
  106.     {
  107.         if (GetConVarBool(c_dwp_enabled))
  108.         {
  109.             new client = GetClientOfUserId(GetEventInt(event,"userid"));
  110.             new attacker = GetClientOfUserId(GetEventInt(event,"attacker"));
  111.             if (IsValidClient(attacker) && GetClientTeam(client) == 2 && IsPlayerTank(attacker))
  112.             {
  113.                 if (!(GetEntProp(client, Prop_Send, "m_isIncapacitated", 1)))
  114.                 {
  115.                     DropWep(client);
  116.                 }
  117.             }
  118.         }
  119.     }
  120. }
  121.  
  122. public Action:PlayerIncapped(Handle:event, String:event_name[], bool:dontBroadcast)
  123. {
  124.     if (TanksInGame != 0)
  125.     {
  126.         if (GetConVarBool(c_dwp_enabled))
  127.         {
  128.             new client = GetClientOfUserId(GetEventInt(event,"userid"));
  129.             new attacker = GetClientOfUserId(GetEventInt(event,"attacker"));
  130.             if(IsValidClient(attacker) && GetClientTeam(client) == 2 && IsPlayerTank(attacker))
  131.             {
  132.                 if (GetConVarBool(c_dwp_drop_incapped)) DropWep(client);
  133.             }
  134.         }
  135.     }
  136. }
  137.  
  138. public Action:Event_Pickup(Handle:event, const String:name[], bool:dontBroadcast)
  139. {
  140.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  141.     if (GivenGun[client] == 1)
  142.     {
  143.         new String:weapon[32];
  144.         GetClientWeapon(client, weapon, 32);
  145.        
  146.         if (StrEqual(weapon, "weapon_melee") || StrEqual(weapon, "weapon_chainsaw") || StrEqual(weapon, "weapon_pistol_magnum"))
  147.         {
  148.             new ent22 = -1;
  149.             new prev22 = 0;
  150.             while ((ent22 = FindEntityByClassname(ent22, "weapon_pistol")) != -1)
  151.             {
  152.                 if (prev22) RemoveEdict(prev22);
  153.                 prev22 = ent22;
  154.             }
  155.             if (prev22) RemoveEdict(prev22);
  156.             GivenGun[client] = 0;
  157.         }  
  158.     }
  159. }
  160.  
  161. public Action:GivePistol(client)
  162. {
  163.     new flags = GetCommandFlags("give");
  164.     SetCommandFlags("give", flags & ~FCVAR_CHEAT);
  165.     FakeClientCommand(client, "give pistol");
  166.     SetCommandFlags("give", flags|FCVAR_CHEAT);
  167.     GivenGun[client] = 1;
  168. }
  169.  
  170. //The following code is from l4d2_drop, http://forums.alliedmods.net/showthread.php?p=1136497
  171. public Action:DropWep(client)
  172. {
  173.     if (client == 0 || GetClientTeam(client) != 2 || !IsPlayerAlive(client))
  174.         return Plugin_Handled;
  175.  
  176.     new String:weapon[32];
  177.     GetClientWeapon(client, weapon, 32);
  178.  
  179.     if (StrEqual(weapon, "weapon_pumpshotgun") || StrEqual(weapon, "weapon_autoshotgun") || StrEqual(weapon, "weapon_rifle") || StrEqual(weapon, "weapon_smg") || StrEqual(weapon, "weapon_hunting_rifle") || StrEqual(weapon, "weapon_sniper_scout") || StrEqual(weapon, "weapon_sniper_military") || StrEqual(weapon, "weapon_sniper_awp") || StrEqual(weapon, "weapon_smg_silenced") || StrEqual(weapon, "weapon_smg_mp5") || StrEqual(weapon, "weapon_shotgun_spas") || StrEqual(weapon, "weapon_shotgun_chrome") || StrEqual(weapon, "weapon_rifle_sg552") || StrEqual(weapon, "weapon_rifle_desert") || StrEqual(weapon, "weapon_rifle_ak47") || StrEqual(weapon, "weapon_grenade_launcher") || StrEqual(weapon, "weapon_rifle_m60"))
  180.         DropSlot(client, 0);
  181.     else if (!(GetEntProp(client, Prop_Send, "m_isIncapacitated", 1)))
  182.     {
  183.         if (GetConVarBool(c_dwp_drop_melee))
  184.         {
  185.             if (StrEqual(weapon, "weapon_melee"))
  186.             {
  187.                 DropSlot(client, 1);
  188.                 if (GetConVarBool(c_dwp_give_pistol))
  189.                     GivePistol(client);
  190.             }
  191.         }
  192.         if (GetConVarBool(c_dwp_drop_chainsaw))
  193.         {
  194.             if (StrEqual(weapon, "weapon_chainsaw"))
  195.             {
  196.                 DropSlot(client, 1);
  197.                 if (GetConVarBool(c_dwp_give_pistol))
  198.                     GivePistol(client);
  199.             }
  200.         }
  201.     }
  202.  
  203.     return Plugin_Handled;
  204. }
  205.  
  206. public DropSlot(client, slot)
  207. {
  208.     if (GetPlayerWeaponSlot(client, slot) > 0)
  209.     {
  210.         new String:weapon[32];
  211.         new ammo;
  212.         new clip;
  213.         new upgrade;
  214.         new upammo;
  215.         new ammoOffset = FindSendPropInfo("CTerrorPlayer", "m_iAmmo");
  216.         GetEdictClassname(GetPlayerWeaponSlot(client, slot), weapon, 32);
  217.  
  218.         if (slot == 0)
  219.         {
  220.             clip = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_iClip1");
  221.             upgrade = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_upgradeBitVec");
  222.             upammo = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_nUpgradedPrimaryAmmoLoaded");
  223.             if (StrEqual(weapon, "weapon_rifle") || StrEqual(weapon, "weapon_rifle_sg552") || StrEqual(weapon, "weapon_rifle_desert") || StrEqual(weapon, "weapon_rifle_ak47"))
  224.             {
  225.                 ammo = GetEntData(client, ammoOffset+(12));
  226.                 SetEntData(client, ammoOffset+(12), 0);
  227.             }
  228.             else if (StrEqual(weapon, "weapon_smg") || StrEqual(weapon, "weapon_smg_silenced") || StrEqual(weapon, "weapon_smg_mp5"))
  229.             {
  230.                 ammo = GetEntData(client, ammoOffset+(20));
  231.                 SetEntData(client, ammoOffset+(20), 0);
  232.             }
  233.             else if (StrEqual(weapon, "weapon_pumpshotgun") || StrEqual(weapon, "weapon_shotgun_chrome"))
  234.             {
  235.                 ammo = GetEntData(client, ammoOffset+(28));
  236.                 SetEntData(client, ammoOffset+(28), 0);
  237.             }
  238.             else if (StrEqual(weapon, "weapon_autoshotgun") || StrEqual(weapon, "weapon_shotgun_spas"))
  239.             {
  240.                 ammo = GetEntData(client, ammoOffset+(32));
  241.                 SetEntData(client, ammoOffset+(32), 0);
  242.             }
  243.             else if (StrEqual(weapon, "weapon_hunting_rifle"))
  244.             {
  245.                 ammo = GetEntData(client, ammoOffset+(36));
  246.                 SetEntData(client, ammoOffset+(36), 0);
  247.             }
  248.             else if (StrEqual(weapon, "weapon_sniper_scout") || StrEqual(weapon, "weapon_sniper_military") || StrEqual(weapon, "weapon_sniper_awp"))
  249.             {
  250.                 ammo = GetEntData(client, ammoOffset+(40));
  251.                 SetEntData(client, ammoOffset+(40), 0);
  252.             }
  253.             else if (StrEqual(weapon, "weapon_grenade_launcher"))
  254.             {
  255.                 ammo = GetEntData(client, ammoOffset+(68));
  256.                 SetEntData(client, ammoOffset+(68), 0);
  257.             }
  258.         }
  259.         new index = CreateEntityByName(weapon);
  260.         new Float:origin[3];
  261.         GetEntPropVector(client, Prop_Send, "m_vecOrigin", origin);
  262.         origin[2]+=20;
  263.         TeleportEntity(index, origin, NULL_VECTOR, NULL_VECTOR);
  264.  
  265.         if (slot == 1)
  266.         {
  267.             if (StrEqual(weapon, "weapon_melee"))
  268.             {
  269.                 new String:item[150];
  270.                 GetEntPropString(GetPlayerWeaponSlot(client, 1), Prop_Data, "m_ModelName", item, sizeof(item));
  271.                 //PrintToChat(client, "%s", item);
  272.                 if (StrEqual(item, MODEL_V_FIREAXE))
  273.                 {
  274.                     DispatchKeyValue(index, "model", MODEL_V_FIREAXE);
  275.                     DispatchKeyValue(index, "melee_script_name", "fireaxe")
  276. ;
  277.                 }
  278.                 else if (StrEqual(item, MODEL_V_FRYING_PAN))
  279.                 {
  280.                     DispatchKeyValue(index, "model", MODEL_V_FRYING_PAN);
  281.                     DispatchKeyValue(index, "melee_script_name", "frying_pan")
  282. ;
  283.                 }
  284.                 else if (StrEqual(item, MODEL_V_MACHETE))
  285.                 {
  286.                     DispatchKeyValue(index, "model", MODEL_V_MACHETE);
  287.                     DispatchKeyValue(index, "melee_script_name", "machete")
  288. ;
  289.                 }
  290.                 else if (StrEqual(item, MODEL_V_BASEBALL_BAT))
  291.                 {
  292.                     DispatchKeyValue(index, "model", MODEL_V_BASEBALL_BAT);
  293.                     DispatchKeyValue(index, "melee_script_name", "baseball_bat")
  294. ;
  295.                 }
  296.                 else if (StrEqual(item, MODEL_V_CROWBAR))
  297.                 {
  298.                     DispatchKeyValue(index, "model", MODEL_V_CROWBAR);
  299.                     DispatchKeyValue(index, "melee_script_name", "crowbar")
  300. ;
  301.                 }
  302.                 else if (StrEqual(item, MODEL_V_CRICKET_BAT))
  303.                 {
  304.                     DispatchKeyValue(index, "model", MODEL_V_CRICKET_BAT);
  305.                     DispatchKeyValue(index, "melee_script_name", "cricket_bat")
  306. ;
  307.                 }
  308.                 else if (StrEqual(item, MODEL_V_TONFA))
  309.                 {
  310.                     DispatchKeyValue(index, "model", MODEL_V_TONFA);
  311.                     DispatchKeyValue(index, "melee_script_name", "tonfa")
  312. ;
  313.                 }
  314.                 else if (StrEqual(item, MODEL_V_KATANA))
  315.                 {
  316.                     DispatchKeyValue(index, "model", MODEL_V_KATANA);
  317.                     DispatchKeyValue(index, "melee_script_name", "katana")
  318. ;
  319.                 }
  320.                 else if (StrEqual(item, MODEL_V_ELECTRIC_GUITAR))
  321.                 {
  322.                     DispatchKeyValue(index, "model", MODEL_V_ELECTRIC_GUITAR);
  323.                     DispatchKeyValue(index, "melee_script_name", "electric_guitar")
  324. ;
  325.                 }
  326.                 else if (StrEqual(item, MODEL_V_GOLFCLUB))
  327.                 {
  328.                     DispatchKeyValue(index, "model", MODEL_V_GOLFCLUB);
  329.                     DispatchKeyValue(index, "melee_script_name", "golfclub")
  330. ;
  331.                 }
  332.             }
  333.             else if (StrEqual(weapon, "weapon_chainsaw"))
  334.             {
  335.                 clip = GetEntProp(GetPlayerWeaponSlot(client, 1), Prop_Send, "m_iClip1");
  336.             }
  337.         }
  338.  
  339.         DispatchSpawn(index);
  340.         ActivateEntity(index);
  341.         RemovePlayerItem(client, GetPlayerWeaponSlot(client, slot));
  342.  
  343.         if (slot == 0)
  344.         {
  345.             SetEntProp(index, Prop_Send, "m_iExtraPrimaryAmmo", ammo);
  346.             SetEntProp(index, Prop_Send, "m_iClip1", clip);
  347.             SetEntProp(index, Prop_Send, "m_upgradeBitVec", upgrade);
  348.             SetEntProp(index, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", upammo);
  349.         }
  350.  
  351.         if (slot == 1)
  352.         {
  353.             if (StrEqual(weapon, "weapon_chainsaw"))
  354.             {
  355.                 SetEntProp(index, Prop_Send, "m_iClip1", clip);
  356.             }
  357.         }
  358.     }
  359. }
  360.  
  361. public IsValidClient(i) // code from Mortiegama
  362. {
  363.     if (i == 0)
  364.         return false;
  365.  
  366.     if (!IsClientConnected(i))
  367.         return false;
  368.    
  369.     if (!IsClientInGame(i))
  370.         return false;
  371.    
  372.     if (!IsPlayerAlive(i))
  373.         return false;
  374.  
  375.     if (!IsValidEntity(i))
  376.         return false;
  377.  
  378.     return true;
  379. }
  380.  
  381. stock bool:IsPlayerTank(i) // code from Mecha the Slag
  382. {
  383.     new String:model[128];
  384.     GetClientModel(i, model, sizeof(model));
  385.     if (StrContains(model, "hulk", false) <= 0)  return false;
  386.     return true;
  387. }
Advertisement
Add Comment
Please, Sign In to add comment