Thursday, November 21, 2013

[TUT] Playing native sounds and external sounds

One interesting feature in scripts its the sounds, some effects turn out to be incomplete without the appropriate sound effect.

*** Verify new strategy to play external sounds simultaneously here :) ***

  • Playing game sounds

Basic needs:

-1 of the play sound strategies:

-Sound ID
-Sound name
-Technique to quit sound (optional)
-Technique to release sound ID (optional)

the PLAY_SOUND i never know specifically how to use, by no means worked in my tests, so i will show only the other 5 strategies.

* Edit - 31/03/2013
To play "non looped" sounds we can use -1 as sound ID because the sound will end automatically. So, to play sounds of weapons shooting, bullet influence, etc., we can use -1 as sound ID and we do not need to have to get an sound ID :)

Before we be able to play an looped sound, we require to get an sound ID to be able to control the sound with this ID in future, to get this ID we use the method GET_SOUND_ID and shop the ID in an int32 variable:

Now we can proceed :)

Download the sample project here, let's use this project as the base for this tutorial.


As the name says, this will play an sound in an object, if the object moves, the sound moves too, but if the object its deleted the sound keeps in final object position :P

The parameters to use this method are:
  1. The sound ID
  2. The name of the sound
  3. The object where the sound will be played
Let's develop an simple example? Ok, i will get all objects surrounding player, get the first that is with less than five units of distance and play the sound on it, lets use the sound Basic_WEAPONS_ROCKET_LOOP that is the looped sound of rocket flight:

Simple? Yes, it is.

  1. The sound ID
  2. The name of the sound
  3. The pedestrian exactly where the sound will be played

  1. The sound ID
  2. The name of the sound
  3. The position (x, y and z) where the sound will be played

  1. The sound ID
  2. The name of the sound
  3. The vehicle exactly where the sound will be played


This a single will play an sound like an regular/external sound, with out 3D positioning, the sound will usually be the very same. It demands:
  1. The sound ID
  2. The name of the sound

Ok, now we know how to play an sound, but how we stop it? Its straightforward too:


just demands the sound ID:

We also can quit the sound playing other sound utilizing exact same sound ID.


When the sound its no far more required, we can release the ID making use of RELEASE_SOUND_ID:

A single thing that we cant do its release an sound ID without stopping it, for an loop sound like the a single from the instance this will result in an uncontrollable sound, its annoying.

After releasing the sound ID you should use GET_SOUND_ID to get an new sound ID to use.

  • Playing audio occasion
We can play audio events too, its extremely equivalent to play_audio_ methods:

PLAY_AUDIO_Event - demands just the sound name

PLAY_AUDIO_Occasion_FROM_OBJECT - demands sound name and object

PLAY_AUDIO_Event_FROM_PED - needs sound name and ped

PLAY_AUDIO_Event_FROM_Vehicle - wants sound name and automobile

The tougher portion will be discover the appropriate sound name to use, if we take a look into decompiled SCOCL files we will see some examples like:



  • Playing external sounds

To play external sounds we can use an object of kind SoundPlayer:

following creating the object we want to set the sound place and then load the sound:

now its just use the Play method to play the sound:

The bad side of using this method is that we can only play one particular sound at time, if we begin playing an sound, then try to play one more sound, the prior will be stopped, don't matter if we are utilizing various sound files or various sound player objects.

*Always check the sound location to be certain that the sound file its offered to be loaded, otherwise you will get an error in your script:

Download the script of this tutorial right here

  • The Sounds demo script and the sounds list

Perhaps you are asking oneself now: Where i can discover the name of the game sounds to use? Here.

Press Manage+S to save the file in your Scripts folder, save with the name sounds.txt, why? Due to the fact you will use this txt file with my Sound Demo script, so, download the script and the sounds.txt file and place in your Scripts folder, in the game press " to see the console window, kind the command "sd" to enable the script:

Now you will see the aid menu:

This sound list i get from an GTA file utilizing OpenIV, wonderful element of them don't result in something :(, so to support us locate an usable sound i produced an filter method, in the console window sort "sfilter filter_string"

for instance, lets filter sounds with string explosion:

Now close the console window and press Left/Correct to modify between filtered sounds, the name of the sound seems in the bottom of the screen and the sound ought to be played, you will simply uncover the sound "PIGEON_EXPLOSION" that is the sound of an poor pigeon dieing when shot ^^

If no sound is being played restart the game (restart not reload), this could occur right after a lot of reloadscripts and GET_SOUND_ID calls :(

Some names are with added characters from the original file, you can try to remove this additional chars making use of backspace, in wonderful element of cases, eliminate the final char its enough, but keep in mind, a lot of those sounds can't be played.

[TUT] Playing native sounds and external sounds
9out of 10 based on 10 ratings. 9 user reviews.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.