Author Topic: How to play and loop a sound like a CampFire?  (Read 559 times)

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« on: July 20, 2015, 02:28:31 am »


               

If a player can build a campfire anywhere how to create a campfire looping sound in the location of the campfire?



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #1 on: July 20, 2015, 07:55:05 am »


               

I haven't tested this, but according to the Lexicon you can place a sound object anywhere in the area, flagged as inactive, then use SoundObjectSetPosition and SoundObjectPlay in a script to play the sound from the location of the campfire.



               
               

               
            

Legacy_CaveGnome

  • Sr. Member
  • ****
  • Posts: 432
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #2 on: July 20, 2015, 10:40:44 am »


               

I will use adequate fire SoundObjects placed at the autorised fireplaces with the object sound volume option adjusted to 0, every SoundObject will have a TagName related to the fireplace VFX,. When you light the campfire, get the Tag of the corresponding soundobject and boost its volume using "SoundObjectSetVolume" to needed level. When the fire estinguishes, cut off the sound volume to 0 with SoundObjectSetVolume. Probably not the best way to do it (you could use a more advanced tag/switchs system) but it works...



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #3 on: July 20, 2015, 03:01:43 pm »


               

To do this you need perfect timing. You'll need your own system for turning this loop on and off. You can see that I simply erase the local string that defines the sound to play.


 


I use the following script "sound_ex" in recursion on the fire object:



float GetSoundLength(string sSnd)
{
    if(sSnd=="al_cv_firepit1")
        return 5.0;
    else if(sSnd=="al_cv_firecppot1")
        return 5.6;
    else
        return 5.9;
}

void main()
{
    string sSnd = GetLocalString(OBJECT_SELF,"SOUND");
    if(sSnd!="")
    {
        PlaySound(sSnd);
        DelayCommand(   GetSoundLength(sSnd),
                        ExecuteScript("sound_ex", OBJECT_SELF)
                    );
    }
}


               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #4 on: July 20, 2015, 06:08:14 pm »


               


 


To do this you need perfect timing. You'll need your own system for turning this loop on and off. You can see that I simply erase the local string that defines the sound to play.


 


I use the following script "sound_ex" in recursion on the fire object:


 


[...]




 


Thats nice henesua and I understand superficially. Could you post the other part of the script please?


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #5 on: July 20, 2015, 06:36:16 pm »


               

I am just scarfing down food before I head out on a roadtrip, so no, i can not post any more scripts for a few weeks.


 


But that is the entire script that loops on an object. All you need to do is set a local string "SOUND" on the object which will play the sound. And you need to ExecuteScript on that object while calling the script I posted above. That is the whole thing as far as sounds go.


 


I did release a resting and campfire and food system on this website a long time ago which contains all the parts, but that is far more complex than you need. All you need is the sound, and I posted the entire script which plays the sound. You can take it from there.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #6 on: July 21, 2015, 01:56:23 am »


               
henesua, my module is very big could be it the problem? The sound have delay and isn't playing immediately:

 

object oSom = CreateObject(OBJECT_TYPE_PLACEABLE,"somfogueira",GetLocation(OBJECT_SELF));

SetLocalString(oSom,"som","al_cv_firepit1");

ExecuteScript("sound_ex", oSom);


DelayCommand(60.0, DeleteLocalString(oSom,"som"));



//::///////////////////////////////////////////////
//:: sound_ex
//:://////////////////////////////////////////////
/*
    Use: Executed by an object

    Recursive script function that plays a sound.
    Local string: SOUND

    if the local string is empty recursion stops
    --> that is how you turn it off

*/
//:://////////////////////////////////////////////
//:: Created By: The Magus (2012 mar 11)
//:: Modified:
//:://////////////////////////////////////////////

float GetSoundLength(string sSom)
{
    if(sSom=="") //none
        return 0.0;
    else if(sSom=="al_cv_firepit1")
        return 5.0;
    else if(sSom=="al_cv_firecppot1")
        return 5.6;
    else
        return 5.9;
}

void main()
{
    string sSom = GetLocalString(OBJECT_SELF,"som");
    float fDelay = GetSoundLength(sSom);

    if(fDelay > 0.0)
    {
        PlaySound(sSom);
        DelayCommand(fDelay, ExecuteScript("sound_ex", OBJECT_SELF));
    }
    else DestroyObject(OBJECT_SELF);
}


               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #7 on: July 21, 2015, 05:43:39 am »


               


I did release a resting and campfire and food system on this website a long time ago which contains all the parts, but that is far more complex than you need. All you need is the sound, and I posted the entire script which plays the sound. You can take it from there.




 


Yes I downloaded your "campfire system" and it worked perfectly in my module. I don't need to use all the system you did, I just need the sound of campfire looping, but when I try to copy the code from your system I have no sucess.


 


There is a secret?


 


edited --------------


the link: http://forum.bioware...m#entry16120997



               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #8 on: July 21, 2015, 10:06:37 pm »


               

If you didn't want to use henesua's whole system and are just trying to cut pieces out of it, you can still do something similar. Make a script like this:


 


void FireLoop()

{

    PlaySound("al_cv_firepit1");

    DelayCommand(5.0, FireLoop());

}

void main()

{

   FireLoop();

}


 


 


Name it whatever. Maybe something like "sound_fireloop". Then in the script you use to make the campfire, add the line:


 


ExecuteScript("sound_fireloop", campfire object gos here...oFire or whatever);


 


The recursion will end when the campfire is destroyed.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #9 on: July 21, 2015, 11:45:41 pm »


               

If you didn't want to use henesua's whole system and are just trying to cut pieces out of it, you can still do something similar. Make a script like this:


void FireLoop()

{

PlaySound("al_cv_firepit1");

DelayCommand(5.0, FireLoop());

}

void main()

{

FireLoop();

}



Name it whatever. Maybe something like "sound_fireloop". Then in the script you use to make the campfire, add the line:


ExecuteScript("sound_fireloop", campfire object gos here...oFire or whatever);


The recursion will end when the campfire is destroyed.




EDITED

not working



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #10 on: July 21, 2015, 11:51:21 pm »


               


I am just scarfing down food before I head out on a roadtrip, so no, i can not post any more scripts for a few weeks.


[...]


EDITED: Im with a problem I thought it worked but not
               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #11 on: July 21, 2015, 11:52:49 pm »


               

I was just going to suggest scratching a record. '<img'>



               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #12 on: July 22, 2015, 01:04:27 am »


               

You need to make sure you are creating a campfire that isn't "static". Make a new campfire blueprint and use that. I just tested creating and playing sound at the same time and it does work.



               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #13 on: July 22, 2015, 02:14:39 am »


               

My test script if it helps at all:


 


void main()

{

    location lTarget = GetLocation(GetWaypointByTag("CAMPFIRE_WP"));

    object oFire = CreateObject(OBJECT_TYPE_PLACEABLE, "campfr002", lTarget);

    ExecuteScript("testfireloop", oFire);

}



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #14 on: July 22, 2015, 06:04:59 am »


               

I have lost many hours with my tests in game to check if the sound is fine but without success. I need to resolve this issue as quickly as possible. There is a mystery in henesua's shortcut code that his code only works in "particular cases". Instead of that if I use the full code of the system (Henesuas Resting/Campfire) the sound plays perfectly. I've tried many times to extract the part of the major system that reproduces the sound of the campfire but all my attempts resulted in a sound with delay and broken.