Jump to content
Sign in to follow this  
BEAKSBY

Location of dialog log files how the countdown is triggered

Recommended Posts

Where do I find the dialog log files...in which folder?

I'm looking to see what command is excuted when I use BIS_fnc_paramCountdown and how the countdown trigger is triggered when it reaches 0. I down't want it to play the "MISSION COMPLETED" ending.

Share this post


Link to post
Share on other sites

See your other thread, but...

I'm looking to see what command is excuted when I use BIS_fnc_paramCountdown

From what i can tell it is only what you showed in the other thread , all it does is use the estimatedtimeleft that displays how long there is left in the mission on the server browser, according to the wiki.

and how the countdown trigger is triggered when it reaches 0. I down't want it to play the "MISSION COMPLETED" ending.

Are you using some module to go along with this (is that what you mean by countDown trigger?) as otherwise i cant see why just using BIS_fnc_paramCountdown would end a mission, unless it does something that is not documented on the wiki.

Ah i see you are using a countDown Module look in the functions viewer at multiplayer -> BIS_fnc_moduleCountDown the line were it says

[] call bis_fnc_missionTimeLeft) == 0

is were it determines if time is up.

BIS_fnc_missionTimeLeft basically does similar to what i showed in your other thread

/*
Author: Karel Moricky

Description:
Returns time in seconds until the mission end.
Remaining time can be set using 'estimatedTimeLeft' command or using BIS_fnc_countdown

Parameter(s): None

Returns:
NUMBER - time in seconds. -1 when no time was set yet.
*/

private ["_value"];
_value = [] call bis_fnc_countdown;
if (_value <= 0 && ismultiplayer) then {
_value = if (estimatedEndServerTime != 0) then {
	((estimatedEndServerTime - servertime) max 0)
} else {
	-1
};
};
_value

Compares estimatedEndServerTime against serverTime.

Share this post


Link to post
Share on other sites
Ah i see you are using a countDown Module look in the functions viewer at multiplayer -> BIS_fnc_moduleCountDown the line were it says

Code:

[] call bis_fnc_missionTimeLeft) == 0

Thanks Larrow,

I still can't figure how to remove "MISSION COMPLETE" ending (i.e.the default ending "END1"). I don't see where I have a BIS_fnc_moduleCountDown ...not even in the editor.

In my description.ext I have:

class Params
{
class TimeLimit 
{
	title = "Time Limit";
	texts[] = {"Unlimited", "1 minute", "10 minutes", "15 minutes", "20 minutes", "25 minutes", "30 minutes", "45 minutes", "60 minutes"};		
	values[] = {0, 60, 600, 900, 1200, 1500, 1800, 2700, 3600};
	default = 1200;
	//file = "BEAKSparamCountdown.sqf"; 
	function = "BIS_fnc_paramCountdown";
	isGlobal = 1;
};
class CommandPoints 
{
	title = "Command Point";
	values[] = {100,250,500,1000};
	default = 500;
	file = "moduleRespawnTickets.sqf"; 
};
};

moduleRespawnTickets.sqf

_activated = true;

if (_activated) then {


//--- End the mission after tickets are exhausted
if (isnil "bis_fnc_moduleRespawnTickets_end") then {
	bis_fnc_moduleRespawnTickets_end = [] spawn {
		scriptname "bis_fnc_moduleRespawnTickets: Loop";
		waituntil {
			sleep 1;
			(([[west,east,resistance,civilian]] call bis_fnc_respawnTickets) select 1) == 0			
			//(([[west,east]] call bis_fnc_respawnTickets) select 1) == 0
		};
		"SideTickets" call bis_fnc_endMissionServer;
	};
};
//if (_logic call bis_fnc_isCuratorEditable) exitwith {};

private ["_tickets"];
_tickets = [_this,0,500,[0]] call bis_fnc_param;
if (_tickets >= 0) then {
{
	if (playableslotsnumber _x > 0) then {
		[_x,_tickets] call bis_fnc_respawnTickets;
	};
} foreach [east,west];
};
[[EAST,WEST],(1/6),1,3] spawn BEAKS_fnc_BEAKSbleedTickets;	//Customized BleedTicket System
};

...but this does not trigger when the time runs out.

in my initplayerlocal.sqf

gameDuration = "TimeLimit" call BIS_fnc_getParamValue;
[gameDuration] spawn {
_time = time;
_gameDuration = _this select 0;
while {true} do {
	sleep 1;
	_countdown = _gameDuration - (time - _time);
	if (_countdown < -2) exitWith {"SideTickets" call BEAKS_fnc_endMissionServer};
	//if (_countdown < 10) exitWith {"end1" call BIS_fnc_endMission};
	};
};

..and I modified BIS_fnc_endMissionServer with

BEAKS_fnc_endMissionServer.sqf

if !(isserver) exitwith {["%1 can be executed only on server",_fnc_scriptname] call bis_fnc_error; false};
private ["_type"];
_type = [_this,0,"sidetickets",[""]] call bis_fnc_param;
switch (tolower _type) do {
case "sidetickets": {	//hint "HELLO endMIssion Server SIDETICKETS";
	private ["_sides","_ticketsMax","_winners"];
	_sides = [east,west,resistance,civilian];
	_ticketsMax = 0;
	_winners = [];
	{
		private ["_tickets"];
		_tickets = _x call bis_fnc_respawnTickets;
		if (_tickets > _ticketsMax) then {
			_ticketsMax = _tickets;
			_winners = [_x];
		} else {
			if (_tickets == _ticketsMax) then {
				_winners set [count _winners,_x];
			};
		};
	} foreach _sides;

	[["SideLost",false,nil,nil,true],"bis_fnc_endMission",_sides - _winners] call bis_fnc_mp;
	[["SideWon",true,nil,nil,true],"bis_fnc_endMission",_winners] call bis_fnc_mp;
	//[["",true,nil,nil,true],"bis_fnc_endMission",allcurators] call bis_fnc_mp;
};
};
true

...yet I still get "MISSION COMPLETE" which is the default ending -->"END1" bis_fnc_endMission???

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

//gameDuration = "TimeLimit" call BIS_fnc_getParamValue; //probably unnecessary line
[[TimeLimit] call BIS_fnc_getParamValue] spawn {
   _time = time;
   _gameDuration = _this select 0;
   while {true} do {
       sleep 1;
       _countdown = _gameDuration - (time - _time);
       if (_countdown < -2) exitWith {"SideTickets" call BEAKS_fnc_endMissionServer};
       //if (_countdown < 10) exitWith {"end1" call BIS_fnc_endMission};
       };
};

...but this does not trigger when the time runs out.

not sure if you're talking about initplayerlocal.sqf, but _countdown will never reach 10 or -2 with the code you posted

lets say time = 10
//gameDuration = "TimeLimit" call BIS_fnc_getParamValue; //unnecessary line
//[[TimeLimit] call BIS_fnc_getParamValue] spawn {
   _time = time;
//    _gameDuration = _this select 0;
//    while {true} do {
//        sleep 1;
       _countdown = _gameDuration - (time - _time);
//        if (_countdown < -2) exitWith {"SideTickets" call BEAKS_fnc_endMissionServer};
       //if (_countdown < 10) exitWith {"end1" call BIS_fnc_endMission};
//        };
//};

_countdown = _gameDuration - (10 - 10);
_countdown = _gameDuration -  0 ;
Time never runs out.

EDIT: nevermind

Edited by DreadedEntity

Share this post


Link to post
Share on other sites
Thanks Larrow,

I still can't figure how to remove "MISSION COMPLETE" ending (i.e.the default ending "END1"). I don't see where I have a BIS_fnc_moduleCountDown ...not even in the editor.

Maybe you don't, i was presuming this is what you meant by "and how the countdown trigger is triggered when it reaches 0."

You logic seems a little messed up here. Ive only quickly browsed over what you posted but...

Mission starts

Param settings (TimeLimit) initialise BIS_fnc_paramCountdown which as discussed in the other thread sets up estimatedEndServerTime, yet you init it globally here (isGlobal = 1) yet the commands are server side only.

Param settings (CommandPoints) calls moduleRespawnTickets.sqf

this spawns a loop that waits until a side has 0 tickets then calls BI's version of endMissionServer with "SideTickets"

You also add the number of tickets from the param if there are any players on that side.

and launch your bleedTickets script we've spoken about before in another thread.

