FlacoBey

Untitled

Jun 17th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.24 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_end", 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(float(viTimerDude[client]), 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(float(viTimerDude[client]), 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.             KillTimer(vTimerPipe[client]);
  157.             vTimerPipe[client] = null;
  158.             vSwitch[client] = false;
  159.             CreateTimer(float(viTimerDude[client]), TimerBomb, client);
  160.         }
  161.     }
  162.     return Plugin_Continue;
  163. }
  164.  
  165. public Action vDropPipeBomb(Handle timer, any ref)
  166. {
  167.     int entity = EntRefToEntIndex(ref);
  168.     if(IsValidEntity(entity))
  169.         SDKCall(sdkKillPipe, entity);
  170. }
  171.  
  172. public Action TimerBomb(Handle timer, int client)
  173. {
  174.     client = GetClientUserId(client);
  175.     if(!client || !IsClientInGame(client)) return;
  176.     if (IsValidEntRef(pipebomb[client]))
  177.     {
  178.         int entity = EntRefToEntIndex(pipebomb[client]);
  179.         SDKCall(sdkKillPipe, entity);
  180.     }
  181. }
  182.  
  183. public Action timerpipe(Handle timer, int client)
  184. {
  185.     client = GetClientUserId(client);
  186.     if(!client || !IsClientInGame(client)) return;
  187.     int iPipe = GetPlayerWeaponSlot(client, 2);
  188.     if (IsValidEntity(iPipe))
  189.     {
  190.         RemovePlayerItem(client, iPipe);
  191.         AcceptEntityInput(iPipe, "Kill");
  192.     }
  193.     ForcePlayerSuicide(client);
  194.     float vPos[3];
  195.     GetEntPropVector(client, Prop_Send, "m_vecOrigin", vPos);
  196.     vPos[2] += 40.0;
  197.     int entity = CreateEntityByName("prop_physics");
  198.     if(IsValidEntity(entity))
  199.     {
  200.         DispatchKeyValue(entity, "model", "models/props_junk/propanecanister001a.mdl");
  201.         DispatchSpawn(entity);
  202.         TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
  203.         AcceptEntityInput(entity, "break");
  204.     }
  205. }
  206.  
  207. public void OnEntityCreated(int entity, const char[] class)
  208. {
  209.     if (strcmp(class, "pipe_bomb_projectile") == 0)
  210.     {
  211.         SDKHook(entity, SDKHook_SpawnPost, SpawnPost);
  212.     }
  213. }
  214.  
  215. public void SpawnPost(int entity)
  216. {
  217.     RequestFrame(nextFrame, EntIndexToEntRef(entity));
  218. }
  219.  
  220. public void nextFrame(int entity)
  221. {
  222.     if( (entity = EntRefToEntIndex(entity)) != INVALID_ENT_REFERENCE )
  223.     {
  224.         int client;
  225.         if ((client = GetEntPropEnt(entity, Prop_Data, "m_hThrower")) > 0 && IsClientInGame(client))
  226.         {
  227.             pipebomb[client] = EntIndexToEntRef(entity);
  228.         }
  229.     }
  230. }
  231.  
  232. public Action OnHeSpawned(Handle timer, any ent)
  233. {
  234.     int client;
  235.     if ((ent = EntRefToEntIndex(ent)) > 0 && (client = GetEntPropEnt(ent, Prop_Data, "m_hThrower")) > 0 && IsClientInGame(client))
  236.     {
  237.         pipebomb[client] = EntIndexToEntRef(ent);
  238.     }
  239. }
  240.  
  241. // ====================================================================================================
  242. //                Stocks
  243. // ====================================================================================================
  244.  
  245. bool IsValidEntRef(int iEnt)
  246. {
  247.     if (iEnt && EntRefToEntIndex(iEnt) != INVALID_ENT_REFERENCE)
  248.         return true;
  249.     return false;
  250. }
  251.  
  252. stock bool bIsSurvivor(int client)
  253. {
  254.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && IsPlayerAlive(client);
  255. }
Advertisement
Add Comment
Please, Sign In to add comment