Browse Source

Added song delay limit

Songs cannot be delayed for longer than the round end lasts.  That'd be
stupid (and have fun precaching if it carries over to the next map).
nosoop 8 years ago
parent
commit
a1ec01b47a
1 changed files with 12 additions and 3 deletions
  1. 12 3
      scripting/round_end_music.sp

+ 12 - 3
scripting/round_end_music.sp

@@ -12,7 +12,7 @@
 #pragma newdecls required
 #include <round_end_music>
 
-#define PLUGIN_VERSION "0.4.0"
+#define PLUGIN_VERSION "0.4.1"
 public Plugin myinfo = {
     name = "[CSRD] Round End Music",
     author = "nosoop",
@@ -91,7 +91,6 @@ void PrintSongList(int client, const char[] listName, ArrayList songList) {
 }
 
 public void OnConfigsExecuted() {
-	// TODO pull g_nMaxActiveSongs from ConVar -- it can't change during map
 	g_nMaxActiveSongs = g_ConVarMaxActiveSongs.IntValue;
 	g_bRoundEndMusicActive = g_ConVarEnabled.BoolValue;
 	
@@ -255,7 +254,12 @@ void FireOnREMPlayedPostEvent(MusicEntry song) {
 }
 
 public void OnRoundEnd(Event event, const char[] name, bool dontBroadcast) {
-	CreateTimer(g_ConVarSongDelay.FloatValue, RoundEndMusicPlaybackDelay);
+	float flSongDelay = g_ConVarSongDelay.FloatValue, flBonusRoundTime = GetBonusRoundTime();
+	
+	// Enforce checking of song delay.
+	flSongDelay = flSongDelay > flBonusRoundTime? flBonusRoundTime : flSongDelay;
+	
+	CreateTimer(flSongDelay, RoundEndMusicPlaybackDelay, _, TIMER_FLAG_NO_MAPCHANGE);
 }
 
 public Action RoundEndMusicPlaybackDelay(Handle timer, any data) {
@@ -266,6 +270,11 @@ public Action RoundEndMusicPlaybackDelay(Handle timer, any data) {
 // that *should* maintain initial play order
 // maybe we should just provide a function that provides the entire list and active counts?
 
+/* Utility functions */
+float GetBonusRoundTime() {
+	return FindConVar("mp_bonusroundtime").FloatValue;
+}
+
 /* Native function calls */
 public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int err_max) {
 	RegPluginLibrary("round-end-music");