You then have initPlayerLocal monitoring time against TimeLimit. Ok this seems odd why have each and ever player that joins start their own. Each and every player would end the mission at a different time. This should be done once on the server. Also isn't _time a reserved variable for how long a scripts been running?

This timer function then calls your version of endMissionServer but as this is a local player calling this it immediately exits because of

if !(isserver) exitwith {["%1 can be executed only on server",_fnc_scriptname] call bis_fnc_error; false};

So know one is ever gonna be calling endMission from this direction.

As i said Ive only had a quick browse over what you've posted but from that the only way i can see this mission ending is if you have a sides tickets reach zero. Is there anything else in your description you have not shown? respawnTemplates or the like?

When i get a little time ill try setting something up to see whats happening (i also want to check when and where file and function in params actually happen, as per the other thread ) but in the mean time i suggest you back through the logic of whats happening here, especially the part where players are monitoring the end time.

@DE TIME & _TIME are different , time is actually a command the returns how long since the mission started.

Share this post


Link to post
Share on other sites

Once again Larrow, I appreciate you following-up with this.

Is there anything else in your description you have not shown? respawnTemplates or the like?

Yes, terribly sorry I didn't include the entire script...I assumed it was irrelavant. BUT YES, I do have a respawnTemplate in there. Could that trigger a game countdown ending?

descrition.ext

// Control types
#define CT_STATIC           0
#define CT_MAP_MAIN         101

// Static styles
#define ST_RIGHT         0x02
#define ST_PICTURE        0x30

class RscTitles 
{
 #include "UI\defines.hpp"  
};

enableDebugConsole = 1;

class CfgFunctions
{
class BEAKS
{
	class RepairRearm
	{
		file = "functions\RepairRearm";
		class RepairRearmFlip {};
		class unitStatusCost {};
	};
	class general
	{
		file = "functions\general";
		class GET_IN {};
		class GoldCollect {};
		class StaticWeapon_addAction {};
		class ReinforceStaticWeapon {};
		class BEAKSbleedTickets {};
		class rearmAT {};
		class regenerateHealth {};
		class sectorDistances {};
		class cargoPlane {};
		class cargoPlaneReinforcements {};
		class endMissionServer {};			
	};
	class RadioTower
	{
		file = "functions\RadioTower";
		class AirStrike {};
		class Artillery {};
		class BCAS {};
		class Intel {};
		//postInit = 1;
		class Reinforcements {};	
	};
};

respawn = "BASE";
respawnDelay = 2;
respawnButton = 0; // 0 - to disable respawn button in pause menu
respawnTemplates[] = {"MenuInventory","MenuPosition"};

class Params
{
#include "\a3\functions_f\Params\paramDaytimeHour.hpp"
#define DAYTIMEHOUR_DEFAULT	12	
class MoneyDropFrequency 
{
	title = "Money Drop Frequency";
	texts[] = {"Never", "1 minute", "2 minutes", "3 minutes", "5 minutes", "10 minutes"};		
	values[] = {0, 60, 120, 180, 300, 600};
	default = 180;
};
class StartingMoney
{
	title = "Amount of Starting Money";
	values[] = {0, 250, 500, 1000, 2500, 5000};
	default = 1000;
};
class TimeLimit 
{
	title = "Time Limit";
	texts[] = {"Unlimited", "1 minute", "10 minutes", "15 minutes", "20 minutes", "25 minutes", "30 minutes", "45 minutes", "60 minutes"};		
	values[] = {0, 60, 600, 900, 1200, 1500, 1800, 2700, 3600};
	default = 1200;
	//file = "BEAKSparamCountdown.sqf"; 
	function = "BIS_fnc_paramCountdown";
	isGlobal = 1;
};
class CommandPoints 
{
	title = "Command Point";
	values[] = {100,250,500,1000};
	default = 500;
	file = "moduleRespawnTickets.sqf"; 
};
class AISkill
{
	title = "AI Skill"; // Param name visible in the list
	values[] = {0.2,0.4,0.6,0.8}; // Values; must be integers; has to have the same number of elements as 'texts'
	texts[] = {"Recruit","Regular", "Advanced", "Veteran"}; // Description of each selectable item
	default = 0.4; // Default value; must be listed in 'values' array, otherwise 0 is used
};

};


class Header
{
 gameType = SC;
 minPlayers = 2;
 maxPlayers = 6;
};

class CfgRespawnInventory
{
class WEST1
{
	displayName = "Capt 'Deuce' Williams"; // Name visible in the menu
	icon = "\A3\Ui_f\data\GUI\Cfg\Ranks\captain_gs.paa"; // Icon displayed next to the name
	// Loadout definition, uses same entries as CfgVehicles classes
	vehicle[] = {
		"B_soldier_AT_F"
	};
	weapons[] = {
		"Binocular",
		"launch_B_Titan_short_F",
		"Titan_AT",
		// "hgun_Pistol_heavy_02_Yorris_F"
		// "hgun_Pistol_heavy_01_F" // "11Rnd_45ACP_Mag"
		// hgun_Pistol_heavy_01_MRD_F 
		// "hgun_Pistol_heavy_01_snds_F"
		"hgun_Pistol_heavy_01_MRD_F" 
	};
	magazines[] = {
		"11Rnd_45ACP_Mag",
		"11Rnd_45ACP_Mag",
		"11Rnd_45ACP_Mag",
		"6Rnd_45ACP_Cylinder",
		"6Rnd_45ACP_Cylinder",
		"6Rnd_45ACP_Cylinder",
		"Titan_AT",
		"Titan_AT",
		"Titan_AT",
		"Titan_AT",
		"SmokeShell"
	};
	items[] = {
		"Titan_AT",
		"Titan_AT",
		"FirstAidKit"

	};
	linkedItems[] = {
		"V_Chestrig_khk",
		"H_Watchcap_blk",
		"optic_Aco",
		"acc_flashlight",
		"ItemMap",
		"ItemCompass",
		"ItemWatch",
		"ItemRadio"
	};
	uniformClass = "U_B_CombatUniform_mcam_tshirt";
	backpack = "B_Carryall_cbr"; // B_AssaultPack_mcamo B_AssaultPack_rgr_LAT
};
class WEST2
{
	displayName = "Sgt Thomas 'Mac' Macintyre"; // Name visible in the menu
	icon = "\A3\Ui_f\data\GUI\Cfg\Ranks\sergeant_gs.paa"; // Icon displayed next to the name
	// Alternative configuration pointing to a CfgVehicles class. Loadout will be copied from it.
	vehicle[] = {
		"B_soldier_AR_F"
	};

