Aller au contenu

Photo

How to play and loop a sound like a CampFire?


  • Veuillez vous connecter pour répondre
24 réponses à ce sujet

#1
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

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



#2
Proleric

Proleric
  • Members
  • 2 350 messages

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.


  • Squatting Monk et WhiteTiger aiment ceci

#3
CaveGnome

CaveGnome
  • Members
  • 290 messages

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...


  • Squatting Monk et WhiteTiger aiment ceci

#4
henesua

henesua
  • Members
  • 3 863 messages

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)
                    );
    }
}

  • Squatting Monk, GhostOfGod et WhiteTiger aiment ceci

#5
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

 

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?



#6
henesua

henesua
  • Members
  • 3 863 messages

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.


  • WhiteTiger aime ceci

#7
WhiteTiger

WhiteTiger
  • Members
  • 479 messages
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);
}



#8
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

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



#9
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

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.



#10
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

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



#11
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

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

#12
The Mad Poet

The Mad Poet
  • Members
  • 425 messages

I was just going to suggest scratching a record. ;)



#13
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

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.


  • Squatting Monk aime ceci

#14
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

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);
}



#15
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

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.



#16
Squatting Monk

Squatting Monk
  • Members
  • 444 messages

Post the entirety of the script you're using to create the campfire placeable and create the sound. Several solutions have been offered and "it's not working" doesn't help us to know where the problem may be.



#17
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

The full system of henesua (Campfire/Resting) is running the script of loop sound (sound_sx.nss) for two objects in the same time!!!

 

The campfire got the loop and an invisible object got the loop of the script (sound_sx).



#18
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

This is not working!!! S. Monk

void FireLoop(object oSound)
{
    AssignCommand(oSound, PlaySound("al_cv_firepit1"));
    DelayCommand(5.0, FireLoop());
}

//Here OBJECT_SELF is the campfire and "soundcampfire" is the ResRef of an invisible object (not static) for doing the sound stuff
object oSound = CreateObject(OBJECT_TYPE_PLACEABLE,"soundcampfire",GetLocation(OBJECT_SELF));
FireLoop(oSound);


#19
Squatting Monk

Squatting Monk
  • Members
  • 444 messages
DelayCommand(5.0, FireLoop());

... should be...

DelayCommand(5.0, FireLoop(oSound));

Your freakout isn't helping any. If you wanna track these bugs down, you gotta calm down. Be specific about what's not working: what errors you get, what the anticipated behavior is, and what's actually happening instead. Also, adding debug statements in can narrow your problem down.


  • GhostOfGod aime ceci

#20
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

If you're trying to do it without executing a second script then it should look something more like so:

 

void FireLoop(object oObject)
{
    AssignCommand(oObject, PlaySound("al_cv_firepit1"));
    DelayCommand(5.0, FireLoop(oObject));
}
void main()
{
    location lTarget = GetLocation(GetWaypointByTag("CAMPFIRE_WP"));
    object oFire = CreateObject(OBJECT_TYPE_PLACEABLE, "campfr002", lTarget);
    //ExecuteScript("testfireloop", oFire);
    FireLoop(oFire);
}

 

In the script you posted it looks like you forgot the void main() as well as what Monk pointed out.


  • Squatting Monk aime ceci

#21
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

I appreciate your tips and I agree with you that I climbed up a bit and I would like to apologize for that. I would be very happy if the error was only that syntax disagreement as I typed that code very quickly. 

 

Well I'll post step by step of my system:

 

1) Create an item with ResRef="montelenha" and property "Activate Item" (I use here "Garbage" appearance)

2) Create an item with ResRef="pederneira" and property "Activate Item".

3) Create an object placeable to be the campfire. Set ResRef="fogueira".

4) Create an object placeable to be the sound generator of the campfire. Use invisible object appearance and set ResRef="somfogueira".

5) In the module events "onacquireitem" script do that:

5) In the module events "onactiveitem" script do that:

void MontarFogueira(object oPC)
{
    location lTarget = GetLocation(oPC);
    object oFogueira = CreateObject(OBJECT_TYPE_PLACEABLE, "fogueira", lTarget);
    object oSom = CreateObject(OBJECT_TYPE_PLACEABLE,"somfogueira", lTarget);
    SetLocalObject(oFogueira, "som_pareado", oSom);
}

void main()
{
    object oPC = GetItemActivator();
    object oItem = GetItemActivated();
    string sItemResRef = GetResRef (oItem);

    if(sItemResRef == "montelenha")
    {
        FloatingTextStringOnCreature ("Montando a lenha ...", oPC);
        AssignCommand(oPC, ClearAllActions());
        AssignCommand(oPC, PlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0, 4.0));
        DelayCommand(0.1, SetCommandable(FALSE, oPC));
        DelayCommand(2.0, MontarFogueira(oPC));
        DelayCommand(4.5, SetCommandable(TRUE, oPC));
    }

    if(sItemResRef == "pederneira")
    {
        object oML = GetItemActivatedTarget();
        int iFogo = GetLocalInt(oML, "fogo");
        if(GetResRef(oML) == "fogueira")
        {
            if(iFogo == FALSE)
            {
                ExecuteScript("a_pederneira", GetItemActivatedTarget());
            }
            else
            {
                FloatingTextStringOnCreature("Falhou!", oPC);
                AssignCommand(oPC,ClearAllActions());
            }
        }
    }
} 

6) Create a object placeable with Flame (small) appearence and set ResRef="fogofogueira".

7) Create the script a_pederneira.

void TerminarFogueira(object oFogo, object oSom)
{
        SetPlaceableIllumination(oFogo, FALSE);
        RecomputeStaticLighting(GetArea(OBJECT_SELF));
        DestroyObject(oSom);
        DestroyObject(oFogo);
        DestroyObject(OBJECT_SELF);
}

void FireLoop(object oSom)
{
    AssignCommand(oSom, PlaySound("al_cv_firepit1"));
    DelayCommand(5.0, FireLoop(oSom));
}

void AcenderFogo()
{
    object oSom = CreateObject(OBJECT_TYPE_PLACEABLE,"somfogueira",GetLocation(OBJECT_SELF));
    FireLoop(oSom);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectVisualEffect(VFX_DUR_LIGHT_ORANGE_5),    OBJECT_SELF);
    float fTime = 25.0;
    SetLocalInt(OBJECT_SELF, "fogo", TRUE);
    object oFogo = CreateObject(OBJECT_TYPE_PLACEABLE,"fogofogueira",GetLocation(OBJECT_SELF));
    DelayCommand(1.0, RecomputeStaticLighting(GetArea(OBJECT_SELF)));
    DelayCommand(fTime, TerminarFogueira(oFogo, oSom));
}

void main()
{
    object oPC = GetItemActivator();
    AssignCommand(oPC, ClearAllActions());
    AssignCommand(oPC, PlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0, 2.0));
    DelayCommand(0.1, SetCommandable(FALSE, oPC));
    DelayCommand(2.5, AcenderFogo());
    DelayCommand(2.5, SetCommandable(TRUE, oPC));
} 

How to use:

 

Use the two first itens

 

Item 1: select any place of the map (creates the camp)

Item 2: select the placeable generated by the first item (fires the fire)


  • Squatting Monk aime ceci

#22
Squatting Monk

Squatting Monk
  • Members
  • 444 messages

Okay, this was super-helpful. The problem is that the sound placeable doesn't want to play any sound effects right away because it's still spawning in. That's not a problem because you're actually creating the sound placeable twice, first when you create the actual campfire placeable and again when you light it. You can just have the one that you already created play the sound effect. Just change AcenderFogo() to the following:

void AcenderFogo()
{
    object oSom = GetLocalObject(OBJECT_SELF, "som_pareado");
    FireLoop(oSom);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectVisualEffect(VFX_DUR_LIGHT_ORANGE_5),    OBJECT_SELF);
    float fTime = 25.0;
    SetLocalInt(OBJECT_SELF, "fogo", TRUE);
    object oFogo = CreateObject(OBJECT_TYPE_PLACEABLE,"fogofogueira",GetLocation(OBJECT_SELF));
    DelayCommand(1.0, RecomputeStaticLighting(GetArea(OBJECT_SELF)));
    DelayCommand(fTime, TerminarFogueira(oFogo, oSom));
}

That should do it!

 

EDIT: is there any reason to use a separate object to play the sound effect? Why not use the fire placeable?


  • WhiteTiger aime ceci

#23
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

EDIT: is there any reason to use a separate object to play the sound effect? Why not use the fire placeable?

 

Thank you the reply

 

As you saw I had already created the object oSom in MontarFogueira () and as you saw in the AcenderFogo() I had created new one instead of using the local object. I've tested it in both ways and no one runs correctly the sound: getting local object and creating new one.

 

 

There is no reason for me to create two identical objects, I just forgot to remove the first.



#24
Squatting Monk

Squatting Monk
  • Members
  • 444 messages

I've tested it in both ways and no one runs correctly the sound: getting local object and creating new one.

 
That's odd. The sound ran immediately for me when I used the one set as the local object instead of creating a new one.

There is no reason for me to create two identical objects, I just forgot to remove the first.


That wasn't what I meant. I was wondering what the point of making an invisible placeable to play the sound is. Why not just have the campfire placeable play it?
  • henesua et WhiteTiger aiment ceci

#25
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

 
That's odd. The sound ran immediately for me when I used the one set as the local object instead of creating a new one.


That wasn't what I meant. I was wondering what the point of making an invisible placeable to play the sound is. Why not just have the campfire placeable play it?

 

I may have pretensions of using the campfire to do other actions in the future, so I do not want endangering its performance to an action that happens constantly.

As the invisible object as the object campfire both does not reproduce the sound in the correctly time. I need to confirm this experiment in a new module that will determine if the problem is for large modules.