Frictional Games Forum (read-only)
Scripting an on/off radio - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Scripting an on/off radio (/thread-21382.html)

Pages: 1 2


RE: Scripting an on/off radio - TheGreatCthulhu - 05-04-2013

(05-04-2013, 08:36 PM)Mr Credits Wrote: Wouldn't it also be necessary to increment/decrement the Radio variable in the case that the radio sound was to be toggled? Unless I had misinterpreted and this is not what the OP specified.

Yyy, you're right Big Grin
In the case of the code above, it would be:

PHP Code:
if(GetLocalVarInt("Radio") == 0)   // 0 means "currently off" - so turn it on
{
    
PlaySoundAtEntity("id.sound.radio""radio.snt""radioarea"0.0false);  // 0.0 - fade in time
    
SetLocalVarInt("Radio"1);   // set it to "currently on"

else  
// local var "Radio" is 1, that is: "currently on" - so turn it off
{
    
StopSound("id.sound.radio"0.5f); //Change 0.5f to how long you want the sound to fade out.
    
SetLocalVarInt("Radio"0);   // set it to "currently off"


Also, the way the code is setup, it should start with:
PHP Code:
void OnStart()
{
    
SetLocalVarInt("Radio"0);   // 0 instead of 1
    // etc... 



RE: Scripting an on/off radio - Daemian - 05-04-2013

(05-04-2013, 11:37 AM)TheGreatCthulhu Wrote: there's really no way for the script to detect a click on an inventory item. So, I guess you'd have to work something out using those.
That's what i didn't want to hear.
I just wanted the player to use the cellphone to stop the music.
I'm not giving up, i'm having it done somehow. hehe.


RE: Scripting an on/off radio - Kalidus - 05-04-2013

(05-04-2013, 10:11 PM)TheGreatCthulhu Wrote:
(05-04-2013, 08:36 PM)Mr Credits Wrote: Wouldn't it also be necessary to increment/decrement the Radio variable in the case that the radio sound was to be toggled? Unless I had misinterpreted and this is not what the OP specified.

Yyy, you're right Big Grin
In the case of the code above, it would be:

PHP Code:
if(GetLocalVarInt("Radio") == 0)   // 0 means "currently off" - so turn it on
{
    
PlaySoundAtEntity("id.sound.radio""radio.snt""radioarea"0.0false);  // 0.0 - fade in time
    
SetLocalVarInt("Radio"1);   // set it to "currently on"

else  
// local var "Radio" is 1, that is: "currently on" - so turn it off
{
    
StopSound("id.sound.radio"0.5f); //Change 0.5f to how long you want the sound to fade out.
    
SetLocalVarInt("Radio"0);   // set it to "currently off"


Also, the way the code is setup, it should start with:
PHP Code:
void OnStart()
{
    
SetLocalVarInt("Radio"0);   // 0 instead of 1
    // etc... 

Awesome, that last code did the trick and it now works as intended! Big Grin

Thanks a lot guys, you will get a place in the credits at the end of my mod. Smile


RE: Scripting an on/off radio - TheGreatCthulhu - 05-04-2013

@Amn: You know what you could try? You could create one huge script area that encompasses entire level, and then add a use item callback on that - if it's possible to do when you're standing inside the script area itself (didn't test). The player experience would be: use the cellphone to interact with "the air". If it's possible, than it would work out rather nicely, for what you want to do, I think.


RE: Scripting an on/off radio - Daemian - 05-05-2013

(05-04-2013, 11:59 PM)TheGreatCthulhu Wrote: @Amn: You know what you could try? You could create one huge script area that encompasses entire level, and then add a use item callback on that - if it's possible to do when you're standing inside the script area itself (didn't test). The player experience would be: use the cellphone to interact with "the air". If it's possible, than it would work out rather nicely, for what you want to do, I think.

Good idea. But even if that worked, how could the player still interact with other things having that permanent area around?
I'll test it out in a sec.

edit2: didn't work very well. You can use the item "with the air" but in this area you can't pick up items or interact with things. So, not good. But i won't give up.