	weapons[] = {
		"acc_pointer_IR",  	// NEW 2014 07 30
		"optic_ACO_grn",	// NEW 2014 07 30
		"LMG_Zafir_F", 		// "LMG_Zafir_pointer_F", 
		"BTC_smaw",		// NEW 2014 07 30
		"BTC_mk42",		// NEW 2014 07 30
		"Laserdesignator"
	 };
	magazines[] = {
		"acc_pointer_IR",  	// NEW 2014 07 30
		"optic_ACO_grn",	// NEW 2014 07 30
		"Laserbatteries", 
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"SmokeShellGreen"
	};
	items[] = {
		"Medikit"
	};
	linkedItems[] = {
		"acc_pointer_IR",  	// NEW 2014 07 30
		"optic_ACO_grn",	// NEW 2014 07 30
		"V_Chestrig_khk",
		"ItemMap",
		"ItemCompass",
		"ItemWatch",
		"ItemRadio"
	};
	uniformClass = "U_B_CombatUniform_mcam_tshirt";
	backpack = "B_Carryall_cbr"; 
};	
class WEST3
{
	displayName = "Lt John Davis Tyler"; // Name visible in the menu
	icon = "\A3\Ui_f\data\GUI\Cfg\Ranks\lieutenant_gs.paa"; // Icon displayed next to the name
	// Loadout definition, uses same entries as CfgVehicles classes
	vehicle[] = {
		"B_recon_M_F"
	};
	weapons[] = {
		"srifle_EBR_DMS_pointer_snds_F", // arifle_MXM_ARCO_point_gripod_F" "srifle_EBR_ARCO_point_grip_F",
		"hgun_P07_F"
	};
	magazines[] = {
		"16Rnd_9x21_Mag",
		"16Rnd_9x21_Mag",
		"16Rnd_9x21_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"SmokeShell"
	};
	items[] = {
		"Rangefinder"
	};
	linkedItems[] = {
		"V_Chestrig_khk",
		"H_Watchcap_blk",
		"ItemMap",
		"ItemCompass",
		"ItemWatch",
		"muzzle_snds_B",
		"ItemRadio",
		"muzzle_snds_L"
	};
	uniformClass = "U_B_GhillieSuit";
	backpack = "B_AssaultPack_mcamo"; // B_AssaultPack_mcamo B_AssaultPack_rgr_LAT
};
class EAST1
{
	displayName = "Gen Hans Von Beck"; // Name visible in the menu
	icon = "\A3\Ui_f\data\GUI\Cfg\Ranks\general_gs.paa"; // Icon displayed next to the name   //configfile >> "CfgRanks"
	// Alternative configuration pointing to a CfgVehicles class. Loadout will be copied from it.
	vehicle[] = {"O_Soldier_AT_F"};
	weapons[] = {
		"Binocular",
		"launch_B_Titan_short_F",
		"Titan_AT",
		// "hgun_Pistol_heavy_02_Yorris_F"
		// "hgun_Pistol_heavy_01_F" // "11Rnd_45ACP_Mag"
		// hgun_Pistol_heavy_01_MRD_F 
		// "hgun_Pistol_heavy_01_snds_F"
		"hgun_Pistol_heavy_01_MRD_F" 
	};
	magazines[] = {
		"11Rnd_45ACP_Mag",
		"11Rnd_45ACP_Mag",
		"11Rnd_45ACP_Mag",
		"6Rnd_45ACP_Cylinder",
		"6Rnd_45ACP_Cylinder",
		"6Rnd_45ACP_Cylinder",
		"Titan_AT",
		"Titan_AT",
		"Titan_AT",
		"Titan_AT",
		"SmokeShell"
	};
	items[] = {
		"Titan_AT",
		"Titan_AT",
		"FirstAidKit"

	};
	linkedItems[] = {
		"V_Chestrig_khk",
		"H_Watchcap_blk",
		"optic_Aco",
		"acc_flashlight",
		"ItemMap",
		"ItemCompass",
		"ItemWatch",
		"ItemRadio"
	};
	uniformClass = "O_B_CombatUniform_mcam_tshirt";
	backpack = "B_Carryall_cbr"; // B_AssaultPack_mcamo B_AssaultPack_rgr_LAT

};
class EAST2
{
	displayName = "Gen Victor Morder"; // Name visible in the menu
	icon = "\A3\Ui_f\data\GUI\Cfg\Ranks\general_gs.paa"; // Icon displayed next to the name   //configfile >> "CfgRanks"
	// Alternative configuration pointing to a CfgVehicles class. Loadout will be copied from it.
	vehicle[] = {
		"O_Soldier_AR_F" // "O_Soldier_AR_F";
	};
	weapons[] = {
		"LMG_Zafir_pointer_F", 		// "LMG_Zafir_pointer_F", 
		"Laserdesignator"
	 };
	magazines[] = {
		"acc_pointer_IR",  	// NEW 2014 07 30
		"optic_ACO_grn",	// NEW 2014 07 30
		"Laserbatteries", 
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"150Rnd_762x51_Box_Tracer",
		"SmokeShellGreen"
	};
	items[] = {
		"Medikit"
	};
	linkedItems[] = {
		"acc_pointer_IR",  	// NEW 2014 07 30
		"optic_ACO_grn_smg",	
		"V_Chestrig_khk",
		"ItemMap",
		"ItemCompass",
		"ItemWatch",
		"ItemRadio"
	};
	uniformClass = "U_I_G_resistanceLeader_F";
	vest = "V_RebreatherB";
	backpack = "B_Carryall_cbr"; 
	Headgear = "H_Beret_blk";
	Goggles = "G_Spectacles_Tinted";
};
class EAST3
{
	displayName = "Maj Nina Diederich"; // Name visible in the menu
	icon = "\A3\Ui_f\data\GUI\Cfg\Ranks\major_gs.paa"; // Icon displayed next to the name   //configfile >> "CfgRanks"
	// Alternative configuration pointing to a CfgVehicles class. Loadout will be copied from it.
	vehicle[] = {"O_soldier_M_F"};
	weapons[] = {
		"srifle_EBR_DMS_pointer_snds_F", // arifle_MXM_ARCO_point_gripod_F" "srifle_EBR_ARCO_point_grip_F",
		"hgun_P07_F"
	};
	magazines[] = {
		"16Rnd_9x21_Mag",
		"16Rnd_9x21_Mag",
		"16Rnd_9x21_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"20Rnd_762x51_Mag",
		"SmokeShell"
	};
	items[] = {
		"Rangefinder"
	};
	linkedItems[] = {
		"V_Chestrig_khk",
		"H_Watchcap_blk",
		"ItemMap",
		"ItemCompass",
		"ItemWatch",
		"muzzle_snds_B",
		"ItemRadio",
		"muzzle_snds_L"
	};
	uniformClass = "U_B_GhillieSuit";
	backpack = "B_AssaultPack_mcamo"; // B_AssaultPack_mcamo B_AssaultPack_rgr_LAT

};
};

When i get a little time ill try setting something up to see whats happening (i also want to check when and where file and function in params actually happen, as per the other thread ) but in the mean time i suggest you back through the logic of whats happening here, especially the part where players are monitoring the end time.

I've placed the follwing in initServer.sqf instead of initPlayerLocal.sqf

gameDuration = "TimeLimit" call BIS_fnc_getParamValue;
[gameDuration] spawn {
_time = time;
_gameDuration = _this select 0;
while {true} do {
	sleep 1;
	_countdown = _gameDuration - (time - _time);
	if (_countdown < -2) exitWith {"SideTickets" call BEAKS_fnc_endMissionServer};
	//if (_countdown < 10) exitWith {"end1" call BIS_fnc_endMission};
	};
};

SO the game ends when the bleedTickets reach 0 for one side or when the time expires. When the time expires I get the "MISSION COMPLETE" screen, but then 2 seconds later I have "YOUR SIDE WON/LOST" based on who ever has the majority/minority of bleedTickets from the function above in the initServer.sqf

Edited by BEAKSBY

Share this post


Link to post
Share on other sites
Yes, terribly sorry I didn't include the entire script...I assumed it was irrelavant. BUT YES, I do have a respawnTemplate in there. Could that trigger a game countdown ending?

Hey no worries, just wanted to make sure there was nothing else there that may cause this problem, but your right i cant see anything in there that would cause this.

What modules are you using? Are you using a 'Gameplay Modes -> SectorControl' ?? This is the only other thing i can see that would cause this and is scripted to call "End1".

If you are, from what you have shown over the last couple of months you have no need for this as you are handling all the bleed and time yourself. Which is all this module does when you have sectors present.

If not can you show me your mission.sqm or if you dont want to publicly post it can you PM it to me.

Share this post


Link to post
Share on other sites

Thanks Larrow,

I'm PM you my mission.sqm.

I do have sectorModules but when looking through it I didn't see anything that would lead to "END1" bis_fnc_endMission being triggered (Display of MISSION COMPLETE).

BIS_fnc_moduleSector.sqf

