UserFunction; PickRandomMusicTrackRule - HWRM/KarosGraveyard GitHub Wiki
PickRandomMusicTrackRule()
Description
Randomly selects a track from a playlist (in progress).
Example
Rule_Add("PickRandomMusicTrackRule")
Arguments
None.
Instructions
Must be placed in a gamerules file.
To change to custom music, update the playlist table file names and update the lengthTable with the track lengths in seconds. Also, you can optionally have a plain text track name [to do...].
Place battle track .fda's into the directory "data/sound/music/<your music collection name>/battle/".
Place ambient track .fda's into the directory "data/sound/music/<your music collection name>/ambient/".
Settings
ambientIDX: the starting index for the ambient tracks.
battleIDX: the starting index for the battle tracks.
score_flag: if this is a multitrack playlist.
track_count: the number of tracks in the playlist.
music_path: the path to the music files in the HW2 directory.
musicTable:
path: the filename of the .fda file.
length: the track length in seconds.
name: plain text name (example: "adagio for strings").
To do
- add support for mp3s (maybe)
- add support for options
- add support for selecting specific track
- add play controls
Playlist Declaration (place this in a file data:scripts/scar/playlist.lua or similar and update the entry in the function declaration
ambientIDX=0
battleIDX=2
score_flag=1
track_count= 4
music_path = "Data:sound/music/musicpath/"
musicTable =
{
{path="ambient01", length=181, name="track 01 name"},
{path="ambient02", length=209, name="track 02 name"},
{path="battle01", length=254, name="track 03 name"},
{path="battle02", length=159, name="track 04 name"},
{path="", length=0, name=""},
}
you can have multiple playlists and select them by changing the dofilepath("data:scripts/scar/playlist.lua") to point to a different playlist
place this in your gamerules or level file (prefereably gamerules)
function declaration
--=============================================================================
function PickRandomMusicTrackRule()
local randNum = 0
local musicDir = ""
mode = 0
dofilepath("data:scripts/scar/playlist.lua")
if(score_flag) then
if (mode == 0) then
tracks=track_count
randNum = random(tracks)
if (randNum < battleIDX) then
musicDir = "ambient/"
else
musicDir = "battle/"
end
elseif (mode == 1) then
tracks=battleIDX
randNum = random(tracks)
musicDir = "ambient/"
elseif (mode == 2) then
tracks=battleIDX-track_count
randNum = random(tracks)
musicDir = "battle/"
end
local track_length = musicTable[randNum].length
local track_path = musicTable[randNum].path
local track_name = musicTable[randNum].name
Sound_MusicPlay(music_path .. musicDir .. track_path)
print([Level music (](/HWRM/KarosGraveyard/wiki/Level-music-() .. randNum .. [): "](/HWRM/KarosGraveyard/wiki/):-") .. track_name .. ["](/HWRM/KarosGraveyard/wiki/"))
Rule_AddInterval("PickRandomMusicTrackRule", track_length)
Rule_Remove("PickRandomMusicTrackRule")
else
local track_length = musicTable[1].length
local track_path = musicTable[1].path
local track_name = musicTable[1].name
Sound_MusicPlay(music_path .. musicDir .. track_path)
end
end
Authors
--EvilleJedi --Mikali
Related Pages
Comments
Page Status
Updated Formatting? Initial
Updated for HWRM? Initial