gametechmods

Robot Arena => Discussion => Topic started by: Battlebotsboy on April 06, 2016, 11:30:13 PM

Title: Playing random music during fights
Post by: Battlebotsboy on April 06, 2016, 11:30:13 PM
I have 12 tracks for the Battlebots arena, but I have to switch each track around one by one. Is there a way to get the game to select a track randomly without having to quit the game every time I need to change tracks?
Title: Re: Playing random music during fights
Post by: Clickbeetle on April 08, 2016, 10:59:15 PM
Paste this in def __init__, making sure "import random" is at the very top of the py.

Code: [Select]
self.whichtrack = random.randint(1, 12)
if self.whichtrack == 1:
    self.AddSound = plus.createSound("Sounds/track1.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 2:
    self.AddSound = plus.createSound("Sounds/track2.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 3:
    self.AddSound = plus.createSound("Sounds/track3.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 4:
    self.AddSound = plus.createSound("Sounds/track4.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 5:
    self.AddSound = plus.createSound("Sounds/track5.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 6:
    self.AddSound = plus.createSound("Sounds/track6.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 7:
    self.AddSound = plus.createSound("Sounds/track7.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 8:
    self.AddSound = plus.createSound("Sounds/track8.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 9:
    self.AddSound = plus.createSound("Sounds/track9.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 10:
    self.AddSound = plus.createSound("Sounds/track10.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 11:
    self.AddSound = plus.createSound("Sounds/track11.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 12:
    self.AddSound = plus.createSound("Sounds/track12.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
Title: Re: Playing random music during fights
Post by: Serge on May 01, 2016, 12:13:07 PM
Paste this in def __init__, making sure "import random" is at the very top of the py.

Code: [Select]
self.whichtrack = random.randint(1, 12)
if self.whichtrack == 1:
    self.AddSound = plus.createSound("Sounds/track1.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 2:
    self.AddSound = plus.createSound("Sounds/track2.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 3:
    self.AddSound = plus.createSound("Sounds/track3.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 4:
    self.AddSound = plus.createSound("Sounds/track4.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 5:
    self.AddSound = plus.createSound("Sounds/track5.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 6:
    self.AddSound = plus.createSound("Sounds/track6.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 7:
    self.AddSound = plus.createSound("Sounds/track7.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 8:
    self.AddSound = plus.createSound("Sounds/track8.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 9:
    self.AddSound = plus.createSound("Sounds/track9.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 10:
    self.AddSound = plus.createSound("Sounds/track10.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 11:
    self.AddSound = plus.createSound("Sounds/track11.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 12:
    self.AddSound = plus.createSound("Sounds/track12.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)

You can make this a little bit less ugly like so (untested):

Code: [Select]
sounds = ["Sounds/track1.wav", "Sounds/track2.wav", "Sounds/track3.wav"] # etc...
self.AddSound = plus.CreateSound(random.choice(sounds), False, (0,0,0))
plus.loopSound(self.AddSound)

or:

Code: [Select]
sounds = ["Sounds/track%i.wav" % i for i in range(1, 12+1)]
self.AddSound = plus.CreateSound(random.choice(sounds), False, (0,0,0))
plus.loopSound(self.AddSound)

or even:

Code: [Select]
sound = "Sounds/track%i.wav" % random.randint(1, 12)
self.AddSound = plus.CreateSound(sound, False, (0,0,0))
plus.loopSound(self.AddSound)

(does AddSound even have to be a object variable? if not, just call it plus_sound or something...)
Title: Re: Playing random music during fights
Post by: R01 on May 01, 2016, 12:44:41 PM
Is it possible/is this already for having different tracks for each arena(by adding it to each of their own init scripts)?
Title: Re: Playing random music during fights
Post by: cephalopod on May 01, 2016, 02:27:51 PM
Each arena already has it's own music edited through the py's.
eg
(https://gametechmods.com/uploads/images/728652016-05-01 20_25_44-Cortana.png)
(From the RW Live arena in RWRA2)
Title: Re: Playing random music during fights
Post by: Battlebotsboy on May 03, 2016, 08:40:44 PM
Paste this in def __init__, making sure "import random" is at the very top of the py.

Code: [Select]
self.whichtrack = random.randint(1, 12)
if self.whichtrack == 1:
    self.AddSound = plus.createSound("Sounds/track1.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 2:
    self.AddSound = plus.createSound("Sounds/track2.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 3:
    self.AddSound = plus.createSound("Sounds/track3.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 4:
    self.AddSound = plus.createSound("Sounds/track4.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 5:
    self.AddSound = plus.createSound("Sounds/track5.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 6:
    self.AddSound = plus.createSound("Sounds/track6.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 7:
    self.AddSound = plus.createSound("Sounds/track7.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 8:
    self.AddSound = plus.createSound("Sounds/track8.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 9:
    self.AddSound = plus.createSound("Sounds/track9.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 10:
    self.AddSound = plus.createSound("Sounds/track10.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 11:
    self.AddSound = plus.createSound("Sounds/track11.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)
elif self.whichtrack == 12:
    self.AddSound = plus.createSound("Sounds/track12.wav", False, (0, 0, 0))
    plus.loopSound(self.AddSound)

You can make this a little bit less ugly like so (untested):

Code: [Select]
sounds = ["Sounds/track1.wav", "Sounds/track2.wav", "Sounds/track3.wav"] # etc...
self.AddSound = plus.CreateSound(random.choice(sounds), False, (0,0,0))
plus.loopSound(self.AddSound)

or:

Code: [Select]
sounds = ["Sounds/track%i.wav" % i for i in range(1, 12+1)]
self.AddSound = plus.CreateSound(random.choice(sounds), False, (0,0,0))
plus.loopSound(self.AddSound)

or even:

Code: [Select]
sound = "Sounds/track%i.wav" % random.randint(1, 12)
self.AddSound = plus.CreateSound(sound, False, (0,0,0))
plus.loopSound(self.AddSound)

(does AddSound even have to be a object variable? if not, just call it plus_sound or something...)

Where exactly do I put these codes? Do they have to be placed in a certain spot?
Title: Re: Playing random music during fights
Post by: Naryar on May 04, 2016, 09:50:23 AM
In the battlebots arena .py file. It's in the arenas folder. (Where else ?)
Title: Re: Playing random music during fights
Post by: Battlebotsboy on May 04, 2016, 06:20:17 PM
In the battlebots arena .py file. It's in the arenas folder. (Where else ?)
I know that, but I'm wondering if I have to put the code in a certain place in the file.
Title: Re: Playing random music during fights
Post by: Serge on May 04, 2016, 06:21:57 PM
In the battlebots arena .py file. It's in the arenas folder. (Where else ?)
I know that, but I'm wondering if I have to put the code in a certain place in the file.

If you have to ask this question, you should probably learn some Python (http://learnpythonthehardway.org/book/). It's a useful life skill, and you won't have to be handholded (handheld? handoldered? you get my point.) by others in the future.
Title: Re: Playing random music during fights
Post by: Battlebotsboy on May 12, 2016, 09:16:58 PM
Anyone?
Title: Re: Playing random music during fights
Post by: Trovaner on May 12, 2016, 10:32:52 PM
Clickbeetle already told you where to paste his code in the file and Serge's code is just a replacement for the code that Clickbeetle posted. In other words, you put it in the same place.

Paste this in def __init__, making sure "import random" is at the very top of the py.

Assuming that you don't insert it in the middle of something, there are no additional requirements regarding placement.
Title: Re: Playing random music during fights
Post by: Serge on May 13, 2016, 04:55:11 AM
Anyone?
Why are you ignoring my advice?
Title: Re: Playing random music during fights
Post by: Battlebotsboy on May 13, 2016, 07:16:00 PM
Anyone?
Why are you ignoring my advice?
I did not ignore your advice. I tried to learn this myself & it is way too complicated. TBH, I'd rather have someone who has the knowledge try to help me with this than waste a lot of my life trying to learn all this stuff that I have no experience doing.
Title: Re: Playing random music during fights
Post by: cephalopod on May 13, 2016, 07:48:10 PM
Perhaps you should ask for an alternate solution instead of seemingly ignoring everyone that has 'wasted their life' giving you solutions...
Title: Re: Playing random music during fights
Post by: Battlebotsboy on May 13, 2016, 08:41:27 PM
Perhaps you should ask for an alternate solution instead of seemingly ignoring everyone that has 'wasted their life' giving you solutions...
I'm sorry, I did what I could, but it's all too confusing for me. And I'm not ignoring everyone, I've done everything everyone suggested & nothing worked. I don't know if I'm doing something wrong or what.