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

Legacy_Squatting Monk

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


               

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.



               
               

               
            

Legacy_WhiteTiger

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


               

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


               
               

               
            

Legacy_WhiteTiger

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


               

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


               
               

               
            

Legacy_Squatting Monk

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


               

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.



               
               

               
            

Legacy_GhostOfGod

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


               

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.



               
               

               
            

Legacy_WhiteTiger

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


               

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)



               
               

               
            

Legacy_Squatting Monk

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


               

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?



               
               

               
            

Legacy_WhiteTiger

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


               


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.



               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
How to play and loop a sound like a CampFire?
« Reply #23 on: July 23, 2015, 06:39:58 pm »


               

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?
               
               

               
            

Legacy_WhiteTiger

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


               


 

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.