Name | Type | is_array | initial_value |
Demo_HolyBoltPath | string | No | |
GRS_Array_p | integer | Yes | |
GRS_autoStop | boolean | No | |
GRS_Create | integer | No | |
GRS_Duration_p | real | Yes | |
GRS_fadeOut | boolean | No | |
GRS_fileName | string | No | |
GRS_First_p | integer | Yes | |
GRS_GetDuration | integer | No | |
GRS_Hash_p | hashtable | No | |
GRS_inRate | integer | No | |
GRS_is3D | boolean | No | |
GRS_Kill | integer | No | |
GRS_Last_p | integer | Yes | |
GRS_LastCreatedRSound | integer | No | |
GRS_List_p | integer | Yes | |
GRS_Next_p | integer | Yes | |
GRS_outRate | integer | No | |
GRS_Play | integer | No | |
GRS_Preload | integer | No | |
GRS_Queue_p | integer | No | |
GRS_Recycle_p | integer | Yes | |
GRS_Sound_p | sound | Yes | |
GRS_SoundDuration | real | No | |
GRS_SoundName_p | string | Yes | |
GRS_Stack_First | integer | Yes | |
GRS_Stack_InstanceCount | integer | No | |
GRS_Stack_Next | integer | Yes | |
GRS_Stack_NodeCount | integer | No | |
GRS_Stack_Recycle | integer | Yes | |
GRS_State | integer | No | |
GRS_Stop | integer | No | |
GRS_Timer_p | timer | Yes | |
GRS_Volume | integer | No | |
GRS_X | real | No | |
GRS_Y | real | No | |
GRS_Z | real | No | |
rp | integer | Yes |
//TESH.scrollpos=21
//TESH.alwaysfold=0
// =========================================================================================
// [GUI-Friendly] Rapid Sound v1.9
//
// ~by Reventhous
// http://www.hiveworkshop.com/threads/gui-friendly-rapid-sound.289576/
//
// ~originally by Quilnez
// http://www.hiveworkshop.com/threads/snippet-rapidsound.258991/
//
// =========================================================================================
// -----------------------------------------------------------------------------------------
// -WHAT IS THIS?
//
// A system that allows you to play sounds rapidly and flawlessly without limit.
// Supports both .mp3 and .wav file
// Remember! One sound file for one instance
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
//
// -HOW TO IMPORT
// 1. Go to File [tab] > Preferences. Make sure "Automatically create unknwon variables...
// is ticked.
// 2. Copy the "Rapid Sound" category with "GUI RapidSound" and "gRSound VarGen" triggers in it.
// 3. Paste it to your map.
// 4. Done.
// -----------------------------------------------------------------------------------------
//
// =========================================================================================
// -----------------------------------------------------------------------------------------
// Configurations
//
// facing problem, turn this to true to see helpful message
constant function IS_DEBUG_MODE takes nothing returns boolean
return false
endfunction
// auto create RapidSound. Highly recommended to set it true
constant function AUTO_CREATE takes nothing returns boolean
return true
endfunction
// auto preload sound, create RapidSound instance on map initialization and the system will
// automatically preload the sound.
constant function AUTO_PRELOAD takes nothing returns boolean
return true
endfunction
//
// End of configurations
// -----------------------------------------------------------------------------------------
// =========================================================================================
// anything you do below this line is at your own risk
// =========================================================================================
constant function MIN_DELAY_FACTOR takes nothing returns real
return 4.00
endfunction
constant function MAX_COUNT takes nothing returns integer
return 4
endfunction
// -----------------------------------------------------------------------------------------
// This function destroys/recycle stack
// -----------------------------------------------------------------------------------------
function RSStack_Destroy takes integer this returns nothing
local integer last = udg_GRS_Stack_First[this]
loop
exitwhen udg_GRS_Stack_Next[last] == 0
set last = udg_GRS_Stack_Next[last]
endloop
// recycle set of nodes
set udg_GRS_Stack_Next[last] = udg_GRS_Stack_Next[0]
set udg_GRS_Stack_Next[0] = udg_GRS_Stack_First[this]
// recycle head
set udg_GRS_Stack_Recycle[this] = udg_GRS_Stack_Recycle[0]
set udg_GRS_Stack_Recycle[0] = this
endfunction
// -----------------------------------------------------------------------------------------
// Push/Add a instance to the stack
// -----------------------------------------------------------------------------------------
function RSStack_Push takes integer this returns integer
local integer node
if (udg_GRS_Stack_Next[0] == 0) then
set udg_GRS_Stack_NodeCount = udg_GRS_Stack_NodeCount + 1
set node = udg_GRS_Stack_NodeCount
else
set node = udg_GRS_Stack_Next[0]
set udg_GRS_Stack_Next[0] = udg_GRS_Stack_Next[node]
endif
set udg_GRS_Stack_Next[node] = udg_GRS_Stack_First[this]
set udg_GRS_Stack_First[this] = node
return node
endfunction
// -----------------------------------------------------------------------------------------
// This function creates stack for sound
// -----------------------------------------------------------------------------------------
function RSStack_Create takes nothing returns integer
local integer this
if (udg_GRS_Stack_Recycle[0] == 0) then
set udg_GRS_Stack_InstanceCount = udg_GRS_Stack_InstanceCount + 1
set this = udg_GRS_Stack_InstanceCount
else
set this = udg_GRS_Stack_Recycle[0]
set udg_GRS_Stack_Recycle[0] = udg_GRS_Stack_Recycle[this]
set udg_GRS_Stack_First[this] = 0
endif
return this
endfunction
// -----------------------------------------------------------------------------------------
// This function gives the duration of a sound
// -----------------------------------------------------------------------------------------
function GetRapidSoundDuration takes integer this returns real
return udg_GRS_Duration_p[this]*MIN_DELAY_FACTOR()
endfunction
// -----------------------------------------------------------------------------------------
// This function will recycle the instance and the queue
// -----------------------------------------------------------------------------------------
function KillRapidSound takes integer this returns nothing
local integer i = 0
local integer dex
loop
exitwhen i == MAX_COUNT()
set dex = udg_GRS_First_p[this] + i
call StopSound(udg_GRS_Sound_p[dex], true, false)
call DestroyTimer(udg_GRS_Timer_p[dex])
set udg_GRS_Sound_p[dex] = null
set udg_GRS_Timer_p[dex] = null
// recycle queue
set udg_GRS_Recycle_p[dex] = udg_GRS_Recycle_p[0]
set udg_GRS_Recycle_p[0] = dex
set i = i + 1
endloop
call RSStack_Destroy(this)
endfunction
// -----------------------------------------------------------------------------------------
// This function stops each sound in RapidSound
// -----------------------------------------------------------------------------------------
function StopRapidSound takes integer this, boolean fadeOut returns nothing
local integer i = 0
loop
exitwhen i == MAX_COUNT()
call StopSound(udg_GRS_Sound_p[udg_GRS_List_p[udg_GRS_First_p[this] + i]], false, fadeOut)
set i = i + 1
endloop
endfunction
// -----------------------------------------------------------------------------------------
// This function plays the sound
// -----------------------------------------------------------------------------------------
function PlayRapidSound takes integer this, real x, real y, real z, integer volume returns nothing
// the sound cycle
if (udg_GRS_Array_p[this] == (udg_GRS_First_p[this]) + MAX_COUNT()) then
set udg_GRS_Array_p[this] = udg_GRS_First_p[this]
endif
if TimerGetRemaining(udg_GRS_Timer_p[udg_GRS_List_p[udg_GRS_Array_p[this]]]) == 0 then
call StopSound(udg_GRS_Sound_p[udg_GRS_List_p[udg_GRS_Array_p[this]]], false, false)
call SetSoundPosition(udg_GRS_Sound_p[udg_GRS_List_p[udg_GRS_Array_p[this]]], x, y, z)
call SetSoundVolume(udg_GRS_Sound_p[udg_GRS_List_p[udg_GRS_Array_p[this]]], volume)
call StartSound(udg_GRS_Sound_p[udg_GRS_List_p[udg_GRS_Array_p[this]]])
call TimerStart(udg_GRS_Timer_p[udg_GRS_List_p[udg_GRS_Array_p[this]]], udg_GRS_Duration_p[this], false, null)
endif
set udg_GRS_Array_p[this] = udg_GRS_Array_p[this] + 1
endfunction
// -----------------------------------------------------------------------------------------
// This function creates RapidSound instance
// -----------------------------------------------------------------------------------------
function CreateRapidSound takes string fileName, boolean is3D, boolean autoStop, integer inRate, integer outRate returns integer
local integer this
local integer i = 1
local integer s
local integer q
set this = RSStack_Create()
set udg_GRS_SoundName_p[this] = fileName
set udg_GRS_Duration_p[this] = I2R(GetSoundFileDuration(fileName))/(1000.*MIN_DELAY_FACTOR())
loop
exitwhen i > MAX_COUNT()
set s = RSStack_Push(this)
if udg_GRS_Recycle_p[0] == 0 then
set udg_GRS_Queue_p = udg_GRS_Queue_p + 1
set q = udg_GRS_Queue_p
else
set q = udg_GRS_Recycle_p[0]
set udg_GRS_Recycle_p[0] = udg_GRS_Recycle_p[q]
endif
set udg_GRS_List_p[q] = s
if i == 1 then
set udg_GRS_First_p[this] = q
endif
set udg_GRS_Sound_p[s] = CreateSound(fileName, false, is3D, autoStop, inRate, outRate, "")
set udg_GRS_Timer_p[s] = CreateTimer()
set i = i + 1
endloop
set udg_GRS_Array_p[this] = udg_GRS_First_p[this]
call SaveInteger(udg_GRS_Hash_p, StringHash(fileName), 0, this)
return this
endfunction
// sound preloading, By Silvenon
function PreloadSoundPath takes string path returns nothing
local sound snd = CreateSound(path, false, false, false, 10, 10, "")
call SetSoundVolume(snd, 0)
call StartSound(snd)
call KillSoundWhenDone(snd)
set snd = null
endfunction
// will tell if the sound file name is valid or not
function IsSoundFileNameValid takes string fileName returns boolean
local sound snd = CreateSound(fileName, false, false, false, 10, 10, "")
local boolean b = (GetSoundDuration(snd) > 0.00)
call StopSound(snd, true, false)
set snd = null
return b
endfunction
function gRS_AutoSoundPreload takes string fileName returns nothing
if not LoadBoolean(udg_GRS_Hash_p, StringHash(fileName), 0) then
call PreloadSoundPath(fileName)
call SaveBoolean(udg_GRS_Hash_p, StringHash(fileName), 0, true)
endif
endfunction
// will search RapidSound instance by string
function gRS_GetRapidSound takes string fileName returns integer
return LoadInteger(udg_GRS_Hash_p, StringHash(fileName), 0)
endfunction
// will reset the gRSParam variable to its default
function gRS_ResetParameters takes nothing returns nothing
set udg_GRS_autoStop = false
set udg_GRS_fadeOut = false
set udg_GRS_fileName = ""
set udg_GRS_inRate = 0
set udg_GRS_is3D = false
set udg_GRS_outRate = 0
set udg_GRS_State = 0
set udg_GRS_Volume = 127
set udg_GRS_X = 0.
set udg_GRS_Y = 0.
set udg_GRS_Z = 0.
endfunction
// -----------------------------------------------------------------------------------------
// The actions and the initializaion
// -----------------------------------------------------------------------------------------
function GRS_Actions takes nothing returns nothing
local integer i
// prevent the system works for nothing
if (udg_GRS_State < 1) or (udg_GRS_State > 6) then
if IS_DEBUG_MODE() then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 30, "|CFFFFCC00[gRapid Sound]|R: " + "Using undefined gRSState" )
endif
call gRS_ResetParameters()
return
endif
// reject invalid sound file name
if not IsSoundFileNameValid(udg_GRS_fileName) then
if IS_DEBUG_MODE() then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 30, "|CFFFFCC00[gRapid Sound]|R: " + "invalid sound file name!" )
endif
call gRS_ResetParameters()
return
endif
if AUTO_PRELOAD() then
call gRS_AutoSoundPreload(udg_GRS_fileName)
endif
// create
if (udg_GRS_State == udg_GRS_Create) then
set udg_GRS_LastCreatedRSound = CreateRapidSound(udg_GRS_fileName, udg_GRS_is3D, udg_GRS_autoStop, udg_GRS_inRate, udg_GRS_outRate)
call gRS_ResetParameters()
return
endif
// find RapidSound instance by string
set i = gRS_GetRapidSound(udg_GRS_fileName)
// if not found,
if (i == 0) then
// automatically create a new instance for the sound.
if AUTO_CREATE() then
set i = CreateRapidSound(udg_GRS_fileName, udg_GRS_is3D, udg_GRS_autoStop, udg_GRS_inRate, udg_GRS_outRate)
else
call gRS_ResetParameters()
return
endif
endif
// play
if (udg_GRS_State == udg_GRS_Play) then
call PlayRapidSound(i, udg_GRS_X, udg_GRS_Y, udg_GRS_Z, udg_GRS_Volume)
// stop
elseif (udg_GRS_State == udg_GRS_Stop) then
call StopRapidSound(i, udg_GRS_fadeOut)
// kill
elseif (udg_GRS_State == udg_GRS_Kill) then
call KillRapidSound(i)
// get sound duration by RapidSound instance
elseif (udg_GRS_State == udg_GRS_GetDuration) then
set udg_GRS_SoundDuration = GetRapidSoundDuration(i)
// preload
elseif (udg_GRS_State == udg_GRS_Preload) then
call PreloadSoundPath(udg_GRS_fileName)
endif
// reset gRSParam variables to its default
call gRS_ResetParameters()
endfunction
function InitTrig_GUI_RapidSound takes nothing returns nothing
// hashtable for instance searching
set udg_GRS_Hash_p = InitHashtable()
// the state id
set udg_GRS_Create = 1
set udg_GRS_Play = 2
set udg_GRS_Stop = 3
set udg_GRS_Kill = 4
set udg_GRS_GetDuration = 5
set udg_GRS_Preload = 6
set gg_trg_GUI_RapidSound = CreateTrigger()
call TriggerAddAction( gg_trg_GUI_RapidSound, function GRS_Actions )
endfunction