Game Music / Changing Tension Script

  • Thread starter =LFC=Chameleon_Silk
  • Start date
L

=LFC=Chameleon_Silk

Guest
#1
Figured I'd share this, its a way of adding samples of music (the intro and the main loop of a composition) into a mission cutting down on the miz file size by reusing and rescheduling it to play as the sample ends, there is also a nother set of 2 samples that represent when hostile forces are in the range of a zone(s) you have placed in the editor.... I'm sure there are even more things you can do with this but for now this represents all the work I want to put into it atm, with this its possible to have a sound track of music playing all the time that will change based on the threat in the mission which is an ode to old flight sims of the past that were a bit more 'gamey', enjoy.

you need MIST on your mission file and the a few edits to the script as well as getting the samples cut and added as well as added into the mission file.

Code:
-- for music function
Music = 1 -- you can use this variable to disable or enable music player
Tension_Set = 1 -- default tension
--
TensionZone = {'Example Tension Zone Name 1', 'Example Tension Zone Name 2'},
-- requires 4 samples, the intro to the relaxed track cut and matching in seconds length, and then the actual main music sample loop
-- the same thing is done for the high tension track, use whatever length you feel makes it sound right and cut it to the exact seconds needed
-- this will require some musical ear to make it sound 'proper'
-- Now place the trigger zones in the mission editor and match the names in TensionZone up above in the format shown
-- load MIST in your mission with a ONCE >> time more 5 >> do scriptfile and point to MIST
-- add another trigger ONCE >> time more 6 >> do scriptfile and point it to this script
-- you will also need to add the 4 samples sound loaded into some aircraft in your mission that is deactivated to get your music samples into the mission file
-- DO NOT EDIT BELOW THIS LINE --
Music_Battle_Sample = 1 -- set to sample 1
Music_Relaxed_Sample = 1 -- set to sample 1

function Music_Poll(arg, time) -- this will be used to setup the triggers to make

if trigger.misc.getUserFlag('5001') == 1 then
trigger.action.setUserFlag('5001',0)
end

if trigger.misc.getUserFlag('5003') == 1 then
trigger.action.setUserFlag('5003',0)
end

mist.flagFunc.units_in_zones{ -- friendly planes are in the zones listed in zones = { }'
units = {'[blue][plane]'},
zones = TensionZone,
flag = 5000,
toggle = true,
stopFlag = 5001,
zone_type = 'sphere',
}

mist.flagFunc.units_in_zones{ -- enemy planes are in the zones listed in zones = { }'
units = {'[red][plane]'},
zones = TensionZone,
flag = 5002,
toggle = true,
stopFlag = 5003,
zone_type = 'sphere',
}

timer.scheduleFunction(Play_Music, nil, timer.getTime() + 2)
end

function Play_Music(arg, time)
local Return_Time = 1
local Old_Tension_Set = Tension_Set
--
if trigger.misc.getUserFlag('5002') == 1 then
Tension_Set = 2
end
if trigger.misc.getUserFlag('5000') == 1 then
Tension_Set = 1
end

-- set tension level based off of enemy present in GCI zone
--
if Tension_set == 1 and Old_Tension_Set == 2 then
Music_Relaxed_Sample = 1
end
if Tension_set == 2 and Old_Tension_Set == 1 then
Music_Battle_Sample = 1
end

local msg = {}
msg.text = ' Resets'
msg.displayTime = 1
msg.msgFor = {coa = {'all'}}
mist.message.add(msg)

-- set back to intro sample if the tension has changed
if Music == 1 then -- condition block only used if Music is enabled
if Music_Relaxed_Sample == 2 and Tension_Set == 1 then -- play relaxed track
trigger.action.outSoundForCoalition(coalition.side.RED, 'relaxed_mid_10sec.ogg')
Return_Time = 10 -- sample is 10 seconds long
end

if Music_Relaxed_Sample == 1 and Tension_Set == 1 then -- play relaxed start
trigger.action.outSoundForCoalition(coalition.side.RED, 'relaxed_start_12sec.ogg')
Return_Time = 12
Music_Relaxed_Sample = 2 -- set to main sample
end

if Music_Battle_Sample == 2 and Tension_Set == 2 then -- play battle track
trigger.action.outSoundForCoalition(coalition.side.RED, 'battle_mid_41sec.ogg')
Return_Time = 41 -- sample is 41 seconds long
end

if Music_Battle_Sample == 1 and Tension_Set == 2 then -- play battle start
trigger.action.outSoundForCoalition(coalition.side.RED, 'battle_start_16sec.ogg')
Return_Time = 16 -- sample is 16 seconds long
Music_Battle_Sample = 2 -- set to main sample
end

else
-- do not play anything

end
return time + Return_Time -- return exactly same time sample ends
end
-- func end
------------------------------------------------------------------
timer.scheduleFunction(Music_Poll, nil, timer.getTime() + 1)
------------------------------------------------------------------​
 
   
   
   
Top