Guest User

[L4D2] Dynamic Sound Test

a guest
Oct 23rd, 2015
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.81 KB | None | 0 0
  1. /* Includes */
  2. #include <sourcemod>
  3. #include <sdktools>
  4.  
  5. /* L4D1 Survivor Models */
  6. #define MODEL_BILL "models/survivors/survivor_namvet.mdl"
  7. #define MODEL_ZOEY  "models/survivors/survivor_teenangst.mdl"
  8. #define MODEL_FRANCIS "models/survivors/survivor_biker.mdl"
  9. #define MODEL_LOUIS "models/survivors/survivor_manager.mdl"
  10.  
  11. /* Plugin Information */
  12. public Plugin:myinfo =  {
  13.     name = "[L4D2] L4D1 sounds restore",
  14.     author = "DeathChaos25",
  15.     description = "Restores L4D1 sounds when playing a L4D1 campaign on L4D2 survivor set",
  16.     version = "1.0",
  17.     url = "1337H4X"
  18. }
  19.  
  20. /* Globals */
  21. #define DEBUG 1
  22. #define DEBUG_TAG "L4D1 Sound Restore"
  23. #define DEBUG_PRINT_FORMAT "[%s] %s"
  24.  
  25. #define MAX_ENTITIES 4096
  26.  
  27. /* Plugin Functions */
  28. public OnPluginStart()
  29. {
  30.     HookEvent("player_incapacitated_start", IncapStart)
  31.     HookEvent("revive_success", ReviveSuccess)
  32.     HookEvent("player_spawn", PlayerSpawn)
  33.     HookEvent("survivor_rescued", SurvivorRescued)
  34.     HookEvent("player_death", PlayerDeath)
  35.     HookEvent("mission_lost", MissionLost)
  36. }
  37.  
  38. public OnMapStart()
  39. {
  40.     // Map check coming soon tm music/tags/LeftForDeathHit_l4d1.wav
  41.     PrefetchSound("music/tags/LeftForDeathHit_l4d1.wav")
  42.     PrecacheSound("music/tags/LeftForDeathHit_l4d1.wav", true)
  43.    
  44.     PrefetchSound("music/tags/LeftForDeathHit_l4d1.wav")
  45.     PrecacheSound("music/tags/LeftForDeathHit_l4d1.wav", true)
  46. }
  47.  
  48.  
  49. public IncapStart(Handle:event, const String:name[], bool:dontBroadcast)
  50. {
  51.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  52.    
  53.     if (IsL4D1Survivor(client) && !IsFakeClient(client))
  54.     {
  55.         StopMusic(client)
  56.         ClientCommand(client, "music_dynamic_play Event.Down_L4D1");
  57.        
  58.         for (new i = 1; i <= MaxClients; i++)
  59.         {
  60.             if (i != client && IsSurvivor(i) && IsPlayerAlive(i) && !IsFakeClient(i))
  61.             {
  62.                 StopMusic(i)
  63.                 EmitSoundToClient(i, "music/tags/PuddleOfYouHit_l4d1.wav", _, SNDCHAN_STATIC)
  64.             }
  65.         }
  66.     }
  67. }
  68.  
  69. public ReviveSuccess(Handle:event, const String:name[], bool:dontBroadcast)
  70. {
  71.     new client = GetClientOfUserId(GetEventInt(event, "subject"));
  72.     if (IsL4D1Survivor(client) && !IsFakeClient(client))
  73.     {
  74.         StopMusic(client)
  75.     }
  76. }
  77.  
  78. public PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
  79. {
  80.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  81.     if (IsSurvivor(client))
  82.     {
  83.         StopMusic(client)
  84.     }
  85. }
  86.  
  87. public SurvivorRescued(Handle:event, const String:name[], bool:dontBroadcast)
  88. {
  89.     new client = GetClientOfUserId(GetEventInt(event, "subject"));
  90.     if (IsSurvivor(client))
  91.     {
  92.         StopMusic(client)
  93.     }
  94. }
  95.  
  96. public PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  97. {
  98.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  99.     if (IsL4D1Survivor(client))
  100.     {
  101.         StopMusic(client)
  102.         ClientCommand(client, "play @#music/undeath/LeftForDeath_l4d1.wav");
  103.        
  104.         for (new i = 1; i <= MaxClients; i++)
  105.         {
  106.             if (i != client && IsSurvivor(i) && IsPlayerAlive(i) && !IsFakeClient(i))
  107.             {
  108.                 ClientCommand(i, "music_dynamic_stop_playing Event.SurvivorDeathHit")
  109.                 EmitSoundToClient(i, "music/tags/LeftForDeathHit_l4d1.wav", _, SNDCHAN_STATIC)
  110.             }
  111.         }
  112.     }
  113. }
  114.  
  115. public MissionLost(Handle:event, const String:name[], bool:dontBroadcast)
  116. {
  117.     for (new i = 1; i <= MaxClients; i++)
  118.     {
  119.         if (IsL4D1Survivor(i) && !IsFakeClient(i))
  120.         {
  121.             CreateTimer(0.00001, STOPMUSIC, i);
  122.         }
  123.     }
  124. }
  125.  
  126. public Action:STOPMUSIC(Handle:Timer, any:i)
  127. {
  128.     StopMusic(i)
  129.     ClientCommand(i, "music_dynamic_play Event.ScenarioLose_L4D1")
  130. }
  131.  
  132. stock StopMusic(client)
  133. {
  134.     ClientCommand(client, "music_dynamic_stop_playing Event.Down_L4D1")
  135.     ClientCommand(client, "music_dynamic_stop_playing Event.Down")
  136.     ClientCommand(client, "music_dynamic_stop_playing Event.SurvivorDeath_L4D1")
  137.     ClientCommand(client, "music_dynamic_stop_playing Event.SurvivorDeath")
  138.     ClientCommand(client, "music_dynamic_stop_playing Event.ScenarioLose_L4D1")
  139.     ClientCommand(client, "music_dynamic_stop_playing Event.ScenarioLose")
  140.    
  141.     FakeCHEAT(client, "stopsound", "@#music/terror/PuddleOfYou.wav")
  142.     FakeCHEAT(client, "stopsound", "@#music/terror/PuddleOfYou_l4d1.wav")
  143.    
  144.     FakeCHEAT(client, "stopsound", "music/tags/LeftForDeathHit.wav")
  145.     FakeCHEAT(client, "stopsound", "music/tags/LeftForDeathHit_l4d1.wav")
  146.    
  147.     FakeCHEAT(client, "stopsound", "@#music/undeath/Death.wav")
  148.     //FakeCHEAT(client, "stopsound", "@#music/undeath/Death_l4d1.wav")
  149.    
  150.     FakeCHEAT(client, "stopsound", "@#music/undeath/LeftForDeath_l4d1.wav")
  151.     FakeCHEAT(client, "stopsound", "music/tags/LeftForDeathHit_l4d1.wav")
  152. }
  153.  
  154. #if DEBUG
  155. stock Debug_PrintText(const String:format[], any:...)
  156. {
  157.     decl String:buffer[256]
  158.     VFormat(buffer, sizeof(buffer), format, 2)
  159.    
  160.     LogMessage(buffer)
  161.    
  162.     new AdminId:adminId
  163.     for (new client = 1; client <= MaxClients; client++) {
  164.         if (!IsClientInGame(client) || IsFakeClient(client)) {
  165.             continue
  166.         }
  167.        
  168.         adminId = GetUserAdmin(client)
  169.         if (adminId == INVALID_ADMIN_ID || !GetAdminFlag(adminId, Admin_Root)) {
  170.             continue
  171.         }
  172.        
  173.         PrintToChat(client, DEBUG_PRINT_FORMAT, DEBUG_TAG, buffer)
  174.     }
  175. }
  176. #endif  
  177.  
  178. stock bool:IsSurvivor(client)
  179. {
  180.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2;
  181. }
  182.  
  183. stock bool:IsL4D1Survivor(client)
  184. {
  185.     if (IsSurvivor(client))
  186.     {
  187.         decl String:model[42];
  188.         GetEntPropString(client, Prop_Data, "m_ModelName", model, sizeof(model));
  189.         if (StrEqual(model, MODEL_FRANCIS, false) || StrEqual(model, MODEL_LOUIS, false)
  190.              || StrEqual(model, MODEL_BILL, false) || StrEqual(model, MODEL_ZOEY, false))
  191.         {
  192.             return true;
  193.         }
  194.        
  195.     }
  196.     return false;
  197. }
  198.  
  199. stock bool:IsIncaped(client)
  200. {
  201.     return bool:GetEntProp(client, Prop_Send, "m_isIncapacitated", 1);
  202. }
  203.  
  204. void FakeCHEAT(client, char[] sCommand, char[] sArgument)
  205. {
  206.     int iFlags = GetCommandFlags(sCommand)
  207.     SetCommandFlags(sCommand, iFlags & ~FCVAR_CHEAT)
  208.     ClientCommand(client, "%s %s", sCommand, sArgument)
  209. }
Advertisement
Add Comment
Please, Sign In to add comment