	--- Set sector owner ---
Parameter(s):
	0: OBJECT - sector module
	1: SIDE

Returns:
BOOL

--- Initialize ---
Parameter(s):
	0: OBJECT - sector module

Returns:
NOTHING
*/

private ["_logic","_units","_activated"];
_logic = [_this,0,objnull,[objnull,sideunknown,true]] call bis_fnc_param;
_units = [_this,1,[],[[],sideunknown]] call bis_fnc_param;
_activated = [_this,2,true,[true]] call bis_fnc_param;

//--- Return all sectors
if (typename _logic == typename true) exitwith {
missionnamespace getvariable ["BIS_fnc_moduleSector_sectors",[]]
};

//--- Return sectors belonging to a side
if (typename _logic == typename sideunknown) exitwith {
private ["_side","_sideID","_sideSectors"];
_side = _logic;
_sideID = _side call bis_fnc_sideID;
_sideSectors = missionnamespace getvariable ["BIS_fnc_moduleSector_sideSectors",[-1,-1,-1,-1,-1]];
if (_sideID in [0,1,2,3,4]) then {_sideSectors select _sideID} else {-1}
};

//--- Set side
if (typename _units == typename sideunknown) exitwith {
_logic setvariable ["owner",_units,true];
true
};

//--- Initialize the sector
if !(_activated) exitwith {};
_mode = [_this,3,"init",[""]] call bis_fnc_param;

switch _mode do {

case "init": {
	[_logic,[],_activated,"server"] spawn bis_fnc_moduleSector;
	waituntil {!isnil {_logic getvariable "finalized"}}; //--- Wait until the module is initialized
};

case "server": {
	/////////////////////////////////////////////////////////////////////////////////////
	// Server
	/////////////////////////////////////////////////////////////////////////////////////
	_loadingScreen = format ["BIS_fnc_moduleSector:%1",_logic];
	_loadingScreen call bis_fnc_startloadingscreen;

	//--- Prepare error handling
	_exitCode = {
		_sectorsError = missionnamespace getvariable ["BIS_fnc_moduleSector_sectorsError",[]];
		_sectorsError set [count _sectorsError,_logic];
		missionnamespace setvariable ["BIS_fnc_moduleSector_sectorsError",_sectorsError];
		publicvariable "BIS_fnc_moduleSector_sectorsError";
		 _loadingScreen call bis_fnc_endloadingscreen;
	};

	//--- Wait until previous sectors are initialized to maintain the same order as in editor
	waituntil {
		_sectors = (entities "ModuleSector_F") - (missionnamespace getvariable ["BIS_fnc_moduleSector_sectors",[]]) - (missionnamespace getvariable ["BIS_fnc_moduleSector_sectorsError",[]]);
		if (count _sectors > 0) then {(_sectors select 0) == _logic} else {true};
	};

	_logicParent = _logic;
	if (typeof _logic == "ModuleSectorDummy_F") then {
		{
			if (typeof _x == "ModuleSector_F") then {_logicParent = _x;};
		} foreach (synchronizedobjects _logic);
	};

	//--- Load params
	[_logic,"BIS_fnc_moduleSector_sector"] call bis_fnc_objectvar;
	_name = _logic getvariable ["Name",""];
	_designation = _logic getvariable ["Designation",""];
	_ownerLimit = (_logicParent getvariable ["OwnerLimit","0"]) call bis_fnc_parsenumber;
	_onOwnerChange = compile (_logicParent getvariable ["OnOwnerChange","true"]);
	_captureCoef = (_logicParent getvariable ["CaptureCoef","0.05"]) call bis_fnc_parsenumber;
	_costInfantry = (_logicParent getvariable ["CostInfantry","1"]) call bis_fnc_parsenumber;
	_costWheeled = (_logicParent getvariable ["CostWheeled","1"]) call bis_fnc_parsenumber;
	_costTracked = (_logicParent getvariable ["CostTracked","1"]) call bis_fnc_parsenumber;
	_costWater = (_logicParent getvariable ["CostWater","1"]) call bis_fnc_parsenumber;
	_costAir = (_logicParent getvariable ["CostAir","1"]) call bis_fnc_parsenumber;
	_costPlayers = compile (_logicParent getvariable ["CostPlayers","1"]);
	_defaultOwner = (_logicParent getvariable ["DefaultOwner","-1"]) call bis_fnc_parsenumber;
	_taskOwner = (_logicParent getvariable ["TaskOwner",0]) call bis_fnc_parsenumber;
	_taskTitle = _logicParent getvariable ["TaskTitle","%1"];
	_taskDescription = _logicParent getvariable ["TaskDescription","%1%2%3"];
	_scoreReward = (_logicParent getvariable ["ScoreReward",0]) call bis_fnc_parsenumber;
	_sides = _logic getvariable ["sides",[]]; //--- Not configurable in module attributes, only by script
	_useDefaultSides = !isnil {_logic getvariable "sides"};

	//--- Register the expression as a scripted event handler
	[_logic,"ownerChanged",_onOwnerChange] call bis_fnc_addscriptedeventhandler;

	//--- Load visuals
	if (_name == "") then {
		_nameID = ["BIS_fnc_moduleSector_nameID",1] call bis_fnc_counter;
		_nameID = ((_nameID - 1) % 26) + 1;
		_name = _nameID call bis_fnc_phoneticalWord;
		_logic setvariable ["name",_name];
	};
	if (_designation == "") then {_designation = _name;};
	_designation = tostring [toarray _designation select 0];
	_markerName = if ((toarray _name select 0) == (toarray _designation select 0)) then {_name} else {format ["%1: %2",_designation,_name];};

	_icon = "n_installation";
	_iconTexture = _icon call bis_fnc_textureMarker;

	//--- Load synced objects
	_sectorsModules = count (entities "ModuleSector_F");
	_sectors = missionnamespace getvariable ["BIS_fnc_moduleSector_sectors",[]];
	_sectorID = count _sectors;
	_areas = [];
	_sideUnits = [[],[],[],[],[],[]];
	_sectorScore = [0,0,0,0,0,0];
	_sideScore = [0,0,0,0,0,0];
	_tasks = ["","","","","",""];
	_taskOrders = [true,true,true,true,true,true];
	_flags = [];
	_markersArea = [];
	_markerIcon = "";
	_markerIconText = "";
	_taskDescriptionUnlocks = "";
	_unlockTriggers = [[],[],[],[],[]];

	_fnc_initArea = {
		_trigger = _this;
		_areas = _areas - [_trigger];
		_areas set [count _areas,_trigger];

		_trigger settriggeractivation ["any","present",false];
		_trigger settriggerstatements ["false","",""];
		_trigger settriggertype "none";

		_triggerMarkers = _trigger getvariable ["markers",[]];
		_markerArea = createmarker ["BIS_fnc_moduleSector_area" + str _trigger,position _trigger];
		_markerArea setmarkerbrush "grid";
		_markerArea setmarkercolor "colorwhite";
		_markerArea setmarkeralpha 0;
		_markersArea set [count _markersArea,_markerArea];
		_triggerMarkers set [count _triggerMarkers,_markerArea];

		if (_markerIcon == "") then {
			_markerIcon = createmarker ["BIS_fnc_moduleSector_icon" + str _logic,position _trigger];
			_markerIcon setmarkertype _icon;
			_markerIcon setmarkercolor "colorwhite";
			//_markerIcon setmarkertext _markerName;
			_markerIcon setmarkersize [1.5,1.5];
			_markerIcon setmarkeralpha 0;
			_triggerMarkers set [count _triggerMarkers,_markerIcon];

			_markerIconText = createmarker ["BIS_fnc_moduleSector_iconText" + str _logic,position _trigger];
			_markerIconText setmarkertype "EmptyIcon";
			_markerIconText setmarkercolor "colorblack";
			_markerIconText setmarkertext _markerName;
			_markerIconText setmarkersize [1.5,1.5];
			_markerIconText setmarkeralpha 0;
			_triggerMarkers set [count _triggerMarkers,_markerIconText];
		};
		_trigger setvariable ["markers",_triggerMarkers];
		_trigger setvariable ["pos",[0,0,0]];

		//--- Show sector rewards
		{
			_xtype = tolower typeof _x;
			switch _xType do {
				case "modulerespawnposition_f": {
					_xTypeID = (_x getvariable ["Type","0"]) call bis_fnc_parsenumber;
					_xSideID = (_x getvariable ["Side","-1"]) call bis_fnc_parsenumber;
					_xSideName = if (_xSideID < 0) then {localize "STR_A3_CfgVehicles_ModuleRespawnPosition_F_Arguments_Side_values_Leader_0"} else {_xSideID call bis_fnc_sidename};

					_xMarkerType = ["respawn_inf","respawn_unknown","respawn_motor","respawn_armor","respawn_air","respawn_plane"] select _xTypeID;
					_xMarkerTypeName = gettext (configfile >> "cfgmarkers" >> _xMarkerType >> "name");
					_xMarkerIcon = (gettext (configfile >> "cfgmarkers" >> _xMarkerType >> "texture")) call bis_fnc_textureMarker;
					_taskDescriptionUnlocks = _taskDescriptionUnlocks + format ["<img image='%1' width='16'/> %2 (%3)<br />",_xMarkerIcon,_xMarkerTypeName,_xSideName];
				};
				case "modulerespawnvehicle_f": {
					_xLogic = _x;
					{
						_xCfg = configfile >> "cfgvehicles" >> typeof _x;
						_xSimulation = tolower gettext (_xCfg >> "simulation");
						if (_xSimulation in ["carx","tankx","helicopterx","helicopterrtd","planex","shipx","submarinex"]) then {
							_xName = gettext (_xCfg >> "displayName");
							_xPicture = (gettext (_xCfg >> "picture")) call bis_fnc_textureVehicleIcon;
							_xPosition = (_xLogic getvariable ["Position","0"]) call bis_fnc_parsenumber;
							_xSide = switch _xPosition do {
								case 2: {(getnumber (_xCfg >> "side")) call bis_fnc_sideName;};
								case 3;
								case 4;
								case 5;
								case 6: {(_xPosition - 3) call bis_fnc_sideName;};
								default {""};
							};
							if (_xSide != "") then {_xSide = format ["(%1)",_xSide];};
							_taskDescriptionUnlocks = _taskDescriptionUnlocks + format ["<img image='%1' width='16'/> %2 %3<br />",_xPicture,_xName,_xSide];
						};
					} foreach (synchronizedobjects _x);
				};
			};
		} foreach (synchronizedobjects _trigger);
	};

	{
		switch (true) do {
			case (typeof _x == "LocationArea_F"): {
				{
					if (_x iskindof "EmptyDetector") then {
						_x call _fnc_initArea;
					};
				} foreach (synchronizedobjects _x);
			};
			case (typeof _x == "MiscUnlock_F"): {
				{
					if (_x iskindof "EmptyDetector") then {
						_trigger = _x;
						_side = triggeractivation _trigger select 0;
						_sideIDs = switch _side do {
							case "EAST";
							case "WEST";
							case "GUER";
							case "CIV";
							case "LOGIC": {[["EAST","WEST","GUER","CIV","LOGIC"] find _side];};
							case "ANY": {[0,1,2,3,4]};
							default {[]};
						};
						{
							_sideTriggers = _unlockTriggers select _x;
							_sideTriggers set [count _sideTriggers,_trigger];

							_triggerStatements = triggerstatements _trigger;
							_triggerStatements set [
								0,
								format [
									"(%1 getvariable ['owner',sideunknown]) == %2",
									_logic,
									["east","west","resistance","civilian","sideunknown"] select _x
								]
							];
							_trigger settriggerstatements _triggerStatements;
						} foreach _sideIDs;
					};
				} foreach (synchronizedobjects _x);

			};
			case (_x iskindof "FlagCarrierCore"): {
				_flags set [count _flags,_x];
			};
		};
	} foreach (synchronizedobjects _logic);

	//--- No synced triggers found - create a default one
	if (count _areas == 0) then {
		_areaTrigger = createtrigger ["emptydetector",position _logic];
		_areaTrigger settriggerarea [50,50,0,false];
		_areaTrigger call _fnc_initArea;
		_areaTrigger attachto [_logic];
	};

	//--- Explain capture ratios
	_participant = "<font color='%2'>%1</font>";
	_participantColor = {if (_this > 0) then {"#ffffff"} else {"#33ffffff"}};
	_taskDescriptionCapture = format [
		"<br /><br /><font size='18'>%1</font><br />%2 / %3 / %4 / %5 / %6",
		localize "str_a3_cfgvehicles_modulesector_f_forces",
		format [_participant,gettext (configfile >> "CfgVehicleClasses" >> "Men" >> "displayName"),_costInfantry call _participantColor],
		format [_participant,gettext (configfile >> "CfgVehicleClasses" >> "Car" >> "displayName"),_costWheeled call _participantColor],
		format [_participant,gettext (configfile >> "CfgVehicleClasses" >> "Armored" >> "displayName"),_costTracked call _participantColor],
		format [_participant,gettext (configfile >> "CfgVehicleClasses" >> "Air" >> "displayName"),_costAir call _participantColor],
		format [_participant,gettext (configfile >> "CfgVehicleClasses" >> "Ship" >> "displayName"),_costWater call _participantColor]
		//format [_participant,localize "str_disp_mp_players_title",_costPlayers call _participantColor]
	];

	//--- Explain sector unlocks
	if (_taskDescriptionUnlocks != "") then {
		_taskDescriptionUnlocks = format ["<br /><br /><font size='18'>%1</font><br />%2",localize "str_a3_cfgvehicles_modulesector_f_rewards",_taskDescriptionUnlocks];
	};

	_taskPos = position (_areas select 0);
	{
		switch (true) do {
			case (_x iskindof "SideBLUFOR_F");
			case (_x iskindof "SideOPFOR_F");
			case (_x iskindof "SideResistance_F"): {
				_side = (["SideOPFOR_F","SideBLUFOR_F","SideResistance_F"] find (typeof _x)) call bis_fnc_sideType;
				_sides set [count _sides,_side];
			};
		};
	} foreach ([_logic,[typeof _logic]] call bis_fnc_allSynchronizedObjects);

	if (count _sides == 0 && _useDefaultSides) then {_sides = [east,west,resistance,civilian];};
	//if (count _sides == 0) exitwith {["No sides defined for %1",_logic] call bis_fnc_error; [] call _exitCode};
	if (_defaultOwner >= 0 && !((_defaultOwner call bis_fnc_sidetype) in _sides)) then {["Default owner %1 is not a competing side for sector %2. No default owner used instead.",_defaultOwner call bis_fnc_sidetype,_name] call bis_fnc_error;};

	//--- Save global variables
	_logic setvariable ["finalized",false,true];
	_logic setvariable ["pos",markerpos _markerIcon,true];
	_logic setvariable ["areas",_areas,true];
	_logic setvariable ["sides",_sides,true];
	_logic setvariable ["flags",_flags,true];
	_logic setvariable ["tasks",_tasks,true];
	_logic setvariable ["designation",_designation,true];

	_sectors set [count _sectors,_logic];
	missionnamespace setvariable ["BIS_fnc_moduleSector_sectors",_sectors];
	publicvariable "BIS_fnc_moduleSector_sectors";

	if (isnil {BIS_fnc_moduleSector_sideSectors}) then {BIS_fnc_moduleSector_sideSectors = [0,0,0,0,0];};

	//--- Execute local function
	//[[_logic,[],true,"player"],"bis_fnc_moduleSector",_sides - [sideunknown],true] call bis_fnc_mp;

	_fnc_conversion = {
		_total = 0;
		_result = +(_this select 0);
		_coef = _this select 1;
		{_total = _total + _x;} foreach _result;
		if (_total > 1) then {
			{
				_result set [_foreachindex,(_result select _foreachindex) / _total * _coef];
			} foreach _result;
		};
		_result
	};
	_fnc_threat = {
		private ["_veh","_coef","_scanCrew","_threat","_score"];
		_veh = _this select 0;
		_coef = _this select 1;
		_scanCrew = _this select 2;
		_threat = getarray (configfile >> "cfgvehicles" >> typeof _veh >> "threat");

		_score = 0;
		{_score = _score + _x} foreach _threat;
		_score = _score * _coef;
		if (isplayer _veh) then {_score = _score * _costPlayersLocal;};

		if (_scanCrew) then {
			{
				_score = _score + ([_x,_costInfantry,false] call _fnc_threat);
				if (isplayer _x) then {_score = _score * _costPlayersLocal;};
			} foreach (crew _veh - [_veh]);
		};
		_score
	};
	_fnc_sort = {
		_unsorted = +_sectorScore;
		_sorted = [];
		while {count _sorted != count _unsorted} do {
			_max = -1;
			_maxIndex = -1;
			_index = count _sorted;
			{
				if (_x > _max) then {
					_max = _x;
					_maxIndex = _foreachindex;
					_sorted set [_index,_maxIndex];
				};
			} foreach _unsorted;
			_unsorted set [_maxIndex,-1];
		};
		_sorted
	};

	//--- Wait until scripts are initialized (to avoid being faster than initServer.sqf)
	waituntil {!isnil "bis_fnc_init"};
	_loadingScreen call bis_fnc_endloadingscreen;


	//--- Global loop -----------------------------------------------------------
	_allSides = [east,west,resistance,civilian,sideunknown,sideenemy];
	_time = 0;
	_pos = position _logic;
	_owner = sideEnemy;
	_ownerOld = _owner;
	_maxScoreOld = 0;
	_firstLoop = true;
	_sidesOld = [];
	_sidesOldStr = str _sidesOld;
	_nameOld = _name;
	_step = 0;
	_taskTitles = [];
	_taskDescriptions = [];
	_curatorObject = _logic getvariable ["curatorObject",objnull];
	_logicAreaShow = !isnull _curatorObject;
	_logicArea = objnull;
	_logicAreaSize = 0;

	while {!(isnull _logic) && (simulationenabled _logic) && !(_logic getvariable ["finalized",false])} do {

		//--- Load variables
		_areas = _logic getvariable ["areas",_areas];
		_sides = _logic getvariable ["sides",_sides];
		_flags = _logic getvariable ["flags",_flags];
		_tasks = _logic getvariable ["tasks",_tasks];
		_ownerForced = _logic getvariable ["owner",_owner];
		_name = _logic getvariable ["name",_name];
		_designation = _logic getvariable ["designation",_designation];
		_logicAreaUpdate = false;

		//--- Detect participating sides
		if (str _sides != _sidesOldStr) then {

			//--- Show MP progress HUD
			[[_logic,[],true,"player"],"bis_fnc_moduleSector",_sides - _sidesOld,true] call bis_fnc_mp;

			//--- Get task titles and descriptions per side (scripted option only)
			_taskTitle = _logicParent getvariable ["TaskTitle","%1"];
			_taskTitles = _taskTitle;
			if (typename _taskTitles == typename "") then {
				_taskTitles = [_taskTitles];
			};
			_taskTitle = "";
			for "_i" from 0 to 5 do {
				_taskTitle = [_taskTitles,_i,_taskTitle,[""]] call bis_fnc_paramin;
				_taskTitles set [_i,_taskTitle];
			};
			_taskDescription = _logicParent getvariable ["TaskDescription","%1%2%3"];
			_taskDescriptions = _taskDescription;
			if (typename _taskDescriptions == typename "") then {
				_taskDescriptions = [_taskDescriptions];
			};
			_taskDescription = "";
			for "_i" from 0 to 5 do {
				_taskDescription = [_taskDescriptions,_i,_taskDescription,[""]] call bis_fnc_paramin;
				_taskDescriptions set [_i,_taskDescription];
			};

			//--- Show / hide markers
			if (count _sides > 0) then {
				if (markeralpha _markerIcon == 0) then {
					{_x setmarkeralpha 1;} foreach [_markerIcon,_markerIconText];
					{if (markerColor _x == "colorblack") then {_x setmarkeralpha 0.25;} else {_x setmarkeralpha 0.5;};} foreach _markersArea;
				};
			} else {
				if (markeralpha _markerIcon == 1) then {
					{_x setmarkeralpha 0;} foreach (_markersArea + [_markerIcon,_markerIconText]);
				};
			};

			//--- Add sides
			{
				_side = _x;
				_sideID = _side call bis_fnc_sideID;

				_task = _tasks select _sideID;
				_taskOrder = true;
				_addTask = switch _taskOwner do {
					case 0: {false};
					case 1: {true};
					case 2: {_sideID == _defaultOwner};
					case 3: {_sideID != _defaultOwner};
				};
				if (_task == "" && _addTask) then {

					//--- Set currents tasks from the top (false) or from the bottom (true)
					_taskOrder = if (_defaultOwner >= 0) then {
						[_side,_defaultOwner call bis_fnc_sidetype] call bis_fnc_arefriendly
					} else {
						([_side,east] call bis_fnc_arefriendly) || !([_side,west] call bis_fnc_arefriendly)
					};

					//--- Add tasks
					_taskTitle = _taskTitles select _sideID;
					_taskDescription = _taskDescriptions select _sideID;
					if (_taskTitle == "") then {_taskTitle = "%1";};
					if (_taskDescription == "") then {_taskDescription = "%1%2%3";};
					_taskID = str _logic + str _side;
					_taskPrio = _sectorID / _sectorsModules;
					_taskCurrent = if (_taskOrder) then {_sectorID == _sectorsModules - 1} else {_taskPrio = 1 - _taskPrio; _sectorID == 0};
					_task = [_taskID,_side,[[_taskDescription,_name,_taskDescriptionCapture,_taskDescriptionUnlocks],[_taskTitle,_name],_name],_taskPos,_taskCurrent,_taskPrio] call bis_fnc_setTask;
				};
				_scoreDefault = if (_sideID == _defaultOwner) then {1} else {0};

				_sideUnits set [_sideID,[]];
				_sectorScore set [_sideID,_scoreDefault];
				_sideScore set [_sideID,_scoreDefault];
				_tasks set [_sideID,_task];
				_taskOrders set [_sideID,_taskOrder];
			} foreach (_sides - _sidesOld);

			//--- Remove sides
			{
				_side = _x;
				_sideID = _side call bis_fnc_sideID;
				_task = _tasks select _sideID;
				if (_task != "") then {
					//[_task,nil,nil,nil,"canceled"] call bis_fnc_settask;
					_task call bis_fnc_deletetask;
					_tasks set [_sideID,""];
				};
			} foreach (_sidesOld - _sides);

			_logic setvariable ["tasks",_tasks,true];
		};
		_sidesOld = _sides;
		_sidesOldStr = str _sidesOld;
		_sides = [sideunknown] + _sides;

		//--- Name changed
		if (_name != _nameOld) then {
			_designation = tostring [toarray _name select 0];
			_logic setvariable ["designation",_designation,true];
			_markerIconText setmarkertext _name;
			{
				if (_x != "") then {
					_taskTitle = _taskTitles select _foreachindex;
					_taskDescription = _taskDescriptions select _foreachindex;
					if (_taskTitle == "") then {_taskTitle = "%1";};
					if (_taskDescription == "") then {_taskDescription = "%1%2%3";};
					[_x,nil,[[_taskDescription,_name,_taskDescriptionCapture,_taskDescriptionUnlocks],[_taskTitle,_name],_name]] call bis_fnc_setTask;
				};
			} foreach _tasks;
			_nameOld = _name;
		};

		//--- Position changed
		if (position _logic distance _pos > 0) then {
			_pos = position _logic;
			{
				[_x,nil,nil,_pos] call bis_fnc_setTask;
			} foreach _tasks;
		};

		//--- Detect leading side
		_owner = sideUnknown;
		_timeCoef = _captureCoef * (time - _time);

		_sectorScore = [_sectorScore,1] call _fnc_conversion;
		_sectorScoreSorted = _sectorScore call _fnc_sort;

		_side1ID = _sectorScoreSorted select 0;
		_side1score = _sectorScore select _side1ID;
		_scoreDiffAdd = 0;
		_scoreDiffRemove = 0;
		if (count _sides > 1) then {
			_side2ID = _sectorScoreSorted select 1;
			_side2score = _sectorScore select _side2ID;
			_scoreDiffAdd = (_side1score - _side2score) * _timeCoef;
			_scoreDiffRemove = _scoreDiffAdd / ((count _sides - 1) max 1);
		};

		//--- Force owner
		if (_ownerForced != _ownerOld && _ownerForced in _sides) then {
			_ownerForcedID = _ownerForced call bis_fnc_sideID;
			{
				_sideScore set [_foreachindex,if (_foreachindex == _ownerForcedID) then {1} else {0}];
			} foreach _sideScore;
		};

		//--- Increase score of the leader, decrease score of others
		_maxScore = 0;
		_ownerScore = 0;
		_totalScore = 0;
		_ownerID = -1;
		_sideUnitsLocal = +_sideUnits;
		{
			if (_x in _sides) then {
				_xScore = _sideScore select _foreachindex;
				_xScore = if (_foreachindex == _side1ID) then {
					_xScore + _scoreDiffAdd
				} else {
					(_xScore - _scoreDiffRemove) max 0
				};
				if (_xScore >= _ownerLimit && _xScore > _ownerScore) then {
					_owner = _x;
					_ownerScore = _xScore;
					_ownerID = _foreachindex;
				};
				_totalScore = _totalScore + _xScore;
				if (_foreachindex > 0) then {_maxScore = _maxScore max _xScore min 1;};
				_sideScore set [_foreachindex,_xScore];
				_sectorScore set [_foreachindex,0];
				_sideUnits set [_foreachindex,[]];
			} else {
				_sideScore set [_foreachindex,0];
			};
		} foreach _allSides;//_sides;
		if (_totalScore < 0.99999) then {_sideScore set [4,1 - _totalScore];}; //--- Don't compare with 1, because it's not always 1 ;)
		_sideScore = [_sideScore,1] call _fnc_conversion;

		//--- Store sector score
		_logic setvariable ["sideScore",_sideScore,true];

		//--- Store sector status
		_contested = _maxScore != _maxScoreOld;
		_contestedOld = _logic getvariable ["contested",false];
		if ((_contested && !_contestedOld) || (!_contested && _contestedOld)) then {
			_logic setvariable ["contested",_contested,true];
		};
		_maxScoreOld = _maxScore;

		//--- Execute code when ownership changes
		if (_owner != _ownerOld) then {

			//--- Call custom code
			[_logic,"ownerChanged",[_logic,_owner,_ownerOld]] call bis_fnc_callscriptedeventhandler;

			//--- Broadcast
			_logic setvariable ["owner",_owner,true];

			//--- Reward
			_owner addscoreside _scoreReward;

			//--- Update total count
			_ownerSideID = _owner call bis_fnc_sideID;
			_ownerOldSideID = (_ownerOld call bis_fnc_sideID) min 4;
			BIS_fnc_moduleSector_sideSectors set [_ownerSideID,(BIS_fnc_moduleSector_sideSectors select _ownerSideID) + 1];
			BIS_fnc_moduleSector_sideSectors set [_ownerOldSideID,((BIS_fnc_moduleSector_sideSectors select _ownerOldSideID) - 1) max 0];
			publicvariable "BIS_fnc_moduleSector_sideSectors";

			//--- Update markers
			//_iconColor = [0.25,0.25,0.25,0.5];
			_markerColor = "colorblack";
			if (_owner != sideUnknown) then {
				//_iconColor = _owner call bis_fnc_sidecolor;
				_markerColor = [_owner,true] call bis_fnc_sidecolor;
			};
			_icon = ["o_installation","b_installation","n_installation","n_installation","u_installation"] select ((_owner call bis_fnc_sideID) min 4);
			_iconTexture = _icon call bis_fnc_texturemarker;
			_markerIcon setmarkertype _icon;
			_markerIcon setmarkercolor _markerColor;
			{
				_x setmarkercolor _markerColor;
				if (markeralpha _x > 0) then {
					if (_markerColor == "colorblack") then {_x setmarkeralpha 0.25;} else {_x setmarkeralpha 0.5;};
				};
			} foreach _markersArea;
			//_logic setvariable ["ownerTexture",_iconTexture,true];
			//_logic setvariable ["ownerColor",_iconColor,true];

			//--- Show notification
			_ownerName = _owner call bis_fnc_sidename;
			if (_owner != sideunknown) then {
				//--- Show it to involved sides and curators (sector itself cannot belong to a curator, but objective module can)
				_curatorObject = _logic getvariable ["curatorObject",objnull];
				_curators = objectcurators _curatorObject;
				{
					//--- Remove curators who are already on side with access to the sector to prevent duplicate notifications
					if (((getassignedcuratorunit _x) call bis_fnc_objectside) in _sides) then {_curators = _curators - [_x];};
				} foreach _curators;
				[[format ["sectorCaptured%1",_owner],[_name,_ownerName,_iconTexture,_designation]],"BIS_fnc_showNotification",_sides - [_ownerOld] + _curators] call bis_fnc_mp;
				[[format ["sectorLost%1",_owner],[_name,_ownerName,_iconTexture,_designation]],"BIS_fnc_showNotification",_ownerOld] call bis_fnc_mp;
			};

			//--- Update flag (not for default owner)
			if ((_firstLoop && _defaultOwner < 0) || !_firstLoop) then {
				_flagTexture = if (_ownerID < 0) then {
					""
				} else {
					_units = _sideUnitsLocal select _ownerID;
					if (count _units > 0) then {
						_ownerFaction = gettext (configfile >> "cfgvehicles" >> typeof effectivecommander (_units select 0) >> "faction");
						gettext (configfile >> "cfgfactionclasses" >> _ownerFaction >> "flag");
					} else {
						(_owner call bis_fnc_sidecolor) call bis_fnc_colorRGBAtoTexture
					};
				};
				{_x setflagtexture _flagTexture;} foreach _flags;
			};

			//--- Update tasks (not in the first run to prevent creating task before others)
			if !(_firstLoop) then {
				_ownerID = _owner call bis_fnc_sideID;//_sides find _owner;
				_firstSector = objnull;
				_lastSector = objnull;
				{
					if (simulationenabled _x || _x == _logic) then {
						if (isnull _firstSector) then {_firstSector = _x;};
						_lastSector = _x;
					};
				} foreach _sectors;
				{
					if (_x != "") then {
						_taskOrder = _taskOrders select _foreachindex;
						_taskState = if (_foreachindex == _ownerID) then {
							"SUCCEEDED"
						} else {
							_compareSector = if (_taskOrder) then {_lastSector} else {_firstSector};
							if (_logic == _compareSector) then {"ASSIGNED"} else {"CREATED"}
						};
						[_x,nil,nil,nil,_taskState,nil,false] call bis_fnc_setTask;
					};
				} foreach _tasks;
			};

			_logicAreaUpdate = true;
		};
		_ownerOld = _owner;
		_time = time;

		//--- Update area positions
		{
			_trigger = _x;
			_triggerPos = position _trigger;
			if (_triggerPos distance (_trigger getvariable ["pos",[0,0,0]]) > 0) then {
				_trigger setvariable ["pos",_triggerPos];
				_markers = _trigger getvariable ["markers",[]];
				{
					_x setmarkerpos position _trigger;
					if (markertype _x == "") then {
						_triggerArea = triggerarea _trigger;
						if (_triggerArea select 3) then {_x setmarkershape "rectangle";} else {_x setmarkershape "ellipse";};
						_x setmarkerdir (_triggerArea select 2);
						_x setmarkersize [_triggerArea select 0,_triggerArea select 1];
						_logicAreaSize = (_triggerArea select 0) * 2;
						_logicAreaUpdate = true;
					};
				} foreach _markers;
				if (_markerIcon in _markers) then {
					_logic setvariable ["pos",markerpos _markerIcon,true];
				};
			};
		} foreach _areas;

		//--- Update 3D marker
		if (_logicAreaShow && _logicAreaUpdate) then {
			if (_logicAreaSize in [100,200,500]) then {
				_logicAreaType = format ["LogicSector%1%2m_F",_owner,_logicAreaSize];
				if (_logicAreaType != typeof _logicArea) then {
					deletevehicle _logicArea;
					_logicArea = createvehicle [_logicAreaType,position _curatorObject,[],0,"none"];
					_logicArea attachto [_curatorObject,[0,0,0]];
					{
						_hideObjects = _x getvariable ["hideObjects",[]];
						_hideObjects = _hideObjects + [_logicArea] - [objnull];
						_x setvariable ["hideObjects",_hideObjects,true];
					} foreach (objectcurators _curatorObject);
				};
			} else {
				deletevehicle _logicArea;
			};
		};

		//--- Calculate side strengths for the next cycle
		_costPlayersLocal = _costPlayers call bis_fnc_parsenumber;
		{
			{
				if ({alive _x} count crew _x > 0) then {
					_side = side group _x;
					if (_side in _sides) then {
						_sideID = _side call bis_fnc_sideID;//_sides find _side;
						_units = _sideUnits select _sideID;
						if !(_x in _units) then {
							_score = _sectorScore select _sideID;

							_simulation = gettext (configfile >> "cfgvehicles" >> typeof _x >> "simulation");

							_xScore = switch (tolower _simulation) do {
								case "soldier": {
									[_x,_costInfantry,true] call _fnc_threat;
								};
								case "carx": {
									[_x,_costWheeled,true] call _fnc_threat;
								};
								case "tankx": {
									[_x,_costTracked,true] call _fnc_threat;
								};
								case "shipx";
								case "submarinex": {
									[_x,_costWater,true] call _fnc_threat;
								};
								case "helicopterrtd";
								case "airplanex";
								case "helicopterx": {
									[_x,_costAir,true] call _fnc_threat;
								};
								default {
									0
								};
							};
							_score = _score + _xScore;
							_sectorScore set [_sideID,_score];

							_units set [count _units,_x];
							_sideUnits set [_sideID,_units];
						};
					};
					sleep 0.05;
				};
			} foreach list _x;
			sleep 0.1;
		} foreach _areas;

		//--- Loop counter for outside use
		_step = _step + 1;
		_logic setvariable ["step",_step];

		_firstLoop = false;
		sleep 0.1;
	};

	//--- Sector finalized
	if (isnull _logic) then {

		_sectors = missionnamespace getvariable ["BIS_fnc_moduleSector_sectors",[]];
		_sectors = _sectors - [_logic,objnull];
		missionnamespace setvariable ["BIS_fnc_moduleSector_sectors",_sectors];
		publicvariable "BIS_fnc_moduleSector_sectors";

		//--- Delete markers
		{
			deletemarker _x;
		} foreach (_markersArea + [_markerIcon,_markerIconText]);
	} else {
		//--- Mark as finalized globaly (enableSImulation is local only)
		_logic setvariable ["finalized",true,true];
		_logic setvariable ["contested",false,true];

		//--- Make markers transparent
		{
			_x setmarkeralpha (markeralpha _x * 0.5);
		} foreach (_markersArea + [_markerIcon,_markerIconText]);
	};

	//--- Delete 3D marker
	deletevehicle _logicArea;

	//--- Activate area triggers
	{
		_x settriggeractivation ["any","present",false];
		_x settriggerstatements ["true","",""];
		_x settriggertype "none";
	} foreach _areas;

	//--- Finalize the tasks
	_ownerID = _owner call bis_fnc_sideID;//_sides find _owner;
	{
		if (_x != "") then {
			_taskState = if (_foreachindex == _ownerID) then {"SUCCEEDED"} else {"CANCELED"};
			[_x,nil,nil,nil,_taskState] call bis_fnc_setTask;
		};
	} foreach _tasks;
};
case "player": {
	/////////////////////////////////////////////////////////////////////////////////////
	// Player
	[_logic,[],true,"area"] call bis_fnc_moduleSector;

	("RscMPProgress" call bis_fnc_rscLayer) cutrsc ["RscMPProgress","plain"];

	waituntil {
		sleep 0.1;
		(_logic getvariable ["finalized",false]) || (isnull _logic)
	};
	_logic enablesimulation false;
};
case "area": {
	/////////////////////////////////////////////////////////////////////////////////////
	// Update default trigger
	_areas = _logic getvariable ["areas",[]];
	_size = _logic getvariable ["size",0];
	{
		_x settriggeractivation ["any","present",false];
		_x settriggerstatements ["false","",""];
		_x settriggertype "none";
		if (_size > 0) then {
			_x settriggerarea [_size,_size,0,false];
		};
	} foreach _areas;
};
};

Share this post


Link to post
Share on other sites

Not sectorModules but sectorControlModules. I will have a look through your PM when i get it.

Share this post


Link to post
Share on other sites
Not sectorModules but sectorControlModules. I will have a look through your PM when i get it.

I also don't see anything in the

BIS_fnc_moduleMPTypeSectorControl.sqf

["BIS_fnc_moduleMPTypeSectorControl"] call bis_fnc_startLoadingScreen;

_logic = [_this,0,objnull,[objnull]] call bis_fnc_param;
_units = [_this,1,[],[[]]] call bis_fnc_param;

enablesaving [false,false];

//--- Global variable declaration
_path = "\a3\missions_f_curator\MPTypes\SectorControl\";
[
_path,
"BIS_fnc_moduleMPTypeSectorControl_",
[
	"initPlayerLocal",
	"initPlayerServer",
	"initCurator",
	"initCurator",
	"missionTasks",
	"missionConversations"
]
] call bis_fnc_loadFunctions;

//--- Server-side FSM declaration
BIS_fnc_moduleMPTypeSectorControl_missionFlowFSM = _path + "missionFlow.fsm";
BIS_fnc_moduleMPTypeSectorControl_sectorFSM = _path + "sector.fsm";

//--- Detect synchronized
_sides = [[],[],[]];
{
_xType = typeof _x;
switch _xType do {

	case "SideBLUFOR_F";
	case "SideOPFOR_F";
	case "SideResistance_F": {
		_sideID = ["SideOPFOR_F","SideBLUFOR_F","SideResistance_F"] find _xType;
		if (_sideID >= 0) then {
			_side = _sideID call bis_fnc_sideType;
			_x setvariable ["side",_side,true];

			_xSynced = synchronizedobjects _x;
			_x setvariable ["BIS_moduleMPTypeSectorControl_mission",_logic];

			_curators = [];
			{
				if (_x call bis_fnc_isCurator) then {_curators set [count _curators,_x];};
			} foreach _xSynced;

			_sides set [_sideID,[_side,_x,+_curators]];
		};
	};
};
} foreach (_logic call bis_fnc_allsynchronizedobjects);

//--- Remove empty sides
{
if (count _x == 0) then {_sides set [_foreachindex,-1];};
} foreach _sides;
_sides = _sides - [-1];

_logic setvariable ["sides",_sides,true];

//--- Init curator
[_logic] call BIS_fnc_moduleMPTypeSectorControl_initCurator;

//--- Execute player scripts
[[_logic],"BIS_fnc_moduleMPTypeSectorControl_initPlayerLocal",true,true] call bis_fnc_mp;

//--- onPlayerConnected
["BIS_fnc_moduleMPTypeSectorControl_initPlayerServer",_logic] call bis_fnc_onPlayerConnected;

//--- Wait for modules to initialize -------------------------------------------------------------------------------------------------
waituntil {!isnil {bis_fnc_init}};

//--- Initialize HQ speakers
{
_var = "BIS_HQ_" + str _x;
missionnamespace setvariable [_var,_x call bis_fnc_modulehq];
publicvariable _var;
} foreach [west,east,resistance];

//--- Main mission flow
BIS_fnc_moduleMPTypeSectorControl_missionFlow = [_logic] execfsm BIS_fnc_moduleMPTypeSectorControl_missionFlowFSM;

if (isdedicated || true) then {["BIS_fnc_moduleMPTypeSectorControl"] call bis_fnc_endLoadingScreen;};
true

Share this post


Link to post
Share on other sites

This

BIS_fnc_moduleMPTypeSectorControl_missionFlowFSM = _path + "missionFlow.fsm"; 

Loads

\a3\missions_f_curator\MPTypes\SectorControl\missionFlow.fsm

Which starts bleed monitoring

{
_sides set [count _sides,_x select 0];
} foreach _sidesArrays;
[_sides] call bis_fnc_bleedTickets;

and

monitors time and tickets

_losingSideData = [_sides] call bis_fnc_respawnTickets;

(_losingSideData select 1) == 0
||
([] call bis_fnc_missionTimeLeft) == 0
||
!simulationenabled _logic
||
isnull _logic

Which if tickets or time are 0 does

_losingSide = _losingSideData select 0;
{
_side = _x select 0;
_sideLogic = _x select 1;
_sideCurators = _x select 2;

_end = if ([_side,_losingSide] call bis_fnc_areFriendly) then {"TeamLost"} else {"TeamWon"};

[size=4][b][[_end],"bis_fnc_endmission",_side] call bis_fnc_mp;[/b][/size]
} foreach _sidesArrays;

TeamLost/TeamWon as standard dont exist in CfgDebriefing so it uses the default end instead.

If you are handling the bleeding and time yourself you do NOT need a sectorControl module. The control module is for dropping in your map if you want all this handled for you , it is a drag and drop option for quickly setting up a sector control game and is NOT needed just because you are using sector modules.

Share this post


Link to post
Share on other sites
The control module is for dropping in your map if you want all this handled for you , it is a drag and drop option for quickly setting up a sector control game and is NOT needed just because you are using sector modules.

Thanks again, good hunting!

I just tested it quickly and deleted the module that was synced with the control sectors. It worked based on my timeout script, but unfortunately my sector progress bar and boxes (on the right side of the screen that show the side that controls it) have all dispeared.

I may have to create/ modify the sector module script and perhaps omit the line line that loads "missionFlow.fsm"?

Share this post


Link to post
Share on other sites
I just tested it quickly and deleted the module that was synced with the control sectors. It worked based on my timeout script, but unfortunately my sector progress bar and boxes (on the right side of the screen that show the side that controls it) have all dispeared.

Thats weird BEAKSBY. You did place a side logic on each sector for who can control it?

If you have a sectorControl and you attach side logics to it these will count for all the sectors that are linked to the control.

By removing the control you have to add side logics to every sector so they know who can capture them.

If they dont have side logics then as you describe the UI elements will not show.

Share this post


Link to post
Share on other sites
You did place a side logic on each sector for who can control it?

No I didn't...Thanks! That did the trick.

Thanks for seeing this one all the way through...much appreciated!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×