erem2k 10 Posted July 13, 2014 (edited) Hello, fellow scripters, I ran into problem while trying to make my idea work in-game Situation: SP mission, player has a wheeled vehicle at their disposal, which has playMusic command in it's init, strapped to it via addAction. AddAction only shows up when player is in the driver's seat (if() check). What playMusic does, is starts playing recorded radio broadcast (~1 hour) for the ambience. As it is known, playMusic starts to play track from it's beginning. What do I want, is that every time addAction is activated, broadcast starts playing at it's random time point (1.30, 8.55, etc.) so it creates an impression of the real radio broadcast. I had an idea of butchering whole broadcast into different tracks, which will be randomly selected every time addAction is activated, but I wonder if there is a smarter way of randomizing starting time point of broadcast playback. Many thanks if you took your time reading trough all of this. Edited July 13, 2014 by Erem2k Share this post Link to post Share on other sites
IT07 10 Posted July 13, 2014 Splitting the track into small sections and then let the script select one is actually a very bright idea and that would also be the closest you will get to your idea. So, do it :) Share this post Link to post Share on other sites
Larrow 2819 Posted July 13, 2014 (edited) PlayMusic already has a option for start time, never used it so not sure if it actually works but check out the command on the wiki. Then all you need is time (how long the mission has been going) mod (%) by the length of the track in seconds (~ 1 hour *60 *60 = 3600 ). playMusic ["myTrack", (time % trackLength)]; if your mission has been going for 30 minutes (1800 seconds), 1800 % 3600 = 1800 <- start time. if your mission has been going for 1 hour 20 minutes (4800 seconds), 4800 % 3600 = 1200 <- start time. Edited July 13, 2014 by Larrow added link to mod command Share this post Link to post Share on other sites
erem2k 10 Posted July 13, 2014 PlayMusic already has a option for start time, never used it so not sure if it actually works but check out the command on the wiki.Then all you need is time (how long the mission has been going) mod (%) by the length of the track in seconds (~ 1 hour *60 *60 = 3600 ). playMusic ["myTrack", (time % trackLength)]; if your mission has been going for 30 minutes (1800 seconds), 1800 % 3600 = 1800 <- start time. if your mission has been going for 1 hour 20 minutes (4800 seconds), 4800 % 3600 = 1200 <- start time. Hmm, definitely interesting, gonna try it out as soon as I get to my PC. I'll post results in this thread Share this post Link to post Share on other sites
IT07 10 Posted July 13, 2014 -- snipped -- I'm not having a bright day today lol. Share this post Link to post Share on other sites
erem2k 10 Posted July 13, 2014 PlayMusic already has a option for start time, never used it so not sure if it actually works but check out the command on the wiki.Then all you need is time (how long the mission has been going) mod (%) by the length of the track in seconds (~ 1 hour *60 *60 = 3600 ). playMusic ["myTrack", (time % trackLength)]; if your mission has been going for 30 minutes (1800 seconds), 1800 % 3600 = 1800 <- start time. if your mission has been going for 1 hour 20 minutes (4800 seconds), 4800 % 3600 = 1200 <- start time. Yes, it worked perfectly fine, never even looked into command's syntax, maybe due to my dumbness :D. Huge thanks for clarifying this one! -- snipped -- I'm not having a bright day today lol. Me neither :c Share this post Link to post Share on other sites
IT07 10 Posted July 13, 2014 Wait I was having a tiny bright moment for a sec: What if a player fails the mission a few times at the same timestamp, (which isn't a small chance) he/she will get almost the same sound every time. So, if you really want to make sure that they won't hear the same stuff every time, you should use the method you described yourself: cut track in pieces and use a switch do with random command. I have a code example, will post that later if you need it. Share this post Link to post Share on other sites
Larrow 2819 Posted July 14, 2014 What if a player fails the mission a few times at the same timestamp, he/she will get almost the same sound every time. Your determined to get Erem2k to split his track up :) randomStartTime = floor (random trackLength) playMusic ["myTrack", ((time + randomStartTime) % trackLength)]; Joking aside there maybe benefits to splitting the track by decreasing the size loaded into memory but would need experimenting with to see how much difference it would actually make. Share this post Link to post Share on other sites
IT07 10 Posted July 14, 2014 True, true. That might be another thing to take into consideration. Share this post Link to post Share on other sites
barbolani 198 Posted July 16, 2014 ...he/she will get almost the same.... Unnecesary typing ;) Share this post Link to post Share on other sites