Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.61 KB | None | 0 0
  1. #define PLUGIN_VERSION "1.6y"
  2.  
  3. /*=======================================================================================
  4. Plugin Info:
  5.  
  6. * Name : [L4D2] Fireworks Party
  7. * Author : SilverShot (idea by jjjapan) Crate Spawn mod by YoNer
  8. * Descrp : Adds fireworks to the firework crate explosions.
  9. * Link : http://forums.alliedmods.net/showthread.php?t=153783
  10.  
  11. ========================================================================================
  12. Change Log:
  13.  
  14. 1.6y (03-03-2017)
  15. - Added sm_fxbow command to manually spawn crates
  16. - Improved spawn position code
  17.  
  18. 1.6 (10-May-2012)
  19. - Added cvar "l4d2_fireworks_modes" to control which game modes the plugin works in.
  20. - Added cvar "l4d2_fireworks_modes_off" same as above.
  21. - Added cvar "l4d2_fireworks_modes_tog" same as above.
  22. - Optimized the plugin by hooking cvar changes.
  23. - Fixed a bug which could cause a server to lock up.
  24. - Removed max entity check and related error logging.
  25.  
  26. 1.5 (22-May-2011)
  27. - Added check for scavenge items to disable converting of gascans.
  28. - Added check to not spawn fireworks when GetEntityCount reaches MAX_ENTITIES.
  29. - Added 6 second delay after the first player spawns or round_start to convert items to firework crates.
  30. - Changed cvar defaults for "l4d2_fireworks_convert_propane", "l4d2_fireworks_convert_oxygen", "l4d2_fireworks_convert_gas" to "50".
  31. - Changed cvar default for "l4d2_fireworks_chase" from 10 to 15.
  32. - Changed cvar default for "l4d2_fireworks_allow_gas" from 1 to 0.
  33.  
  34. 1.4 (18-May-2011)
  35. - Added cvar "l4d2_fireworks_chase" - which controls how long zombies are attracted to firework explosions.
  36.  
  37. 1.3 (10-Apr-2011)
  38. - Added admin command "sm_fw" or "sm_fireworks" to spawn fireworks on crosshair position.
  39.  
  40. 1.2 (03-Apr-2011)
  41. - Added cvar "l4d2_fireworks_allow_gas" to display fireworks on gascan explosions.
  42. - Added cvar "l4d2_fireworks_allow_oxygen" to display fireworks on oxygen tank explosions.
  43. - Added cvar "l4d2_fireworks_allow_propane" to display fireworks on propane tank explosions.
  44. - Added cvar "l4d2_fireworks_convert_oxygen" to convert a percentage of oxygen tanks into firework crates.
  45. - Added cvar "l4d2_fireworks_convert_propane" to convert a percentage of propane tanks into firework crates.
  46.  
  47. 1.1 (02-Apr-2011)
  48. - Added cvar "l4d2_fireworks_convert_gas" to convert a percentage of gascans into firework crates.
  49. - Changed various default cvars and cvar limits.
  50.  
  51. 1.0 (29-Mar-2011)
  52. - Initial release.
  53.  
  54. ========================================================================================
  55.  
  56. This plugin was made using source code from the following plugins.
  57. If I have used your code and not credited you, please let me know.
  58.  
  59. * Thanks to "honorcode23" for PrecacheParticle()
  60.  
  61. * "Zuko & McFlurry" for "[L4D2] Weapon/Zombie Spawner" - Modified the SetTeleportEndPoint()
  62. http://forums.alliedmods.net/showthread.php?t=109659
  63.  
  64. ======================================================================================*/
  65.  
  66. #pragma semicolon 1
  67.  
  68. #include <sourcemod>
  69. #include <sdktools>
  70.  
  71. #define CVAR_FLAGS FCVAR_NOTIFY
  72. #define MAX_PARTICLES 50 // WARNING: excessive amounts of fireworks can crash the game!
  73.  
  74. #define MODEL_CRATE "models/props_junk/explosive_box001.mdl"
  75. #define MODEL_GASCAN "models/props_junk/gascan001a.mdl"
  76. #define MODEL_OXYGEN "models/props_equipment/oxygentank01.mdl"
  77. #define MODEL_PROPANE "models/props_junk/propanecanister001a.mdl"
  78.  
  79.  
  80. // Cvar handles
  81. static Handle:g_hCvarAllow, Handle:g_hCvarGas, Handle:g_hCvarOxy, Handle:g_hCvarPro, Handle:g_hCvarChase, Handle:g_hCvarInitMax, Handle:g_hCvarInitMin,
  82. Handle:g_hCvarModes, Handle:g_hCvarModesOff, Handle:g_hCvarModesTog, Handle:g_hCvarDelayMax, Handle:g_hCvarDelayMin, Handle:g_hCvarDelayRan,
  83. Handle:g_hCvarMaxTime, Handle:g_hCvarMinTime, Handle:g_hCvarType, Handle:g_hCvarConvert1, Handle:g_hCvarConvert2, Handle:g_hCvarConvert3,
  84.  
  85. bool:g_bCvarAllow, g_iCvarGas, g_iCvarOxy, g_iCvarPro, g_iCvarChase, g_iCvarInitMax, g_iCvarInitMin,
  86. g_iCvarDelayMax, g_iCvarDelayMin, g_iCvarDelayRan, Float:g_fCvarMaxTime, Float:g_fCvarMinTime, g_iCvarType,
  87. g_iCvarConvert1, g_iCvarConvert2, g_iCvarConvert3,
  88.  
  89. // Globals
  90. Handle:g_hMPGameMode, g_iParticleCount, Float:g_fLastPlayed, g_iPlayerSpawn, g_iRoundStart;
  91.  
  92.  
  93. // Firework types
  94. enum (<<=1)
  95. {
  96. TYPE_RED = 1,
  97. TYPE_BLUE,
  98. TYPE_GOLD,
  99. TYPE_FLASH
  100. }
  101.  
  102. static const String:g_sParticles[4][16] =
  103. {
  104. "fireworks_01",
  105. "fireworks_02",
  106. "fireworks_03",
  107. "fireworks_04"
  108. };
  109.  
  110. static const String:g_sSoundsLaunch[6][45] =
  111. {
  112. "ambient/atmosphere/firewerks_launch_01.wav",
  113. "ambient/atmosphere/firewerks_launch_02.wav",
  114. "ambient/atmosphere/firewerks_launch_03.wav",
  115. "ambient/atmosphere/firewerks_launch_04.wav",
  116. "ambient/atmosphere/firewerks_launch_05.wav",
  117. "ambient/atmosphere/firewerks_launch_06.wav"
  118. };
  119.  
  120. static const String:g_sSoundsBursts[4][45] =
  121. {
  122. "ambient/atmosphere/firewerks_burst_01.wav",
  123. "ambient/atmosphere/firewerks_burst_02.wav",
  124. "ambient/atmosphere/firewerks_burst_03.wav",
  125. "ambient/atmosphere/firewerks_burst_04.wav"
  126. };
  127.  
  128.  
  129.  
  130. // ====================================================================================================
  131. // EVENTS
  132. // ====================================================================================================
  133. // ====================================================================================================
  134. // PLUGIN INFO / START / END
  135. // ====================================================================================================
  136. public Plugin:myinfo =
  137. {
  138. name = "[L4D2] Fireworks Party",
  139. author = "SilverShot",
  140. description = "Adds fireworks to the firework crate explosions.",
  141. version = PLUGIN_VERSION,
  142. url = "http://forums.alliedmods.net/showthread.php?t=153783"
  143. }
  144.  
  145. public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
  146. {
  147. decl String:sGameName[12];
  148. GetGameFolderName(sGameName, sizeof(sGameName));
  149. if( strcmp(sGameName, "left4dead2", false) )
  150. {
  151. strcopy(error, err_max, "Plugin only supports Left 4 Dead 2.");
  152. return APLRes_SilentFailure;
  153. }
  154. return APLRes_Success;
  155. }
  156.  
  157. public OnPluginStart()
  158. {
  159. g_hCvarAllow = CreateConVar( "l4d2_fireworks_allow", "1", "0=Plugin off, 1=Plugin on.", CVAR_FLAGS);
  160. g_hCvarGas = CreateConVar( "l4d2_fireworks_allow_gas", "0", "Allow gascan explosions to display fireworks (only works on cans which have not been picked up).", CVAR_FLAGS);
  161. g_hCvarOxy = CreateConVar( "l4d2_fireworks_allow_oxygen", "0", "Allow oxygen tank explosions to display fireworks.", CVAR_FLAGS);
  162. g_hCvarPro = CreateConVar( "l4d2_fireworks_allow_propane", "0", "Allow propane tank explosions to display fireworks.", CVAR_FLAGS);
  163. g_hCvarChase = CreateConVar( "l4d2_fireworks_chase", "10", "0=Off. How long zombies are attracted to firework explosions.", CVAR_FLAGS, true, 0.0, true, 20.0);
  164. g_hCvarConvert1 = CreateConVar( "l4d2_fireworks_convert_gas", "50", "Percentage of gascans to convert into firework crates.", CVAR_FLAGS, true, 0.0, true, 100.0);
  165. g_hCvarConvert2 = CreateConVar( "l4d2_fireworks_convert_oxygen", "50", "Percentage of oxygen tanks to convert into firework crates.", CVAR_FLAGS, true, 0.0, true, 100.0);
  166. g_hCvarConvert3 = CreateConVar( "l4d2_fireworks_convert_propane", "50", "Percentage of propane tanks to convert into firework crates.", CVAR_FLAGS, true, 0.0, true, 100.0);
  167. g_hCvarDelayMax = CreateConVar( "l4d2_fireworks_delay_max", "10", "Maximum delayed fireworks to display (0 disables delayed).", CVAR_FLAGS, true, 0.0, true, 20.0);
  168. g_hCvarDelayMin = CreateConVar( "l4d2_fireworks_delay_min", "3", "Minimum delayed fireworks to display.", CVAR_FLAGS, true, 0.0, true, 10.0);
  169. g_hCvarDelayRan = CreateConVar( "l4d2_fireworks_delay_ran", "1", "Randomise how many delayed fireworks display. 0=Max, 1=Random.", CVAR_FLAGS, true, 0.0, true, 1.0);
  170. g_hCvarMaxTime = CreateConVar( "l4d2_fireworks_delay_time_max", "10.0", "Max time after explosion for delayed fireworks to be created.", CVAR_FLAGS, true, 2.0, true, 20.0);
  171. g_hCvarMinTime = CreateConVar( "l4d2_fireworks_delay_time_min", "0.2", "Min time after explosion before delayed fireworks can show.", CVAR_FLAGS, true, 0.1, true, 15.0);
  172. g_hCvarInitMax = CreateConVar( "l4d2_fireworks_init_max", "3", "Maximum fireworks to display on initial explosion (0 disables).", CVAR_FLAGS, true, 0.0, true, 10.0);
  173. g_hCvarInitMin = CreateConVar( "l4d2_fireworks_init_min", "0", "Minimum fireworks to display on initial explosion.", CVAR_FLAGS, true, 0.0, true, 10.0);
  174. g_hCvarModes = CreateConVar( "l4d2_fireworks_modes", "", "Turn on the plugin in these game modes, separate by commas (no spaces). (Empty = all).", CVAR_FLAGS );
  175. g_hCvarModesOff = CreateConVar( "l4d2_fireworks_modes_off", "", "Turn off the plugin in these game modes, separate by commas (no spaces). (Empty = none).", CVAR_FLAGS );
  176. g_hCvarModesTog = CreateConVar( "l4d2_fireworks_modes_tog", "0", "Turn on the plugin in these game modes. 0=All, 1=Coop, 2=Survival, 4=Versus, 8=Scavenge. Add numbers together.", CVAR_FLAGS );
  177. g_hCvarType = CreateConVar( "l4d2_fireworks_type", "15", "Which fireworks to display. Bit flags, add up the numbers. 1=Red; 2=Blue; 4=Gold; 8=Flash", CVAR_FLAGS);
  178. CreateConVar( "l4d2_fireworks_version", PLUGIN_VERSION, "Fireworks Party plugin version.", CVAR_FLAGS|FCVAR_REPLICATED|FCVAR_DONTRECORD);
  179. AutoExecConfig(true, "l4d2_fireworks_party");
  180.  
  181. g_hMPGameMode = FindConVar("mp_gamemode");
  182. HookConVarChange(g_hMPGameMode, ConVarChanged_Allow);
  183. HookConVarChange(g_hCvarAllow, ConVarChanged_Allow);
  184. HookConVarChange(g_hCvarModes, ConVarChanged_Allow);
  185. HookConVarChange(g_hCvarModesOff, ConVarChanged_Allow);
  186. HookConVarChange(g_hCvarModesTog, ConVarChanged_Allow);
  187. HookConVarChange(g_hCvarGas, ConVarChanged_Cvars);
  188. HookConVarChange(g_hCvarOxy, ConVarChanged_Cvars);
  189. HookConVarChange(g_hCvarPro, ConVarChanged_Cvars);
  190. HookConVarChange(g_hCvarChase, ConVarChanged_Cvars);
  191. HookConVarChange(g_hCvarInitMax, ConVarChanged_Cvars);
  192. HookConVarChange(g_hCvarInitMin, ConVarChanged_Cvars);
  193. HookConVarChange(g_hCvarDelayMax, ConVarChanged_Cvars);
  194. HookConVarChange(g_hCvarDelayMin, ConVarChanged_Cvars);
  195. HookConVarChange(g_hCvarDelayRan, ConVarChanged_Cvars);
  196. HookConVarChange(g_hCvarMaxTime, ConVarChanged_Cvars);
  197. HookConVarChange(g_hCvarMinTime, ConVarChanged_Cvars);
  198. HookConVarChange(g_hCvarType, ConVarChanged_Cvars);
  199. HookConVarChange(g_hCvarConvert1, ConVarChanged_Cvars);
  200. HookConVarChange(g_hCvarConvert2, ConVarChanged_Cvars);
  201. HookConVarChange(g_hCvarConvert3, ConVarChanged_Cvars);
  202.  
  203. RegConsoleCmd("sm_ph1", CmdFireworks, "bắn pháo hoa 1");
  204. RegConsoleCmd("sm_ph2", CmdFireworks, "bắn pháo hoa 2" );
  205. RegConsoleCmd("sm_hph", CmdCrate, "hộp pháo hoa" );
  206. }
  207.  
  208. public OnMapStart()
  209. {
  210. new i;
  211. for( i = 0; i <= 3; i++ ) PrecacheParticle(g_sParticles[i]);
  212. for( i = 0; i <= 3; i++ ) PrecacheSound(g_sSoundsBursts[i], true);
  213. for( i = 0; i <= 5; i++ ) PrecacheSound(g_sSoundsLaunch[i], true);
  214. PrecacheModel(MODEL_CRATE, true);
  215. }
  216.  
  217.  
  218.  
  219. // ====================================================================================================
  220. // CVARS
  221. // ====================================================================================================
  222. public OnConfigsExecuted()
  223. {
  224. GetCvars();
  225. IsAllowed();
  226. }
  227.  
  228. public ConVarChanged_Cvars(Handle:convar, const String:oldValue[], const String:newValue[])
  229. GetCvars();
  230.  
  231. public ConVarChanged_Allow(Handle:convar, const String:oldValue[], const String:newValue[])
  232. IsAllowed();
  233.  
  234. GetCvars()
  235. {
  236. g_iCvarGas = GetConVarInt(g_hCvarGas);
  237. g_iCvarOxy = GetConVarInt(g_hCvarOxy);
  238. g_iCvarPro = GetConVarInt(g_hCvarPro);
  239. g_iCvarChase = GetConVarInt(g_hCvarChase);
  240. g_iCvarInitMax = GetConVarInt(g_hCvarInitMax);
  241. g_iCvarInitMin = GetConVarInt(g_hCvarInitMin);
  242. g_iCvarDelayMax = GetConVarInt(g_hCvarDelayMax);
  243. g_iCvarDelayMin = GetConVarInt(g_hCvarDelayMin);
  244. g_iCvarDelayRan = GetConVarInt(g_hCvarDelayRan);
  245. g_fCvarMaxTime = GetConVarFloat(g_hCvarMaxTime);
  246. g_fCvarMinTime = GetConVarFloat(g_hCvarMinTime);
  247. g_iCvarType = GetConVarInt(g_hCvarType);
  248. g_iCvarConvert1 = GetConVarInt(g_hCvarConvert1);
  249. g_iCvarConvert2 = GetConVarInt(g_hCvarConvert2);
  250. g_iCvarConvert3 = GetConVarInt(g_hCvarConvert3);
  251. }
  252.  
  253. IsAllowed()
  254. {
  255. new bool:bCvarAllow = GetConVarBool(g_hCvarAllow);
  256. new bool:bAllowMode = IsAllowedGameMode();
  257.  
  258. if( g_bCvarAllow == false && bCvarAllow == true && bAllowMode == true )
  259. {
  260. g_bCvarAllow = true;
  261. HookEvents();
  262. }
  263.  
  264. else if( g_bCvarAllow == true && (bCvarAllow == false || bAllowMode == false) )
  265. {
  266. g_bCvarAllow = false;
  267. UnhookEvents();
  268. }
  269. }
  270.  
  271. bool:IsAllowedGameMode()
  272. {
  273. if( g_hMPGameMode == INVALID_HANDLE )
  274. return false;
  275.  
  276. // Get game mode cvars, if empty allow.
  277. decl String:sGameModes[64], String:sGameMode[64];
  278. GetConVarString(g_hCvarModes, sGameModes, sizeof(sGameModes));
  279. if( strlen(sGameModes) == 0 )
  280. return true;
  281.  
  282. // Better game mode check: ",versus," instead of "versus", which would return true for "teamversus" for example.
  283. GetConVarString(g_hMPGameMode, sGameMode, sizeof(sGameMode));
  284. Format(sGameModes, sizeof(sGameModes), ",%s,", sGameModes);
  285. Format(sGameMode, sizeof(sGameMode), ",%s,", sGameMode);
  286. return (StrContains(sGameModes, sGameMode, false) != -1);
  287. }
  288.  
  289.  
  290.  
  291. // ====================================================================================================
  292. // ADMIN COMMANDS
  293. // ====================================================================================================
  294. public Action:CmdFireworks(client, args)
  295. {
  296. if( client && IsClientInGame(client) )
  297. {
  298. decl Float:vPos[3];
  299. decl Float:vAng[3];
  300.  
  301. if( SetTeleportEndPoint(client, vPos, vAng) )
  302. MakeFireworks(vPos);
  303. }
  304. return Plugin_Handled;
  305. }
  306.  
  307. public Action:CmdCrate(client, args)
  308. {
  309. new entity;
  310. if( client && IsClientInGame(client) )
  311. {
  312. decl Float:vPos[3];
  313. decl Float:vAng[3];
  314. if( SetTeleportEndPoint(client, vPos, vAng) )
  315.  
  316. entity = CreateEntityByName("physics_prop");
  317. if( entity != -1 )
  318. {
  319. vPos[2] += 3;
  320. SetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", vPos);
  321. SetEntPropVector(entity, Prop_Data, "m_angAbsRotation", vAng);
  322.  
  323.  
  324. SetEntityModel(entity, MODEL_CRATE);
  325. DispatchSpawn(entity);
  326. }
  327.  
  328.  
  329.  
  330. }
  331. return Plugin_Handled;
  332. }
  333.  
  334. SetTeleportEndPoint(client, Float:vPos[3] = NULL_VECTOR, Float:vAng[3] = NULL_VECTOR)
  335. {
  336.  
  337. GetClientEyeAngles(client, vAng);
  338. GetClientEyePosition(client, vPos);
  339.  
  340.  
  341. new Handle:trace = TR_TraceRayFilterEx(vPos, vAng, MASK_SHOT, RayType_Infinite, TraceEntityFilterPlayer,client);
  342.  
  343. if(TR_DidHit(trace))
  344. {
  345.  
  346. TR_GetEndPosition(vPos, trace);
  347. CloseHandle(trace);
  348.  
  349. vAng[0] = 0.0;
  350. vAng[1] += 90.0;
  351. vAng[2] = 0.0;
  352.  
  353. }
  354. else
  355. {
  356. CloseHandle(trace);
  357. return false;
  358. }
  359. return true;
  360. }
  361.  
  362. public bool:TraceEntityFilterPlayer(entity, contentsMask, any:client)
  363. {
  364. if( entity == client )
  365. return false;
  366. return true;
  367. }
  368.  
  369.  
  370.  
  371. // ====================================================================================================
  372. // EVENTS
  373. // ====================================================================================================
  374. HookEvents()
  375. {
  376. HookEvent("break_prop", Event_BreakProp, EventHookMode_Pre);
  377. HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
  378. HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  379. HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
  380. HookEvent("weapon_fire", Event_FireStart);
  381. }
  382.  
  383. UnhookEvents()
  384. {
  385. UnhookEvent("break_prop", Event_BreakProp, EventHookMode_Pre);
  386. UnhookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
  387. UnhookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  388. UnhookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
  389. }
  390.  
  391. public Event_BreakProp(Handle:event, const String:name[], bool:dontBroadcast)
  392. {
  393. decl String:sTemp[42], Float:vPos[3];
  394. new entity = GetEventInt(event, "entindex");
  395. GetEdictClassname(entity, sTemp, sizeof(sTemp));
  396.  
  397. if( strcmp(sTemp, "prop_physics") == 0 )
  398. {
  399. GetEntPropString(entity, Prop_Data, "m_ModelName", sTemp, sizeof(sTemp));
  400.  
  401. if( strcmp(sTemp, MODEL_CRATE) == 0 ||
  402. (g_iCvarGas && strcmp(sTemp, MODEL_GASCAN) == 0 ) ||
  403. (g_iCvarOxy && strcmp(sTemp, MODEL_OXYGEN) == 0 ) ||
  404. (g_iCvarPro && strcmp(sTemp, MODEL_PROPANE) == 0 )
  405. )
  406. {
  407. GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
  408. MakeFireworks(vPos);
  409.  
  410. if( g_iCvarChase )
  411. {
  412. entity = CreateEntityByName("info_goal_infected_chase");
  413. if( entity != -1 )
  414. {
  415. DispatchSpawn(entity);
  416. vPos[2] += 2.0;
  417. TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
  418. Format(sTemp, sizeof(sTemp), "OnUser1 !self:kill::%d:1", g_iCvarChase);
  419. SetVariantString(sTemp);
  420. AcceptEntityInput(entity, "AddOutput");
  421. AcceptEntityInput(entity, "FireUser1");
  422. AcceptEntityInput(entity, "Enable");
  423. }
  424. }
  425. }
  426. }
  427. }
  428.  
  429. public Action:tmrPlayBurst(Handle:timer, Handle:hPack)
  430. {
  431. decl Float:vPos[3];
  432.  
  433. ResetPack(hPack);
  434. vPos[0] = ReadPackFloat(hPack);
  435. vPos[1] = ReadPackFloat(hPack);
  436. vPos[2] = ReadPackFloat(hPack) + 400.0;
  437.  
  438. PlayAmbient(g_sSoundsBursts[GetRandomInt(0, 3)], vPos);
  439. }
  440.  
  441. PlayAmbient(String:sName[], Float:vPos[3])
  442. {
  443. vPos[2] += 200.0;
  444. EmitAmbientSound(sName, vPos, SOUND_FROM_WORLD, SNDLEVEL_HELICOPTER, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_NORMAL);
  445. }
  446.  
  447. public OnMapEnd()
  448. {
  449. g_iParticleCount = 0;
  450. g_iRoundStart = 0;
  451. g_iPlayerSpawn = 0;
  452. }
  453.  
  454. public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
  455. {
  456. g_iParticleCount = 0;
  457. g_iRoundStart = 0;
  458. g_iPlayerSpawn = 0;
  459. }
  460.  
  461. public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
  462. {
  463. if( g_iPlayerSpawn == 0 && g_iRoundStart == 1 )
  464. {
  465. CreateTimer(8.0, tmrConvert);
  466. }
  467.  
  468. if( g_iPlayerSpawn == 0 )
  469. {
  470. g_iPlayerSpawn = 1;
  471. }
  472. }
  473.  
  474. public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  475. {
  476. if( g_iPlayerSpawn == 1 && g_iRoundStart == 0 )
  477. {
  478. CreateTimer(8.0, tmrConvert);
  479. }
  480.  
  481. if( g_iRoundStart == 0 )
  482. {
  483. g_iRoundStart = 1;
  484. }
  485. }
  486.  
  487. public Action:tmrConvert(Handle:timer)
  488. {
  489. ConvertToCrates();
  490. }
  491.  
  492. ConvertToCrates()
  493. {
  494. new iReplace1 = g_iCvarConvert1;
  495. new iReplace2 = g_iCvarConvert2;
  496. new iReplace3 = g_iCvarConvert3;
  497.  
  498. if( iReplace1 + iReplace2 + iReplace3 == 0 )
  499. return;
  500.  
  501. decl String:sTemp[64];
  502. new entity, iCount1, iCount2, iCount3, iDone, iResult;
  503.  
  504.  
  505. // ======================================================================================
  506. // Do not replace gascans if 'gas_nozzle' is found
  507. // ======================================================================================
  508. if( iReplace1 )
  509. {
  510. entity = -1;
  511. while( (entity = FindEntityByClassname(entity, "point_prop_use_target") ) != -1 )
  512. {
  513. GetEntPropString(entity, Prop_Data, "m_sGasNozzleName", sTemp, 64);
  514. if( strcmp(sTemp, "gas_nozzle") == 0 )
  515. {
  516. iReplace1 = 0;
  517. break;
  518. }
  519. }
  520. }
  521.  
  522.  
  523. // ======================================================================================
  524. // Find 'prop_physics', gascan/oxygen/propane - COUNT
  525. // ======================================================================================
  526. entity = -1;
  527.  
  528. while( (entity = FindEntityByClassname(entity, "prop_physics") ) != -1 )
  529. {
  530. GetEntPropString(entity, Prop_Data, "m_ModelName", sTemp, sizeof(sTemp));
  531. if( iReplace1 && strcmp(sTemp, MODEL_GASCAN) == 0 )
  532. iCount1++;
  533. else if( iReplace2 && strcmp(sTemp, MODEL_OXYGEN) == 0 )
  534. iCount2++;
  535. else if( iReplace3 && strcmp(sTemp, MODEL_PROPANE) == 0 )
  536. iCount3++;
  537. }
  538.  
  539.  
  540. // Percentage to replace
  541. if( iReplace1 && iCount1 )
  542. iResult = (iReplace1 * iCount1) / 100;
  543. if( iReplace2 )
  544. iResult += (iReplace2 * iCount2) / 100;
  545. if( iReplace3 )
  546. iResult += (iReplace3 * iCount3) / 100;
  547.  
  548.  
  549. // ======================================================================================
  550. // Find 'prop_physics', gascan/oxygen/propane - REPLACE
  551. // ======================================================================================
  552. iReplace1 = 0;
  553. iReplace2 = 0;
  554. iReplace3 = 0;
  555. entity = -1;
  556.  
  557. while( (entity = FindEntityByClassname(entity, "prop_physics")) != -1 )
  558. {
  559. if( iDone < iResult )
  560. {
  561. GetEntPropString(entity, Prop_Data, "m_ModelName", sTemp, sizeof(sTemp));
  562.  
  563. if( iReplace1 < iCount1 && strcmp(sTemp, MODEL_GASCAN) == 0 )
  564. {
  565. iReplace1++;
  566. iDone++;
  567. ReplaceCan(entity);
  568. }
  569. else if( iReplace2 < iCount2 && strcmp(sTemp, MODEL_OXYGEN) == 0 )
  570. {
  571. iReplace2++;
  572. iDone++;
  573. ReplaceCan(entity);
  574. }
  575. else if( iReplace3 < iCount3 && strcmp(sTemp, MODEL_PROPANE) == 0 )
  576. {
  577. iReplace3++;
  578. iDone++;
  579. ReplaceCan(entity);
  580. }
  581. }
  582. else
  583. break;
  584. }
  585. }
  586.  
  587. ReplaceCan(entity)
  588. {
  589. decl Float:vPos[3], Float:vAng[3];
  590. GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", vPos);
  591. GetEntPropVector(entity, Prop_Data, "m_angAbsRotation", vAng);
  592. AcceptEntityInput(entity, "kill");
  593.  
  594. vAng[0] += 90;
  595. vPos[2] += 5.0;
  596.  
  597. entity = CreateEntityByName("physics_prop");
  598. if( entity != -1 )
  599. {
  600. SetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", vPos);
  601. SetEntPropVector(entity, Prop_Data, "m_angAbsRotation", vAng);
  602. SetEntityModel(entity, MODEL_CRATE);
  603. DispatchSpawn(entity);
  604. }
  605. return entity;
  606. }
  607.  
  608.  
  609.  
  610. // ====================================================================================================
  611. // FIREWORKS
  612. // ====================================================================================================
  613. MakeFireworks(const Float:vOrigin[3])
  614. {
  615. decl Float:vPos[3];
  616. vPos = vOrigin;
  617. new iAmount;
  618. // Display fireworks on initial explosion?
  619. if( g_iCvarInitMax )
  620. {
  621. iAmount = GetRandomInt(g_iCvarInitMin, g_iCvarInitMax);
  622.  
  623. if( iAmount > 0 )
  624. {
  625. new iFirework, Float:fHeight, Float:vAng[3];
  626.  
  627. for( new i = 0; i < iAmount; i++ )
  628. {
  629. fHeight = GetRandomFloat(300.0, 1400.0);
  630. vPos[2] -= fHeight;
  631. vAng[0] = GetRandomFloat(-10.0, 10.0);
  632. vAng[1] = GetRandomFloat(-10.0, 10.0);
  633. vAng[2] = GetRandomFloat(-10.0, 10.0);
  634.  
  635. // Show fireworks and play sound
  636. iFirework = GetRandomFirework();
  637. ShowParticle(vPos, vAng, g_sParticles[iFirework]);
  638. PlaySound(vPos);
  639.  
  640. // Reset origin
  641. vPos[2] += fHeight;
  642. }
  643. }
  644. }
  645.  
  646. // Display random delayed fireworks?
  647. iAmount = g_iCvarDelayMax;
  648. if( iAmount )
  649. {
  650. // Random amount of fireworks? Or fixed amount?
  651. if( g_iCvarDelayRan )
  652. iAmount = GetRandomInt(g_iCvarDelayMin, iAmount);
  653.  
  654. if( iAmount > 0 )
  655. {
  656. new Float:fTime, Handle:hPack;
  657. for( new i = 0; i < iAmount; i++ )
  658. {
  659. // Create timers to make delayed fireworks
  660. fTime = GetRandomFloat( g_fCvarMinTime, g_fCvarMaxTime );
  661. hPack = INVALID_HANDLE;
  662. CreateDataTimer(fTime, tmrRandomFirework, hPack);
  663. WritePackFloat(hPack, vPos[0]);
  664. WritePackFloat(hPack, vPos[1]);
  665. WritePackFloat(hPack, vPos[2]);
  666. }
  667. }
  668. }
  669. }
  670.  
  671. public Action:tmrRandomFirework(Handle:timer, Handle:hPack)
  672. {
  673. decl Float:vPos[3], Float:vAng[3];
  674.  
  675. ResetPack(hPack);
  676. vPos[0] = ReadPackFloat(hPack);
  677. vPos[1] = ReadPackFloat(hPack);
  678. vPos[2] = ReadPackFloat(hPack);
  679.  
  680. new i = GetRandomFirework();
  681. vPos[2] -= GetRandomFloat(300.0, 1400.0);
  682.  
  683. vAng[0] = GetRandomFloat(-10.0, 10.0);
  684. vAng[1] = GetRandomFloat(-10.0, 10.0);
  685. vAng[2] = GetRandomFloat(-10.0, 10.0);
  686. ShowParticle(vPos, vAng, g_sParticles[i]);
  687.  
  688. PlaySound(vPos); // Play whistle now and explosion sound in 2 seconds.
  689. }
  690.  
  691. // Get a random firework type from the cvars enum and display
  692. GetRandomFirework()
  693. {
  694. new iCount, iArray[4], iType = g_iCvarType;
  695.  
  696. if( iType & TYPE_RED )
  697. {
  698. iArray[iCount] = 0;
  699. iCount++;
  700. }
  701. if( iType & TYPE_BLUE )
  702. {
  703. iArray[iCount] = 1;
  704. iCount++;
  705. }
  706. if( iType & TYPE_GOLD )
  707. {
  708. iArray[iCount] = 2;
  709. iCount++;
  710. }
  711. if( iType & TYPE_FLASH )
  712. {
  713. iArray[iCount] = 3;
  714. iCount++;
  715. }
  716.  
  717. iType = GetRandomInt(0, iCount -1);
  718. return iArray[iType];
  719. }
  720.  
  721.  
  722.  
  723. // ====================================================================================================
  724. // PARTICLES
  725. // ====================================================================================================
  726. PrecacheParticle(const String:sParticle[])
  727. {
  728. new entity = CreateEntityByName("info_particle_system");
  729. if( entity != -1 )
  730. {
  731. DispatchKeyValue(entity, "effect_name", sParticle);
  732. DispatchSpawn(entity);
  733. ActivateEntity(entity);
  734. AcceptEntityInput(entity, "start");
  735. CreateTimer(0.5, tmrRemoveEnt, EntIndexToEntRef(entity));
  736. g_iParticleCount++;
  737. }
  738. }
  739.  
  740. ShowParticle(Float:vPos[3], Float:vAng[3], String:sParticle[])
  741. {
  742. if( g_iParticleCount >= MAX_PARTICLES )
  743. return;
  744.  
  745. new entity = CreateEntityByName("info_particle_system");
  746. if( entity != -1 )
  747. {
  748. TeleportEntity(entity, vPos, vAng, NULL_VECTOR);
  749. DispatchKeyValue(entity, "effect_name", sParticle);
  750. DispatchSpawn(entity);
  751. ActivateEntity(entity);
  752. AcceptEntityInput(entity, "start");
  753. CreateTimer(5.0, tmrRemoveEnt, EntIndexToEntRef(entity));
  754. g_iParticleCount++;
  755. }
  756. }
  757.  
  758. public Action:tmrRemoveEnt(Handle:timer, any:entity)
  759. {
  760. g_iParticleCount--;
  761. entity = EntRefToEntIndex(entity);
  762. if( entity != INVALID_ENT_REFERENCE )
  763. AcceptEntityInput(entity, "kill");
  764. }
  765.  
  766.  
  767.  
  768. // ====================================================================================================
  769. // SOUNDS
  770. // ====================================================================================================
  771. PlaySound(Float:vPos[3])
  772. {
  773. // Limit sounds so they are not played more than once during 0.3 seconds.
  774. new Float:fTime = GetGameTime();
  775. if( (fTime - g_fLastPlayed) <= 0.3 )
  776. return;
  777. g_fLastPlayed = fTime;
  778.  
  779. new iChance = 3;
  780.  
  781. // Whistle sound
  782. if( GetRandomInt(1, 5) <= iChance ) // 3/5 chance to play sound
  783. PlayAmbient(g_sSoundsLaunch[GetRandomInt(0, 5)], vPos);
  784.  
  785. // Explosion sound (in 2 seconds when the particle explodes)
  786. if( GetRandomInt(1, 5) <= iChance ) // 3/5 chance to play fireworks explosion sound
  787. {
  788. new Handle:hPack;
  789. CreateDataTimer(2.0, tmrPlayBurst, hPack);
  790. WritePackFloat(hPack, vPos[0]);
  791. WritePackFloat(hPack, vPos[1]);
  792. WritePackFloat(hPack, vPos[2]);
  793. }
  794. }
  795. public Action:Event_FireStart(Handle:event, String:name[], bool:dontBroadcast)
  796. {
  797. new userid = GetEventInt(event, "userid", 0);
  798. new client = GetClientOfUserId(userid);
  799. if (GetEntProp(client, PropType:0, "m_isIncapacitated", 4, 0) == 1)
  800. {
  801. if (GetClientButtons(client) & 4)
  802. {
  803. int i;
  804. int iAmount;
  805. new Float:fHeight;
  806. new Float:vPos[3] = 0.0;
  807. new Float:vAng[3] = 0.0;
  808. GetClientEyeAngles(client, vAng);
  809. GetClientAbsOrigin(client, vPos);
  810. PlayAmbient(g_sSoundsLaunch[GetRandomInt(0, 5)], vPos);
  811. iAmount = g_iCvarDelayMax;
  812. if( iAmount )
  813. {
  814. if( g_iCvarDelayRan )
  815. iAmount = GetRandomInt(g_iCvarDelayMin, iAmount);
  816.  
  817. if( iAmount > 0 )
  818. {
  819. new Float:fTime, Handle:hPack;
  820. for( new i = 0; i < iAmount; i++ )
  821. {
  822. fTime = GetRandomFloat( g_fCvarMinTime, g_fCvarMaxTime );
  823. hPack = INVALID_HANDLE;
  824. CreateDataTimer(fTime, tmrRandomFirework, hPack);
  825. WritePackFloat(hPack, vPos[0]);
  826. WritePackFloat(hPack, vPos[1]);
  827. WritePackFloat(hPack, vPos[2]);
  828. int iFirework = GetRandomFirework();
  829. ShowParticle(vPos, vAng, g_sParticles[iFirework]);
  830. PlaySound(vPos); // Play whistle now and explosion sound in 2 seconds.
  831. vPos[2] += fHeight;
  832. }
  833. }
  834. return;
  835. }
  836. }
  837. }
  838. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement