Call to prayer script for mission makers (marker version)

  1. ‹ Older
  2. 9 years ago

    Once again Spyder, thank you! With this modified function, can I still spawn loudspeakers using the same code as before (see below)? I've just tried to run a script searching for the building class ("CUP_A2_minaret_ep1") and it's returning nothing so I suspect the original loudspeaker spawn might be more useful with FATA. Not quite sure why it's not being picked up!

    This is the code (which I suspect you wrote!).

    _cities = [] call CalltoPrayer_fnc_getCities;
    
    CalltoPrayerLoudspeakers = [];
    {
    	_spawnPos = [_x select 0, 20,50,3,0,0,0] call BIS_fnc_findSafePos;
    	_pole = "Land_Loudspeakers_F" createVehicle _spawnPos;
    	CalltoPrayerLoudspeakers pushBack _pole;
    	if (_CalltoPrayerDebug) then {
    		_n = format["%1", floor (random 1000)];
    		_marker = createMarker [_n, _spawnPos];
    		_marker setMarkerShape "ICON";
    		_marker setMarkerType "mil_dot";
    		_marker setMarkerText "Spawn Pos";
    	};
    } forEach _cities;
    
    [] call CalltoPrayer_fnc_prayerLoop;
  3. Yeah you can go ahead and try that. In theory it should work as long as you place the markers and define
    INS_CTPMARKERS

  4. Seems to be doing something! The speakers are spawning at the right locations but I haven't managed to catch it just yet. Presumably if the speakers are spawning then the sound should follow!

  5. Okay, I'm spawning louspeakers but there's no sounds. Do you mind having a look and making sure everything looks good to you? I'll update this post once it is working with the final instruction set.

    So init.sqf in mission root:

    INS_CTPMARKERS = ["CTP1","CTP2","CTP3"];
    call compile preprocessFile "CallToPrayer\init.sqf";

    description.ext:

    //----------------------CalltoPrayer----------------------------
    
    class CfgSounds {
    	sounds[] = {prayer};
    	class prayer {
    		name = "prayer";
    		sound[] = {"CalltoPrayer\sounds\prayer.ogg", db+1, 1};
    		titles[] = {};
    	};
    };

    Inside folder CalltoPrayer, functions.sqf:

    /*
    Author:	Sacha
    ______________________________________________________*/
    CalltoPrayer_fnc_getCities = {
    	private ["_locations","_cityTypes","_randomLoc","_x","_cities"];
    	_cities = [];
    
    	_locations = configfile >> "CfgWorlds" >> worldName >> "Names";
    	_cityTypes = ["NameVillage","NameCity","NameCityCapital","NameLocal"];
    
    	for "_x" from 0 to (count _locations - 1) do {
    		_randomLoc = _locations select _x;
    
    		private["_cityPos","_cityType"];
    		_cityPos = getArray(_randomLoc >> "position");
    		_cityType = getText(_randomLoc >> "type");
    		if (_cityType in _cityTypes) then {
    			_cities pushback [_cityPos];
    		};
    	};
    
    	{_cities pushback (getmarkerpos _x)} foreach INS_CTPMARKERS;
    	_cities;
    };
    /////////////////////////////////////////////////////////////////////
    
    /*
    Author:
    
    	Hazey - Main loop for the prayer.
    
    ______________________________________________________*/
    CalltoPrayer_fnc_prayerLoop = {
    	[] spawn {
    		private ["_fnc_between","_fnc_prayer"];
    		_fnc_between = {
    			private ["_a","_b"];
    			_a = _this select 0;
    			_b = _this select 1;
    
    			(daytime >= _a AND daytime < _b)
    		};
    
    		_fnc_prayer = {
    			{
    				[_x, "prayer"] call CBA_fnc_globalSay3d;
    			} foreach CalltoPrayerLoudspeakers;
    		};
    
    		waitUntil {
    			{
    				if (_x call _fnc_between) exitwith {
    					_x call _fnc_prayer;
    				};
    			} foreach [[3.30,3.40],[5.00,5.05],[11.51,11.58],[15.35,15.42],[18.40,18.48],[20.10,20.28]]; ////updated for adhan times relevant to mission date
    
    			sleep 160;
    			false;
    
    		};
    
    	};
    };

    Aaaand the init.sqf inside the CalltoPrayer folder:

    if (!isServer) exitWith {};
    
    _CalltoPrayerDebug = false;
    _functions = execVM "CallToPrayer\functions.sqf";
    waitUntil {scriptDone _functions};
    
    //-- Get cities
    _cities = [] call CalltoPrayer_fnc_getCities;
    
    CalltoPrayerLoudspeakers = [];
    {
    	_spawnPos = [_x select 0, 20,50,3,0,0,0] call BIS_fnc_findSafePos;
    	_pole = "Land_Loudspeakers_F" createVehicle _spawnPos;
    	CalltoPrayerLoudspeakers pushBack _pole;
    	if (_CalltoPrayerDebug) then {
    		_n = format["%1", floor (random 1000)];
    		_marker = createMarker [_n, _spawnPos];
    		_marker setMarkerShape "ICON";
    		_marker setMarkerType "mil_dot";
    		_marker setMarkerText "Spawn Pos";
    	};
    } forEach _cities;
    
    [] call CalltoPrayer_fnc_prayerLoop;

    Finally, I added a few markers to the mission with the relevant names.

    To me, this all looks good and it does spawn loudspeakers but the lack of sounds is puzzling. Any thoughts?

  6. Probably obvious and I'm sure you checked it but are you checking during the correct times of day?

  7. Yup!

  8. Edited 9 years ago by SpyderBlack723

    Just another check, during the correct time of day, did you wait the entire period out (I think it's like 15-20 in game minutes, use 4x speed). The script checks if it's the correct time of day once every 160 secs.

    I'll look at it, maybe tomorrow.. just not sure why it would not work

  9. I've done some digging by running it on Altis and it's all good until I set the marker. Then the sounds stop and an error pops up relating to BIS_fnc_findsafepos.sqf. So somehow, I think the pushback is messing with the array that's produced with _cities and possibly turning into a number:

    {_cities pushback (getmarkerpos _x)} foreach INS_CTPMARKERS;

    The error is

    ' _defaultPos = _this select 8;
    };
    
    if ((count _pos) == 0) then 
    {
    	_pos = getArray...'
    Error count: Type number, expected Array, String, Config entry

    The trouble is, I'm not yet at a level where I understand how it would do that!

  10. Edited 9 years ago by SpyderBlack723

    Oh god I'm dumb

    {_cities pushback (getmarkerpos _x)} foreach INS_CTPMARKERS;

    should be

    {_cities pushback [getmarkerpos _x]} foreach INS_CTPMARKERS;
  11. Knew it would be something simple. And now I know what to look for with arrays! Thanks mate! Do you mind if I post a working sample mission on FATA with everything included?

  12. Go ahead, seems it's become a popular map.

  13. Ahh for fuck's sake... now I'm getting a generic error expression that only appears on FATA and not on Altis.

    private ["_newX", "_newY", "_testPos"];
    	_newX = _posX + (_maxDist - (random (_maxDist * 2)));
    
    Error Generic error in expression
    File (***)\fn_finsafepos.sqf

    Seems FATA is immune to call to prayers. I'm guessing this is because it can't find a safe location near the marker (even though it still places loudspeakers). I tried relaxing some of the variables in the array to see if that changed anything but to no avail.

    Perhaps if I altered it to only look for markers and not cities this would disappear, or is there something I'm missing?

  14. Did you change the findsafepos call at all, looks like it's probably being fed an improper parameter (probably a result of my marker method insertion :) )

  15. I did, but only after this error popped up. Didn't make any real difference. The only reason I can think of it being fed anything wrong is if there's something funky about FATA or if _cities only gives the right information when there are actually cities being found and not just markers.

  16. Got it working!!

  17. My only thought would be to put

    systemchat str _x;

    right above the bis_fnc_spawnpos function call

    Like

           systemchat str _x;
    	_spawnPos = [_x select 0, 20,50,3,0,0,0] call BIS_fnc_findSafePos;

    Then run the mission and if you see anything other than [[x,y,z]] then something, somewhere is going wrong (x,y,z will be numbers)

  18. @incontinenetia Got it working!!

    What was it ??? :)

  19. I just changed the cities function to just CalltoPrayer_fnc_getCities = { private ["_cities"]; _cities = []; {_cities pushback [(getmarkerpos _x)]} foreach INS_CTPMARKERS; _cities; };

    Although it won't work on other maps, it does on FATA! I'm guessing it was looking for suitable positions in urban areas that hadn't been defined so it then couldn't set a safe position. It's not the most elegant of solutions but as long as the vanilla script covers all other maps and this works on FATA then we're golden.

    I keep saying this, but thanks again Spyder!

  20. Edited 9 years ago by SpyderBlack723

    Actually yeah I might know why that was erroring there lol, good catch!

    edit: This might work with all maps including FATA

    CalltoPrayer_fnc_getCities = {
    	private ["_locations","_cityTypes","_randomLoc","_x","_cities"];
    	_cities = [];
    
    	_locations = getArray (configfile >> "CfgWorlds" >> worldName >> "Names");
    	_cityTypes = ["NameVillage","NameCity","NameCityCapital","NameLocal"];
    
    	{
    		private["_cityPos","_cityType"];
    		_randomLoc = _x;
    
    		_cityPos = getArray (_randomLoc >> "position");
    		_cityType = getText (_randomLoc >> "type");
    		if (_cityType in _cityTypes) then {
    			_cities pushback [_cityPos];
    		};
    	} foreach _locations;
    
    	{_cities pushback (getmarkerpos _x)} foreach INS_CTPMARKERS;
    	_cities;
    };
  21. Edited 9 years ago by incontinenetia

    This is a defining moment in my Arma 3 scripting career... I've actually found a solution to an error. It feels strangely profound. Think I might have to have some champagne to celebrate.

  22. Newer ›
 

or Sign Up to reply!