Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scripting an on/off radio
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#9
RE: Scripting an on/off radio

Both scripts are setup so that you can both start and stop the playback. In the first script, you have to add your own code for playback start and end. The second script (by JustAnotherPlayer) has all the code in place, but there's another problem with it that I overlooked earlier:

PHP Code: (Select All)
PlaySoundAtEntity("""radio.snt""radioarea"0.0false); 
The first parameter, which can be left out as it was done here, is an internal ID of the (auto-generated) sound-entity that the game (and you) can use in other script functions to identify the specific sound-entity you want to affect. The ID is a string chosen by you.

The StopSound function takes this ID as a parameter, not the name of the sound file. (This is because you may have the same sound file played on several places, and you don't want to stop them all at once.)

So, change this:
PHP Code: (Select All)
PlaySoundAtEntity("""radio.snt""radioarea"0.0false); 

to this (I've chosen to use "id.sound.radio"):
PHP Code: (Select All)
PlaySoundAtEntity("id.sound.radio""radio.snt""radioarea"0.0false); 

and then, a in the else branch, change this:
PHP Code: (Select All)
StopSound("radio.snt"0.5f); 

to
PHP Code: (Select All)
StopSound("id.sound.radio"0.5f); 


Here's the revised version of the entire script:
PHP Code: (Select All)
void OnStart()
{
    
SetLocalVarInt("Radio"1); //The VarInt that makes it to go ON/OFF. 1 = OFF, 0 = ON
    
PreloadSound("radio.snt"); //Preloaded sound.

    
SetEntityPlayerInteractCallback("PlayerInteract""RadioPlay"false); //SEPIC have three arguments, not five.
}

void RadioPlay(string &in asEntity//You had the wrong syntax.
{
    if(
GetLocalVarInt("Radio") == 0)
    {
        
PlaySoundAtEntity("id.sound.radio""radio.snt""radioarea"0.0false);  // 0.0 - fade in time
    

    else
    {
        
StopSound("id.sound.radio"0.5f); //Change 0.5f to how long you want the sound to fade out.
    
}


That should do it.
(This post was last modified: 05-04-2013, 08:31 PM by TheGreatCthulhu.)
05-04-2013, 08:25 PM
Find


Messages In This Thread
Scripting an on/off radio - by Kalidus - 05-03-2013, 05:48 PM
RE: Scripting an on/off radio - by Tomato Cat - 05-03-2013, 06:45 PM
RE: Scripting an on/off radio - by Kalidus - 05-04-2013, 07:13 PM
RE: Scripting an on/off radio - by Daemian - 05-04-2013, 10:44 AM
RE: Scripting an on/off radio - by Daemian - 05-04-2013, 10:56 PM
RE: Scripting an on/off radio - by Tomato Cat - 05-04-2013, 07:20 PM
RE: Scripting an on/off radio - by TheGreatCthulhu - 05-04-2013, 08:25 PM
RE: Scripting an on/off radio - by Tomato Cat - 05-04-2013, 08:36 PM
RE: Scripting an on/off radio - by Kalidus - 05-04-2013, 10:57 PM
RE: Scripting an on/off radio - by Daemian - 05-05-2013, 05:10 AM



Users browsing this thread: 4 Guest(s)