Browse Source

Added REM_SongWasRecentlyPlayed

Added functionality to check if this song was recently played.  Useful
to determine if it was a repeat (so, for example, a play count doesn't
get inflated if a ton of rounds are played on one map).
nosoop 8 years ago
parent
commit
a94e00e792
2 changed files with 33 additions and 3 deletions
  1. 9 0
      scripting/include/round_end_music.inc
  2. 24 3
      scripting/round_end_music.sp

+ 9 - 0
scripting/include/round_end_music.inc

@@ -83,6 +83,15 @@ native bool REM_AddSong(MusicEntry song);
  */
 native int REM_GetActiveSongCount();
 
+/**
+ * Returns whether or not the song's file path exists in the played songs list.
+ * 
+ * A song is recently played if it was already played on the current map (i.e., the first time
+ * it was played since being queued).  A song is considered played after OnRoundEndMusicPlayed
+ * is done being called, so you can determine if it was recently played through that forward.
+ */
+native bool REM_SongWasRecentlyPlayed(MusicEntry song);
+
 /**
  * Called when a song is about to be played.
  * 

+ 24 - 3
scripting/round_end_music.sp

@@ -12,7 +12,7 @@
 #pragma newdecls required
 #include <round_end_music>
 
-#define PLUGIN_VERSION "0.4.2"
+#define PLUGIN_VERSION "0.5.0"
 public Plugin myinfo = {
     name = "[CSRD] Round End Music",
     author = "nosoop",
@@ -229,6 +229,15 @@ void EmitRoundEndMusic(MusicEntry song) {
 	}
 	
 	if (result != Plugin_Stop) {
+		/**
+		 * Plugins listening to OnRoundEndMusicPlayed might check if the song was already
+		 * played, so we'll have to fire off the event before it gets put into the "played"
+		 * list.
+		 * 
+		 * I can't remember if there was any reason why it was last in the first place...
+		 */
+		FireOnREMPlayedPostEvent(song);
+		
 		if (g_PlayedSongs.FindValue(song) == -1) {
 			g_PlayedSongs.Push(song);
 		}
@@ -237,8 +246,6 @@ void EmitRoundEndMusic(MusicEntry song) {
 		if ( (pos = g_ActiveSongs.FindValue(song)) != -1 ) {
 			g_ActiveSongs.Erase(pos);
 		}
-		
-		FireOnREMPlayedPostEvent(song);
 	}
 }
 
@@ -286,6 +293,7 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int err_max)
 	CreateNative("REM_RegisterSource", Native_RegisterSource);
 	CreateNative("REM_AddSong", Native_AddSong);
 	CreateNative("REM_GetActiveSongCount", Native_GetActiveSongCount);
+	CreateNative("REM_SongWasRecentlyPlayed", Native_SongWasRecentlyPlayed);
 }
 
 public int Native_RegisterSource(Handle hPlugin, int nArgs) {
@@ -339,4 +347,17 @@ public int Native_AddSong(Handle hPlugin, int nArgs) {
 
 public int Native_GetActiveSongCount(Handle hPlugin, int nArgs) {
 	return g_nMaxActiveSongs;
+}
+
+public int Native_SongWasRecentlyPlayed(Handle hPlugin, int nArgs) {
+	MusicEntry song = GetNativeCell(1);
+	
+	for (int i = 0; i < g_PlayedSongs.Length; i++) {
+		MusicEntry playedSong = g_PlayedSongs.Get(i);
+		
+		if (song.Equals(playedSong)) {
+			return true;
+		}
+	}
+	return false;
 }