Advertisement
FlacoBey

Untitled

Jun 17th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.00 KB | None | 0 0
  1. #pragma semicolon 1
  2. #pragma newdecls required
  3.  
  4. #include <sdktools>
  5. #include <sdkhooks>
  6.  
  7. int viTimerDude[MAXPLAYERS+1], pipebomb[MAXPLAYERS+1];
  8. Handle vTimerPipe[MAXPLAYERS+1], sdkKillPipe, sdkActivatePipe;
  9. ConVar iTimerPipeBomb;
  10. bool vSwitch[MAXPLAYERS+1];
  11. Handle gTimer;
  12.  
  13. // ====================================================================================================
  14. //                PLUGIN INFO / START / END / CVARS
  15. // ====================================================================================================
  16.  
  17. public Plugin myinfo =
  18. {
  19.     name = "[L4D2] Realistico",
  20.     author = "BHaType",
  21.     description = "Makes pipe bomb more real.",
  22.     version = "1.9.1",
  23.     url = "https://steamcommunity.com/profiles/76561198865209991/"
  24. }
  25.  
  26. public void OnPluginStart()
  27. {
  28.     Handle hGameConf = LoadGameConfigFile("Realistico.GameData");
  29.     StartPrepSDKCall(view_as<SDKCallType>(1));
  30.     if (!(PrepSDKCall_SetFromConf(hGameConf, view_as<SDKFuncConfSource>(1), "iDetonatePipeBomb")))
  31.         SetFailState("Could not load the \"iDetonatePipeBomb\" gamedata signature.");
  32.     sdkKillPipe = EndPrepSDKCall();
  33.  
  34.     StartPrepSDKCall(SDKCall_Static);
  35.     if ( PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "CPipeBombProjectile_Create") == false )
  36.         SetFailState("Could not load the \"CPipeBombProjectile_Create\" gamedata signature.");
  37.     PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
  38.     PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
  39.     PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
  40.     PrepSDKCall_AddParameter(SDKType_Vector, SDKPass_ByRef);
  41.     PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer);
  42.     PrepSDKCall_AddParameter(SDKType_Float, SDKPass_Plain);
  43.     PrepSDKCall_SetReturnInfo(SDKType_CBaseEntity, SDKPass_Pointer);
  44.     sdkActivatePipe = EndPrepSDKCall();
  45.     if ( sdkActivatePipe == null )
  46.         SetFailState("Could not prep the \"CPipeBombProjectile_Create\" function.");
  47.     iTimerPipeBomb = FindConVar("pipe_bomb_timer_duration");
  48.     HookEvent("round_start", EventFire, EventHookMode_PostNoCopy);
  49. }
  50.  
  51. public Action EventFire(Handle event, const char[] name, bool dontbroadcast)
  52. {
  53.     for (int i = 1; i <= MaxClients; i++)
  54.     {
  55.         viTimerDude[i] = 0;
  56.         pipebomb[i] = 0;
  57.         vSwitch[i] = false;
  58.         if(vTimerPipe[i] != null)
  59.         {
  60.             KillTimer(vTimerPipe[i]);
  61.             vTimerPipe[i] = null;
  62.         }
  63.     }
  64.     if(gTimer != null)
  65.     {
  66.         KillTimer(gTimer);
  67.         gTimer = null;
  68.     }
  69. }
  70.  
  71.  
  72. public Action TimerOut(Handle timer)
  73. {
  74.     bool set;
  75.     for (int i = 1; i <= MaxClients; i++)
  76.     {
  77.         if (IsClientInGame(i) && viTimerDude[i] > 0)
  78.         {
  79.             viTimerDude[i]--;
  80.             PrintHintText(i, "Time to detonate %d", viTimerDude[i]);
  81.             set = true;
  82.         }
  83.     }
  84.  
  85.     if( !set )
  86.     {
  87.         gTimer = null;
  88.         return Plugin_Stop;
  89.     }
  90.     return Plugin_Continue;
  91. }
  92.  
  93. // ====================================================================================================
  94. //                Plugin / Hooks
  95. // ====================================================================================================
  96.  
  97.  
  98. public void OnClientPutInServer(int client)
  99. {
  100.     SDKHook(client, SDKHook_WeaponCanSwitchTo, WeaponSwitch);
  101. }
  102.  
  103. public Action WeaponSwitch(int client, int deleted)
  104. {
  105.     if(vSwitch[client])
  106.     {
  107.         int iPipe = GetPlayerWeaponSlot(client, 2);
  108.         if(!IsValidEntity(iPipe))
  109.             return Plugin_Continue;
  110.        
  111.         char sWeaponEx[32];
  112.         GetEntityClassname(iPipe, sWeaponEx, sizeof(sWeaponEx));
  113.         if(strcmp(sWeaponEx, "weapon_pipe_bomb") == 0)
  114.         {
  115.             RemovePlayerItem(client, iPipe);
  116.             AcceptEntityInput(iPipe, "Kill");
  117.    
  118.             float vAng[3], vPos[3];
  119.             GetEntPropVector(client, Prop_Send, "m_vecOrigin", vPos);
  120.             vPos[2] += 40.0;
  121.             int entity = SDKCall(sdkActivatePipe, vPos, vAng, vAng, vAng, client, 2.0);
  122.             CreateTimer(viTimerDude[client] * 1.0, vDropPipeBomb, EntIndexToEntRef(entity));
  123.             return Plugin_Continue;
  124.         }
  125.     }
  126.     return Plugin_Continue;
  127. }
  128.  
  129. public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon)
  130. {
  131.     if (vTimerPipe[client] == null)
  132.     {
  133.         int iCurrentWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  134.  
  135.         if (!IsValidEntity(iCurrentWeapon))
  136.             return Plugin_Continue;
  137.  
  138.         char weaponclass[32];
  139.         GetEntityClassname(iCurrentWeapon, weaponclass, sizeof(weaponclass));
  140.         if (buttons & IN_ATTACK)
  141.         {
  142.             if (strcmp(weaponclass, "weapon_pipe_bomb") == 0)
  143.             {
  144.                 vSwitch[client] = true;
  145.                 viTimerDude[client] = iTimerPipeBomb.IntValue;
  146.                 vTimerPipe[client] = CreateTimer(viTimerDude[client] * 1.0, timerpipe, client);
  147.                 if( gTimer == null )
  148.                     gTimer = CreateTimer(1.0, TimerOut, _, TIMER_REPEAT);
  149.             }
  150.         }
  151.     }
  152.     else
  153.     {
  154.         if (!(buttons & IN_ATTACK))
  155.         {
  156.             vSwitch[client] = false;
  157.             CreateTimer(viTimerDude[client] * 1.0, TimerBomb, client);
  158.         }
  159.     }
  160.     return Plugin_Continue;
  161. }
  162.  
  163. public Action vDropPipeBomb(Handle timer, any ref)
  164. {
  165.     int entity = EntRefToEntIndex(ref);
  166.     if(IsValidEntity(ref))
  167.         SDKCall(sdkKillPipe, entity);
  168. }
  169.  
  170. public Action TimerBomb(Handle timer, int client)
  171. {
  172.     if (IsValidEntRef(pipebomb[client]))
  173.     {
  174.         int entity = EntRefToEntIndex(pipebomb[client]);
  175.         SDKCall(sdkKillPipe, entity);
  176.     }
  177. }
  178.  
  179. public Action timerpipe(Handle timer, int client)
  180. {
  181.     int iPipe = GetPlayerWeaponSlot(client, 2);
  182.     if (IsValidEntity(iPipe))
  183.     {
  184.         RemovePlayerItem(client, iPipe);
  185.         AcceptEntityInput(iPipe, "Kill");
  186.     }
  187.     ForcePlayerSuicide(client);
  188.     float vPos[3];
  189.     GetEntPropVector(client, Prop_Send, "m_vecOrigin", vPos);
  190.     vPos[2] += 40.0;
  191.     int entity = CreateEntityByName("prop_physics");
  192.     if(IsValidEntity(entity))
  193.     {
  194.         DispatchKeyValue(entity, "model", "models/props_junk/propanecanister001a.mdl");
  195.         DispatchSpawn(entity);
  196.         TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
  197.         AcceptEntityInput(entity, "break");
  198.     }
  199. }
  200.  
  201. public void OnEntityCreated(int entity, const char[] class)
  202. {
  203.     if (strcmp(class, "pipe_bomb_projectile") == 0)
  204.     {
  205.         SDKHook(entity, SDKHook_SpawnPost, SpawnPost);
  206.     }
  207. }
  208.  
  209. public void SpawnPost(int entity)
  210. {
  211.     RequestFrame(nextFrame, EntIndexToEntRef(entity));
  212. }
  213.  
  214. public void nextFrame(int entity)
  215. {
  216.     if( (entity = EntRefToEntIndex(entity)) != INVALID_ENT_REFERENCE )
  217.     {
  218.         int client;
  219.         if ((client = GetEntPropEnt(entity, Prop_Data, "m_hThrower")) > 0 && IsClientInGame(client))
  220.         {
  221.             pipebomb[client] = EntIndexToEntRef(entity);
  222.         }
  223.     }
  224. }
  225.  
  226. public Action OnHeSpawned(Handle timer, any ent)
  227. {
  228.     int client;
  229.     if ((ent = EntRefToEntIndex(ent)) > 0 && (client = GetEntPropEnt(ent, Prop_Data, "m_hThrower")) > 0 && IsClientInGame(client))
  230.     {
  231.         pipebomb[client] = EntIndexToEntRef(ent);
  232.     }
  233. }
  234.  
  235. // ====================================================================================================
  236. //                Stocks
  237. // ====================================================================================================
  238.  
  239. bool IsValidEntRef(int iEnt)
  240. {
  241.     if (iEnt && EntRefToEntIndex(iEnt) != INVALID_ENT_REFERENCE)
  242.         return true;
  243.     return false;
  244. }
  245.  
  246. stock bool bIsSurvivor(int client)
  247. {
  248.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && IsPlayerAlive(client);
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement