OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Shadow.D. ^BOB^ on 31 Dec 2008, 00:37:00

Title: Call To Prayer...
Post by: Shadow.D. ^BOB^ on 31 Dec 2008, 00:37:00
Hey guys, im currently building a template for futur missions on the new Afghan Village aswell as Avani.  I was looking into a "Call To Prayer" script, that would play a sound file at various time of the day. Now i could use the old trigger with rough time delay, but its not perfect and in the template the time is selectable.  Which would render this dead anyway.

Does anybody have an idea of how i could get the sound file to play from a certain point (wether it be a game logic, whatever), at set time of the day?

The call to prayer is done like the following (I think!).

- Sun Up

- Midday (When Sun Is Highest)

- + 3 Hours

- Sun Down
 
- + 1 Hour

Obviously to get states of the sun, is a bit much. But you could get the effect with times of day.  I must admit im a complete script noob, when it comes to actually starting from scratch.  So any help would be greatly appreciated.

Thx in advance...
Title: Re: Call To Prayer...
Post by: Mandoble on 31 Dec 2008, 01:18:34
Code: [Select]
_times_to_play = [5, 12, 15, 18, 19];
_played_times = [0, 0, 0, 0, 0];
_i = 0;
while {true} do
{
   _i = 0;
   {
      if (abs (dayTime - _x) < 0.05) then
      {
         if ((_played_times select _i) == 0) then
         {
            _played_times set [_i, 1];
            _gamelogic say "PRAY_SOUND";
         };
      };
      _i = _i + 1;
   } forEach _played_times;

   if (dayTime > (_times_to_play select 4)) then
   {
      _played_times = [0, 0, 0, 0, 0];
   };

   Sleep 10;
};
Title: Re: Call To Prayer...
Post by: Shadow.D. ^BOB^ on 31 Dec 2008, 01:55:51
Will try this asap Mandoble, thanks for such a quick reply.

Edit:  Could i just check i am implemeting this correctly.  I have defined the sound in the description, files are all in.  I then took the code and made an .sqf file, changing the "PRAY_SOUND" for "Adhan.ogg".  Then i run this script from the init.  Is this correct, or have i totally missed the point?
Title: Re: Call To Prayer...
Post by: johnnyboy on 31 Dec 2008, 03:10:15
You need the sound defined in a description.ext file that refers to your .ogg file.  Here is an example of a description.ext file that defines one sound:

Code: [Select]
class CfgSounds
{
sounds[] = {Adhan};

class scream
{
name = "Adhan";
sound[] = {"Adhan.ogg", db+0, 1.0};
titles[] = {0,""};
};
};

Be sure to put the Adhan.ogg file in a subdirectory called /Sound (within your mission directory).

Your say command need only say the name (not including the .ogg extension):

Code: [Select]
_gamelogic say "Adhan";
Note that Mando's example also requires a game logic (shown as a local variable _gamelogic) to exist.  So near the top of Mando's script (before the while loop), you should create the gamelogic:

Code: [Select]
_gamelogic="logic" createVehicle [0,0,0];
Title: Re: Call To Prayer...
Post by: hoz on 31 Dec 2008, 03:21:31
Make sure you can play and hear the sound before you try anything fancy. Also if your making lots of changes to the description.ext be sure to save and reload the mission.
Title: Re: Call To Prayer...
Post by: Shadow.D. ^BOB^ on 31 Dec 2008, 04:08:59
Ok i have checked everything, the sound plays fine in the editor if i use a trigger.  But does not play at the specific time when using the script.

Also while i have your attention  :cool2:   This method plays a sound file to all clients, but could it be possible to use is like the "Trigger" option in the trigger effects.  Whereby is plays the sound from a location (e.g a minaret  :D)  and have the sound drown out the further away the client is?

Will keep checking the script, see if i can get it work.

Script now reads:-
Code: [Select]
_gamelogic="logic" createVehicle [0,0,0];
_times_to_play = [5, 12, 15, 18, 19];
_played_times = [0, 0, 0, 0, 0];
_i = 0;
while {true} do
{
   _i = 0;
   {
      if (abs (dayTime - _x) < 0.05) then
      {
         if ((_played_times select _i) == 0) then
         {
            _played_times set [_i, 1];
            _gamelogic say "Adhan";
         };
      };
      _i = _i + 1;
   } forEach _played_times;

   if (dayTime > (_times_to_play select 4)) then
   {
      _played_times = [0, 0, 0, 0, 0];
   };

   Sleep 10;
};

Cheers...
Title: Re: Call To Prayer...
Post by: Mandoble on 31 Dec 2008, 08:44:48
Change
Code: [Select]
_gamelogic="logic" createVehicle [0,0,0];by
Code: [Select]
_gamelogic="logic" createVehicleLocal [0,0,0];as this script will be running in every client.

Also, you will never hear the sound placing the gamelogic at position [0,0,0]
change [0,0,0] by (getPos player) just for testing, later put there the correct position of the sound source.
Title: Re: Call To Prayer...
Post by: Shadow.D. ^BOB^ on 31 Dec 2008, 16:29:42
Hmmm i have made all the changes, set the logic pos to getPos player.  Still no sound coming through, ive set it to the diff times of day, even waited a couple of minutes either side of the hour, but nothing.  I fear im totally missing something, but i dont really know what to look for.  If i attach the sound file here, is there any chance one of you loverly people could spend some of you valuable time creating a small example of the script?  :-[ :-[

Cheers guys...
Title: Re: Call To Prayer...
Post by: hoz on 31 Dec 2008, 16:50:20
Is it possible that your playing the sound at the gamelogic location of 0,0,0?
Are you able to hear the sound if you use playsound? within the script?

If you move the _gamelogic say "Adhan";  to the top of the script are you able to hear it?In the script below I don't see you setting the position of the GL to the playa
Title: Re: Call To Prayer...
Post by: Mandoble on 31 Dec 2008, 16:59:45
My mistake:
Code: [Select]
_gamelogic="logic" createVehicle [0,0,0];
_times_to_play = [5, 12, 15, 18, 19];
_played_times = [0, 0, 0, 0, 0];
_i = 0;
while {true} do
{
   _i = 0;
   {
      if (abs (dayTime - _x) < 0.05) then
      {
         if ((_played_times select _i) == 0) then
         {
            _played_times set [_i, 1];
            _gamelogic say "Adhan";
         };
      };
      _i = _i + 1;
   } forEach _times_to_play; 

   if (dayTime > (_times_to_play select 4)) then
   {
      _played_times = [0, 0, 0, 0, 0];
   };

   Sleep 10;
};
Title: Re: Call To Prayer...
Post by: Shadow.D. ^BOB^ on 31 Dec 2008, 17:23:13
Cheers mandoble, kinda working.  At least script wise, although i'm getting that is cant find the sound file.  My description includes
Code: [Select]
class CfgSounds
{
sounds[] = {Adhan};

class scream
{
name = "Adhan";
sound[] = {"Adhan.ogg", db+0, 1.0};
titles[] = {0,""};
};
};

I can then use the sound in triggers, so its def in there some how. Seems the script cant find it.
Title: Re: Call To Prayer...
Post by: johnnyboy on 31 Dec 2008, 19:14:06
The sound problem was my mistake.  I was replacing "scream" everywhere with "adhan", but missed the class name, so change "class scream" to "class adhan" in the description.ext, so it looks like this:

Code: [Select]
class CfgSounds
{
sounds[] = {Adhan};

class adhan
{
name = "Adhan";
sound[] = {"Adhan.ogg", db+0, 1.0};
titles[] = {0,""};
};
};
Title: Re: Call To Prayer...
Post by: Shadow.D. ^BOB^ on 31 Dec 2008, 20:57:59
You guys......

 :good: :good: :good:  Sorted, all seems to be working fine.  Will report back if i have any bugs, thankyou all for your help.

Title: Re: Call To Prayer...
Post by: Planck on 31 Dec 2008, 21:01:52
Amen


Sorry totally off-topic, somebody shoot me.....hicc :(


Planck
Title: Re: Call To Prayer...
Post by: hoz on 31 Dec 2008, 21:57:28
Bob, consider submitting your work to the ED this is something maybe other people might wish to use in their missions.
Title: Re: Call To Prayer...
Post by: Shadow.D. ^BOB^ on 31 Dec 2008, 22:27:04
Will look at doing that Hoz.

Just found a little bug.  Although the script works fine, the last prayer time (19:00) plays the sound file repeatedly.  Everyother specified time is correct, playing it only once.

This is so close to being complete now, it definatly gives the map much more immersion.

Cheers...
Title: Re: Call To Prayer...
Post by: Mandoble on 31 Dec 2008, 22:40:30
change
Code: [Select]
if (dayTime > (_times_to_play select 4)) then

by
Code: [Select]
if (dayTime > ((_times_to_play select 4) + 0.1)) then
Title: Re: Call To Prayer...
Post by: Shadow.D. ^BOB^ on 01 Jan 2009, 01:30:30
Sorted...  Thanks again guys, this definatly adds a nice element.  Will get a template etc. done for the depot.  Will give full credit to Mandoble and everyone here :)

Catch u soon.
Title: Re: Call To Prayer...
Post by: Landdon on 17 Jan 2009, 14:59:32
Hello,

I'm am attempting to do the exact same thing, but I have not been successful as of yet.  I have tried my best to follow the thread and attempted to reconstruct it properly.

I have the falling in my description file.

Code: [Select]
// ================================================================================

class CfgSounds
{
sounds[] = {Adhan};

class adhan
{
name = "Adhan";
sound[] = {"Adhan.ogg", db+0, 1.0};
titles[] = {0,""};
};
};;

//================================================================================

I have the Adhan.ogg file within a folder called "Sound" which is where I understand it is suppost to be located.
I have created a SQF file called "prayer" and within, it contains the following code:

Code: [Select]
_gamelogic="logic" createVehicleLocal [0,0,0];
_times_to_play = [5, 12, 15, 18, 19];
_played_times = [0, 0, 0, 0, 0];
_i = 0;
while {true} do
{
   _i = 0;
   {
      if (abs (dayTime - _x) < 0.05) then
      {
         if ((_played_times select _i) == 0) then
         {
            _played_times set [_i, 1];
            _gamelogic say "Adhan";
         };
      };
      _i = _i + 1;
   } forEach _times_to_play; 

    if (dayTime > ((_times_to_play select 4) + 0.1)) then
   {
      _played_times = [0, 0, 0, 0, 0];
   };

   Sleep 10;
};


In my init.sqf file, I have the following:

Code: [Select]

[]execVM "prayer.sqf";


So is my coding valid?  I have not recieved an error from the game when loading it.  But I'm not getting a sound as of yet.  I would like the sound to come from a couple of Minarets.  Is that possiable?  How would I go about making the sound come from a specfic minaret?  That for your help! 
Title: Re: Call To Prayer...
Post by: DeanosBeano on 17 Jan 2009, 15:46:04
Hi,

 first thing would be
 
Code: [Select]
_gamelogic="logic" createVehicleLocal [0,0,0];
 create near you or the minarete instead.
 to get pos of minarette , place a cone or something near it in mission ,save , open mission.sqm . get co-ordinates of cone.
remember convert data from .mission .sqm which is x,z,y  to setpos which is z,y,z .

 also
 If i recall correctly ,for say to work your ogg. must be recorded in mono  @ 44100 ,120kbps .ogg

 the programme to fo this can be found in the excellent sound tutorial in the turorial sections of this site , the software is called goldwave.
Title: Re: Call To Prayer...
Post by: Spooner on 17 Jan 2009, 19:05:01
Deano, I you meant to type:
Quote
remember convert data from .mission .sqm which is x,z,y  to setpos which is x,y,z .

To get the position of any object in-game, you can put this in the init:
Code: [Select]
player sideChat format ["%1 at %2", typeOf this, getPos this];
Though this means you need to copy the value visually from the screen, rather than copy-and-paste from a file. This is possibly a lot easier if you have a lot of the same type of object in the mission and it would be hard to work out which one you want from the mission.sqm (in this case, if you only have one minaret on the map, it would be easy enough to look at the mission.sqm as Deano suggested).
Title: Re: Call To Prayer...
Post by: Landdon on 22 Jan 2009, 19:51:21
THANKS ALL!  I COULDN'T HAVE GOT IT TO WORK WITHOUT YOUR HELP!!! :good: :good: :clap: