Jump to content
Atlas1205

patrol team spawning script causing serious script lag

Recommended Posts

when using this script, it gets so laggy, cinematic camera rotation lags like playing a power point and tasks can't even be triggered to end as intended. what could be causing the problem? framerate is fine tho. please help!

in init.sqf:

allraidpat = [raiderpatrol_1,raiderpatrol_2,raiderpatrol_3,raiderpatrol_4,raiderpatrol_5,raiderpatrol_6,raiderpatrol_7,raiderpatrol_8,raiderpatrol_9,raiderpatrol_10,raiderpatrol_11,raiderpatrol_13,raiderpatrol_14,raiderpatrol_15,raiderpatrol_16,raiderpatrol_17,raiderpatrol_18,raiderpatrol_19,raiderpatrol_20,raiderpatrol_21,raiderpatrol_22,raiderpatrol_23,raiderpatrol_24,raiderpatrol_25,raiderpatrol_26,raiderpatrol_27,raiderpatrol_28,raiderpatrol_29];
allraidveh = [raiderveh_1,raiderveh_2,raiderveh_3,raiderveh_4,raiderveh_5,raiderveh_6,raiderveh_7,raiderveh_8,raiderveh_9,raiderveh_10,raiderveh_11,raiderveh_12,raiderveh_13,raiderveh_14,raiderveh_15];
allcsatpat = [csatpatrol_0,csatpatrol_2,csatpatrol_3,csatpatrol_4,csatpatrol_5,csatpatrol_6,csatpatrol_7,csatpatrol_8,csatpatrol_9,csatpatrol_10,csatpatrol_11,csatpatrol_12,csatpatrol_13,csatpatrol_14,csatpatrol_15,csatpatrol_16,csatpatrol_17,csatpatrol_18,csatpatrol_19,csatpatrol_20];
allcsatveh = [csatveh_1,csatveh_2,csatveh_3,csatveh_4,csatveh_5,csatveh_6,csatveh_7,csatveh_8,csatveh_9,csatveh_10,csatveh_11,csatveh_12,csatveh_13];
Spawner_allLogics = allraidpat+allraidveh+allcsatveh+allcsatpat;


if(isServer)then
{
	Spawner_waitForDelete = [];
	Spawner_fnc_addToWaitForDeleteArray =
	{
		Spawner_waitForDelete pushBackUnique _this;
	};
	Spawner_fnc_removeFromWaitForDeleteArray =
	{
		Spawner_waitForDelete = Spawner_waitForDelete - [_this];
	};
	Spawner_fnc_spawnPatrol =
	{
		private _patrolteam = _this getVariable ["Atlas_spawner_spawnedGroup",grpNull];
		if ( isNull _patrolteam ) then
		{
			private _patrolpos = ASLToAGL (getPosASL _this);
			
			//royals
			if (MOD_hasRHSGREF) then
			{
			
			if (_this in allraidpat) then {
			_chance = floor random [0,5,10];
			if (_chance >5) then {_patrolteam = [_patrolpos, resistance , (configfile >> "CfgGroups" >> "Indep" >> "rhsgref_faction_chdkz_g" >> "rhsgref_group_chdkz_ins_gurgents_infantry" >> "rhsgref_group_chdkz_infantry_patrol")] call BIS_fnc_spawnGroup;}}
			else {
			_veh = objnull;
			_patrolteam = [_patrolpos, resistance , (configfile >> "CfgGroups" >> "Indep" >> "rhsgref_faction_chdkz_g" >> "rhsgref_group_chdkz_ins_gurgents_infantry" >> "rhsgref_group_chdkz_ins_gurgents_squad")] call BIS_fnc_spawnGroup;};
			}
			
			else {
			
			
			if (_this in allraidpat) then {
			_chance = floor random [0,5,10];
			if (_chance >5) then {_patrolteam = [_patrolpos, resistance , (configfile >> "CfgGroups" >> "Indep" >> "IND_C_F" >> "Infantry" >> "ParaShockTeam")] call BIS_fnc_spawnGroup;
			} 
			else
			{_veh = objnull;
			_patrolteam = [_patrolpos, resistance , (configfile >> "CfgGroups" >> "Indep" >> "IND_C_F" >> "Infantry" >> "ParaCombatGroup")] call BIS_fnc_spawnGroup;
			}
				};
				

			};
		
			if (_this in allraidveh && MOD_hasRHSGREF) then {
			_patrolteam = createGroup resistance;
			_veh = "rhsgref_ins_g_uaz_dshkm_chdkz" createvehicle _patrolpos;_crewd = _patrolteam createUnit ["rhsgref_ins_g_rifleman",_patrolpos,[],2,"NONE"]; _crewg = _patrolteam createUnit ['rhsgref_ins_g_rifleman_aksu',_patrolpos,[],2,"NONE"];_crewg moveInGunner _veh; _crewd moveInDriver _veh;{deleteVehicle _x}foreach ((units _patrolteam) - ([_crewd]+[_crewg]));
			};
			if (_this in allraidveh && !(MOD_hasRHSGREF)) then {
			_patrolteam = createGroup resistance;
			_veh = "I_G_Offroad_01_armed_F" createvehicle _patrolpos;_crewd = _patrolteam createUnit ["I_C_Soldier_para_1_F",_patrolpos,[],2,"NONE"]; _crewg = _patrolteam createUnit ["I_C_Soldier_para_3_F",_patrolpos,[],2,"NONE"]; _crewg moveInGunner _veh; _crewd moveInDriver _veh;{deleteVehicle _x}foreach ((units _patrolteam) - ([_crewd]+[_crewg]));
			//csat
			
			if (_this in allcsatpat) then {
			_chance = floor random [0,5,10];
			if (_chance >5) then {_veh = objnull;_patrolteam = [_patrolpos, east , (configfile >> "CfgGroups" >> "East" >> "OPF_T_F" >> "Infantry" >> "O_T_InfSquad")] call BIS_fnc_spawnGroup;}
			else {_veh = objnull;_patrolteam = [_patrolpos, east , (configfile >> "CfgGroups" >> "East" >> "OPF_T_F" >> "Infantry" >> "O_T_InfTeam")] call BIS_fnc_spawnGroup;}
			};
			
			
			if (_this in allcsatveh) then {		
			_patrolteam = createGroup east;
			_class = ["O_T_LSV_02_armed_F","O_T_MRAP_02_hmg_ghex_F"]call bis_fnc_selectrandom;
			_veh = _class createvehicle _patrolpos;_crewd = _patrolteam createUnit ["O_T_Soldier_GL_F",_patrolpos,[],2,"NONE"]; _crewg = _patrolteam createUnit ["O_T_Engineer_F",_patrolpos,[],2,"NONE"]; _crewg moveInGunner _veh; _crewd moveInDriver _veh;{deleteVehicle _x}foreach ((units _patrolteam) - ([_crewd]+[_crewg]));	
			};
			
			
			
			if (vehicle (leader(_patrolteam)) != (leader(_patrolteam))) then {
			[_patrolteam, _patrolpos, 600, 4, "MOVE", "SAFE", "YELLOW", "LIMITED", "FILE", "", [1,2,3]] call CBA_fnc_taskPatrol;
			
			}
			else {
			[_patrolteam, _patrolpos, 250, 4, "MOVE", "SAFE", "YELLOW", "LIMITED", "FILE", "", [3,6,9]] call CBA_fnc_taskPatrol;
			};
			_this setVariable ["Atlas_spawner_spawnedGroup",_patrolteam,true];
			_this call Spawner_fnc_addToWaitForDeleteArray;
		};
	};
	0 spawn
	{
		while {true} do
		{
			allPlayersUIDs = [];
			{
				allPlayersUIDs pushBackUnique (getPlayerUID _x);
			} forEach allPlayers;
			sleep 60;
			{
				private _patrolteam = _x getVariable ["Atlas_spawner_spawnedGroup",grpNull];
				if ( isNull _patrolteam ) then
				{
					_x setVariable ["Atlas_spawner_nearPlayersUID",nil,true];
					_x call Spawner_fnc_removeFromWaitForDeleteArray;
				}
				else
				{
					private _nearPlayers = _x getVariable ["Atlas_spawner_nearPlayersUID",[]];
					if( ({_x in allPlayersUIDs} count _nearPlayers) == 0 )then
					{
						{
							deleteVehicle _x;
						} forEach units _patrolteam;
						deleteGroup _patrolteam;
						_x setVariable ["Atlas_spawner_spawnedGroup",grpNull,true];
						_x call Spawner_fnc_removeFromWaitForDeleteArray;
					};
				};
			} forEach Spawner_waitForDelete;
		};
	};
};

if(hasInterface)then
{
	ATLAS_SPAWN_DISTANCE_ONFOOT = 1000;
	ATLAS_SPAWN_DISTANCE_ONFOOT_SQR = ATLAS_SPAWN_DISTANCE_ONFOOT * ATLAS_SPAWN_DISTANCE_ONFOOT;
	ATLAS_DESPAWN_DISTANCE_ONFOOT = 2000;
	ATLAS_DESPAWN_DISTANCE_ONFOOT_SQR = ATLAS_DESPAWN_DISTANCE_ONFOOT * ATLAS_DESPAWN_DISTANCE_ONFOOT;
	ATLAS_SPAWN_DISTANCE_ONVEHICLE = 1500;
	ATLAS_SPAWN_DISTANCE_ONVEHICLE_SQR = ATLAS_SPAWN_DISTANCE_ONVEHICLE * ATLAS_SPAWN_DISTANCE_ONVEHICLE;
	ATLAS_DESPAWN_DISTANCE_ONVEHICLE = 2000;
	ATLAS_DESPAWN_DISTANCE_ONVEHICLE_SQR = ATLAS_DESPAWN_DISTANCE_ONVEHICLE * ATLAS_DESPAWN_DISTANCE_ONVEHICLE;
	ATLAS_SPAWN_DISTANCE_ONAIR = 0;
	ATLAS_SPAWN_DISTANCE_ONAIR_SQR = ATLAS_SPAWN_DISTANCE_ONAIR * ATLAS_SPAWN_DISTANCE_ONAIR;
	ATLAS_DESPAWN_DISTANCE_ONAIR = 500;
	ATLAS_DESPAWN_DISTANCE_ONAIR_SQR = ATLAS_DESPAWN_DISTANCE_ONAIR * ATLAS_DESPAWN_DISTANCE_ONAIR;

	Spawner_Logics_activated_by_me = [];

	0 spawn
	{
		while {true} do
		{
			sleep 30;
			private _veh = vehicle player;
			private _pos = ASLToAGL (getposASL _veh);
			private _distSpawnSqr = ATLAS_SPAWN_DISTANCE_ONFOOT_SQR;
			private _dstrDespawnSqr = ATLAS_DESPAWN_DISTANCE_ONFOOT_SQR;
			if(_veh != player)then
			{
				switch true do
				{
					case ( _veh isKindOf "LandVehicle" ): 
					{
						_distSpawnSqr = ATLAS_SPAWN_DISTANCE_ONVEHICLE_SQR ;
						_dstrDespawnSqr = ATLAS_DESPAWN_DISTANCE_ONVEHICLE_SQR;
					};
					case ( _veh isKindOf "Ship" ): 
					{
						_distSpawnSqr = ATLAS_SPAWN_DISTANCE_ONVEHICLE_SQR ;
						_dstrDespawnSqr = ATLAS_DESPAWN_DISTANCE_ONVEHICLE_SQR;
					};
					case ( _veh isKindOf "Air" ): 
					{
						_distSpawnSqr = ATLAS_SPAWN_DISTANCE_ONAIR_SQR ;
						_dstrDespawnSqr = ATLAS_DESPAWN_DISTANCE_ONAIR_SQR;
					};
				};
			};
			
			_dstrDespawnSqr = (_distSpawnSqr + 500) max _dstrDespawnSqr;

			private _Spawner_Logics_activated_by_me = Spawner_Logics_activated_by_me;
			{
				private _patrolteam = _x getVariable ["Atlas_spawner_spawnedGroup",grpNull];
				if ( (!isNull _patrolteam ) && { (leader _patrolteam) distanceSqr _pos > _dstrDespawnSqr }) then
				{
					private _nearPlayers = _x getVariable ["Atlas_spawner_nearPlayersUID",[]];
					private _nearPlayersNew = _nearPlayers - [getPlayerUID player];

					if( (count _nearPlayersNew) != (count _nearPlayers) )then
					{
						_x setVariable ["Atlas_spawner_nearPlayersUID",_nearPlayersNew,true];
						Spawner_Logics_activated_by_me = Spawner_Logics_activated_by_me - [_x];
					};
				};
			} forEach _Spawner_Logics_activated_by_me;
			{
				private _patrolteam = _x getVariable ["Atlas_spawner_spawnedGroup",grpNull];
				private _patrolpos = ASLToAGL (getPosASL _x);
				if ( _patrolpos vectorDistanceSqr _pos < _distSpawnSqr ) then
				{

					private _nearPlayers = _x getVariable ["Atlas_spawner_nearPlayersUID",[]];
					private _nearPlayersNew = _nearPlayers;
					private _result = _nearPlayersNew pushBackUnique (getPlayerUID player);
					if(_result > -1)then
					{
						_x setVariable ["Atlas_spawner_nearPlayersUID",_nearPlayersNew,true];
					};
					Spawner_Logics_activated_by_me pushBackUnique _x;

					if ( isNull _patrolteam ) then
					{
						_x remoteExecCall ["Spawner_fnc_spawnPatrol",2,false];
					};
				};
			} forEach Spawner_allLogics;
		};
	};
};

 

Share this post


Link to post
Share on other sites

I also have a script that randomizes units' weapons, could it be causing the problem?

//init.sqf


for "_i" from 0 to (count (configFile >> "CfgWeapons") - 1)  do
{
	_entry = (configFile >> "CfgWeapons") select _i;
	if (isClass _entry) then
	{
		_entry = configName _entry;
		_cursor = getText (configfile >> "CfgWeapons" >> _entry >> "cursor");
		_model = getText (configfile >> "CfgWeapons" >> _entry >> "model");
		_scope = getNumber (configfile >> "CfgWeapons" >> _entry >> "scope");

		if( (_scope > 0) && { ! ( (toLower _model) in ["","\a3\weapons_f\empty","a3\weapons_f\empty","\a3\weapons_f\empty.p3d","a3\weapons_f\empty.p3d"]) } ) then
		{
			switch _cursor do
			{
				case "arifle":
				{
					if(count getArray (configFile>> "CfgWeapons" >> _entry >> "muzzles") > 1)then
					{
						a_GLRIFLES = a_GLRIFLES + [format ["%1", _entry]];
					}
					else
					{
						a_RIFLES = a_RIFLES + [format ["%1", _entry]];
					};
				};
				case "srifle":
				{
					a_SNIPERFIFLES = a_SNIPERFIFLES + [format ["%1", _entry]];
				};
				case "mg":
				{
					a_MGS = a_MGS + [format ["%1", _entry]];
				};
				case "smg":
				{
					a_SMGS = a_SMGS + [format ["%1", _entry]];
				};
				case "hgun":
				{
					a_HGUNS = a_HGUNS + [format ["%1", _entry]];
				};
				case "rocket":
				{
					a_ROCKETLAUNCHERS = a_ROCKETLAUNCHERS + [format ["%1", _entry]];
				};
				case "missile":
				{
					a_MISSLELAUNCHERS = a_MISSLELAUNCHERS + [format ["%1", _entry]];
				};
			};
		};
	};
};

a_SECONDARY = a_ROCKETLAUNCHERS + a_MISSLELAUNCHERS;
a_PRIMARY = a_RIFLES + a_GLRIFLES + a_SNIPERFIFLES + a_MGS + a_SMGS;

I cannot just define it in description.ext otherwise the game gets stuck on infinite loading screen, so i had to use it in a trigger's onACT field:

//copy from mission.sqf, from the trigger's onACT

onActivation="[""CAManBase"",""Initpost"",{if (!(isplayer (_this select 0))&& ((side (_this select 0)) != civilian) && !((_this select 0) in units group civilianjob)) then {(_this select 0) remoteExecCall ['atlas_fnc_randomguns', 0, false];(_this select 0)selectWeapon (primaryWeapon (_this select 0))};},true,[],true] call CBA_fnc_addclasseventhandler;";


//that called function executes this script on target:
//guns.sqf

if !(local _this) exitWith{};
_gun = primaryWeapon _this;
_selected = _gun == currentWeapon _this;
_cursor = getText (configfile >> "CfgWeapons" >> _gun >> "cursor");
_muzzles = getArray (configFile>> "CfgWeapons" >> _gun >> "muzzles");
{
	if(toLower _x != "this")then
	{
		_muzzles pushBack _x;
		_mags = getArray (configFile>> "CfgWeapons" >> _gun >> _x >> "magazines");
		{_this removeMagazines _x} count _mags;
	};
} forEach _muzzles;
_mags = getArray (configFile>> "CfgWeapons" >> _gun >> "magazines");
{_this removeMagazines _x} count _mags;
_this removeWeapon _gun;
switch _cursor do
{
	case "arifle":
	{
		if(count _muzzles > 1)then
		{
			_gun = ( a_GLRIFLES call BIS_fnc_selectRandom );
			_muzzles =[];
			{
				if(toLower _x != "this")then
				{
					_muzzles pushBack _x;
				};
			} forEach getArray (configFile>> "CfgWeapons" >> _gun >> "muzzles");
			{
				_mags = getArray (configFile>> "CfgWeapons" >> _gun >> _x >> "magazines");
				_mag = _x;
				_count = 0;
				{
					_count = 4 - _forEachIndex;
					if(_count > 0)then
					{
						_this addMagazines [_mag, _count];
					};
				} forEach _mags;
			} forEach _muzzles;
		}
		else
		{
			_gun = ( a_RIFLES call BIS_fnc_selectRandom );
		};
	};
	case "srifle":
	{
		_gun = ( a_SNIPERFIFLES call BIS_fnc_selectRandom );
	};
	case "mg":
	{
		_gun = ( a_MGS call BIS_fnc_selectRandom );
	};
	case "smg":
	{
		_gun = ( a_SMGS call BIS_fnc_selectRandom );
	};
	default
	{
		_gun = ( a_PRIMARY call BIS_fnc_selectRandom );
	};
};
_this addMagazines [getArray (configFile>> "CfgWeapons" >> _gun >> "magazines") select 0, 9];
_this addWeapon _gun;
if(_selected)then
{
	_this selectWeapon _gun;
};


 

Share this post


Link to post
Share on other sites

that is a lot of stuff.

can you desribe a bit more what these scripts should do and how they do it. Did you write em on your own or where did u get em from?

 

Those infinite loading screen indicates a problem. I would seek there first.

Share this post


Link to post
Share on other sites

I would try preProcessing this file anyways if it's being ran more than once..

 

Share this post


Link to post
Share on other sites

yeah preprocessing and compiling or better use function library.

 

what I do if I have a big script and want to fight a bug is that I comment out parts of the script and run that stripped version. With that method you can identify in which part of the script your bug happens.

Share this post


Link to post
Share on other sites
3 minutes ago, sarogahtyp said:

yeah preprocessing and compiling or better use function library.

 

what I do if I have a big script and want to fight a bug is that I comment out parts of the script and run that stripped version. With that method you can identify in which part of the script your bug happens.

Yeah good point. Sometimes if it throws and error for me it won't even be on that line, and the error was a line or two above it.

so commenting out some different problematic lines could help break it down to the solution.

I guess in your case @shape1205 there could be something wrong, and preventing something loading even if arma doesn't throw an error in your face.

Share this post


Link to post
Share on other sites
3 hours ago, sarogahtyp said:

that is a lot of stuff.

can you desribe a bit more what these scripts should do and how they do it. Did you write em on your own or where did u get em from?

 

Those infinite loading screen indicates a problem. I would seek there first.

never mind. turns out the script lag is caused by weapon randomization. I will see about preprocessing.

Share this post


Link to post
Share on other sites
1 hour ago, shape1205 said:

never mind. turns out the script lag is caused by weapon randomization. I will see about preprocessing.

Well I wouldn't doubt one bit that it would.

Every single weapon config entry?

At start? At Random?

I wouldn't expect any less.

the preProcessing will help, I believe the server saves a cache of these kind of operations.

:dozingoff:

Share this post


Link to post
Share on other sites
1 minute ago, Midnighters said:

Well I wouldn't doubt one bit that it would.

Every single weapon config entry?

At start? At Random?

I wouldn't expect any less.

the preProcessing will help, I believe the server saves a cache of these kind of operations.

:dozingoff:

still didnt do too much good...

i think an alternative to this is to set up a few arrays, use isClass to check players' addons, and select the right one as weapon randomization array.

that way, it's a hell less of work for the server and/or clients.

Share this post


Link to post
Share on other sites
4 hours ago, shape1205 said:

still didnt do too much good...

i think an alternative to this is to set up a few arrays, use isClass to check players' addons, and select the right one as weapon randomization array.

that way, it's a hell less of work for the server and/or clients.

Well. One could say, it's still being calculated locally. But...

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

×