Guest User

Untitled

a guest
Apr 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.94 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3.  
  4. #pragma semicolon 1
  5.  
  6. #define MAX_CLIENTS 52
  7. #define TEAM_PRISONERS 2
  8.  
  9. new Handle:hRadius = INVALID_HANDLE;
  10. new Handle:hMagnitude = INVALID_HANDLE;
  11.  
  12. new iExplosion = -1;
  13. new bool:bHasBomb[MAX_CLIENTS + 1];
  14.  
  15. public OnPluginStart()
  16. {
  17.     hRadius = CreateConVar("jjk_bomb_radius",
  18.                             "250", "Radius of bomb explosion");
  19.  
  20.     hMagnitude = CreateConVar("jjk_bomb_magnitude", "200",
  21.                                 "Magnitude of the bomb explosion");
  22.  
  23.     HookEvent("round_start", round_start);
  24.     HookEvent("player_death", player_death);
  25.     HookEvent("item_pickup", item_pickup);
  26.  
  27.     AddFileToDownloadsTable("sound/crosshair/rebelyell.wav");
  28.  
  29.     PrecacheSound("crosshair/rebelyell.wav");
  30.     AutoExecConfig(true, "bomb");
  31. }
  32.  
  33. public OnMapStart()
  34. {
  35.     PrecacheSound("crosshair/rebelyell.wav");
  36. }
  37.  
  38. public Action:OnClientCommand(client, args)
  39. {
  40.     decl String:command[8];
  41.     decl String:weapon[10];
  42.  
  43.     GetClientWeapon(client, weapon, sizeof(weapon));
  44.     GetCmdArg(0, command, sizeof(command));
  45.  
  46.     if (StrEqual("drop", command, false) && StrEqual("weapon_c4", weapon)) {
  47.         explodePlayer(client);
  48.     }
  49. }
  50.  
  51. public round_start(Handle:event, const String:name[], bool:dontBroadcast)
  52. {
  53.     CreateTimer(0.1, giveBomb);
  54. }
  55.  
  56. public Action:giveBomb(Handle:timer)
  57. {
  58.     new iClientCount;
  59.     decl iClients[MAX_CLIENTS];
  60.  
  61.     for (new i = 1; i <= MAX_CLIENTS; i++) {
  62.         bHasBomb[i] = false;
  63.         if (IsClientInGame(i) && GetClientTeam(i) == TEAM_PRISONERS)
  64.             iClients[iClientCount++] = i;
  65.     }
  66.  
  67.     new client = iClients[GetRandomInt(0, iClientCount - 1)];
  68.     GivePlayerItem(client, "weapon_c4");
  69. }
  70.  
  71. public item_pickup(Handle:event, const String:name[], bool:dontBroadcast)
  72. {
  73.     decl String:sWeapon[32];
  74.     GetEventString(event, "item", sWeapon, sizeof(sWeapon));
  75.  
  76.     if (StrEqual(sWeapon, "c4"))
  77.         bHasBomb[GetClientOfUserId(GetEventInt(event, "userid"))] = true;
  78. }
  79.  
  80. public player_death(Handle:event, const String:name[], bool:dontBroascast)
  81. {
  82.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  83.     if (bHasBomb[client])
  84.         explodePlayer(client);
  85. }
  86.  
  87. stock explodePlayer(client)
  88. {
  89.     new iMagnitude = GetConVarInt(hMagnitude);
  90.     new iRadius = GetConVarInt(hRadius);
  91.     new index = GetPlayerWeaponSlot(client, 4);
  92.  
  93.     if (index == -1) {
  94.         while ((index = FindEntityByClassname(index, "weapon_c4")) != -1)
  95.             if (GetEntProp(index, Prop_Send, "m_hOwnerEntity") == -1)
  96.                 break;
  97.     }
  98.  
  99.     AcceptEntityInput(index, "kill");
  100.     EmitSoundToAll("crosshair/rebelyell.wav");
  101.  
  102.     decl Float:loc[3];
  103.     GetClientEyePosition(client, loc);
  104.  
  105.     for (new i = 1; i < MaxClients; i++) {
  106.         if (!IsClientInGame(i))
  107.             continue;
  108.  
  109.         //FakeClientCommandEx(i, "play crosshair/rebelyell.wav");
  110.         FakeClientCommand(i, "play crosshair/rebelyell.wav");
  111.  
  112.         decl Float:tempLoc[3];
  113.         GetClientAbsOrigin(i, tempLoc);
  114.  
  115.         /* The player is within the range of the bomb, slap them */
  116.         if (Pow(Pow(loc[0] - tempLoc[0], 2.0) +
  117.                 Pow(loc[1] - tempLoc[1], 2.0) +
  118.                 Pow(loc[2] - tempLoc[2], 2.0), 0.5) < iRadius)
  119.  
  120.             SlapPlayer(i, 0, false);
  121.     }
  122.  
  123.     decl String:magnitude[8];
  124.     decl String:radius[8];
  125.  
  126.     IntToString(iMagnitude, magnitude, sizeof(magnitude));
  127.     IntToString(iRadius, radius, sizeof(radius));
  128.  
  129.     iExplosion = CreateEntityByName("env_explosion");
  130.     bHasBomb[client] = false;
  131.  
  132.     if (iExplosion > 0) {
  133.  
  134.         DispatchKeyValueVector(iExplosion, "Origin", loc);
  135.         SetEntPropEnt(iExplosion, Prop_Send, "m_hOwnerEntity", client);
  136.  
  137.         DispatchKeyValue(iExplosion, "iMagnitude", magnitude);
  138.         DispatchKeyValue(iExplosion, "iRadiusOverride", radius);
  139.  
  140.         AcceptEntityInput(iExplosion, "Explode");
  141.         AcceptEntityInput(iExplosion, "Kill");
  142.     }
  143. }
Add Comment
Please, Sign In to add comment