Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Random Sound Files in Order


ClareXoBearrx3R9
 Share

Recommended Posts

ClareXoBearrx3R9

Hello everyone,

 

In the GTA IV police vehicles, there is a scanner that plays a random set of sounds. Basically, the dispatcher has a number of sound files including "Crimes", "Conjunctives", "Areas", "Streets", "Vehicles", etc.

 

There is a code somewhere in the game that picks a random sound from each category (in a specific order) and plays them as the police scanner.

 

I was wondering if I could do this myself...I have all the sound files in .WAV format and would like to write something like this for my clan, to have as a custom scanner, so that we have some pretend situations to respond to.

 

I have some knowledge in Flash Actionscript 3.0, and C++, as well as some knowledge in html. Is there anything that anyone could think of something to writing to do such a thing?

 

 

Any help is greatly appreciated!!! wink.gif

Thanks smile.gif

Link to comment
Share on other sites

This really does not belong in this section, there is modding subforum here, you know.

 

Do you want to do this ingame or as a separate program?

Link to comment
Share on other sites

ClareXoBearrx3R9

Oh, I'm sorry smile.gif

I wasn't exactly sure where it was supposed to go.

 

Anyway, I wanted to do it as a separate program. smile.gif

Link to comment
Share on other sites

Well, you'll have to organise your files in some directory structure, then it's probably best to have various playlists, organized to your liking, and finally have a program load the files from those playlists randomly. You can probably use some external player so that coding needs would be minimal.

Link to comment
Share on other sites

ClareXoBearrx3R9

Thanks for the info smile.gif

 

So I might have to do it through a media player or something like that.

Are you aware of there being any codes for something like this, say on a website? (eg.: A code that would allow me to run something like this on a website, treating it as background music).

 

I guess the main thing is I've got the files organized in a file & folder structure, I'm just not sure how to get them to play randomly.

Link to comment
Share on other sites

The algorithm would be the following:

 

1. organise the files (try using standard mp3) in a folder structure

 

2. create playlists which match your needs

 

3. create a program that will follow some logic you may need.

The program will read the playlists contents and then randomly choose an entry from the playlist, using a certain order which matches your needs. There are many functions which can be used for this to happen, like c++ rand() function which outputs a random number from 0 to 1. So, if you need a random index from 0 to 101 you would use floor(rand()*102). floor() is another c++ function.

Files in the playlists can be added with full or relative file path, relative is better as it will allow you to pass on the program to somone else. If you place all the files (including the program) in the game directory, that's probably for the best.

 

4. All of this can be greatly simplifed if you use a special file naming convention. Lets say you have one mysounds folder and in it 11 folders, named 0-10. Each folder may contain files named 0.mp3 to x.mp3. In this case, your program needs to store x for every folder and then you just randomly generate numbers to build paths. Ex.

 

 

// this one holds your game logic, folder index from 0-10, according to above exampleint internal_logic;// this holds the number of mp3 files per folder, 11 folders, 11 entriesarray index[11]= { 50, 87, 55, 10, 38, 25, 45, 86, 100, 15, 20 };// finally the pathstring mp3path= "mysounds\" + inernal_logic + "\" + floor(rand() * index[internal_logic]) + ".mp3";

 

 

5. finally, you may use a commandline mp3 player, like this one to actually play the files. You would use something like this

 

 

start /w cmdmp3win.exe mysounds\0\0.mp3here you would actually use the mp3path variable from above

 

 

which can be fed to ShellExecute() function. It's also rahter easy writing some mp3 reading function, you may look it up on the web.

 

OK, I'll now actually stop before I write, compile and build the program for ya tounge.gif

Link to comment
Share on other sites

ClareXoBearrx3R9

Wow. That was an awesome explanation! smile.gif

 

I'm wondering if I could save some work from building a playlist and perhaps have the program randomly select a sound file in order of specific directories, instead.

I'll definitely rename the files as you suggested with a special convention.

Perhaps I'll write this in c++. I'll try that first.

 

Thanks again for your detailed explanations! Very helpful! biggrin.gif

 

I'll post here my progress with the program. wink.gif

Link to comment
Share on other sites

You don't need the playlist, you can use the above provided file naming convention or just use a function like FindFile().

Link to comment
Share on other sites

ClareXoBearrx3R9

Oh. Hmm. I might try both, to see which is easier.

 

Thanks again smile.gif

Link to comment
Share on other sites

The first one with files organized by logic in folders is definitely easier.

Link to comment
Share on other sites

ClareXoBearrx3R9

Yeah, good point.

 

Thanks smile.gif

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.