Advertisement
Guest User

Untitled

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