Advertisement
FlacoBey

Untitled

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