Jump to content
Sign in to follow this  
unidad2pete

My mission have LAG :(

Recommended Posts

I just finished a mission, and everything works fine.

The problem I have is that after some time everyone has LAG.

When there are 15 players on the server, the LAG appears after 1 hour or so. But when there are 60 people on the server LAG appears after 10 minutes.

What are the main causes of LAG in multiplayer missions?

This is my first big mission, I am newbie.

The mission has many variables, and loops (While {true} do {etc.}).

Also when someone dies, it leaves a briefcase on the floor, so you catch the players and everything is full of briefcases.

It has a ranking system, experience, money and a lot of things, but in theory everything works fine.

Please I need help, I've been working on this mission very long time and makes it unplayable LAG.

The LAG disappears when I restart the mission and depending on the players appears before or after.

Is not Graphic LAG, is connection LAG.

If anyone can take a look at my mission I would be extremely grateful. Or any kind of help.

Thank you all.

Share this post


Link to post
Share on other sites
I just finished a mission, and everything works fine.

The problem I have is that after some time everyone has LAG.

When there are 15 players on the server, the LAG appears after 1 hour or so. But when there are 60 people on the server LAG appears after 10 minutes.

What are the main causes of LAG in multiplayer missions?

This is my first big mission, I am newbie.

The mission has many variables, and loops (While {true} do {etc.}).

Also when someone dies, it leaves a briefcase on the floor, so you catch the players and everything is full of briefcases.

It has a ranking system, experience, money and a lot of things, but in theory everything works fine.

Please I need help, I've been working on this mission very long time and makes it unplayable LAG.

The LAG disappears when I restart the mission and depending on the players appears before or after.

Is not Graphic LAG, is connection LAG.

If anyone can take a look at my mission I would be extremely grateful. Or any kind of help.

Thank you all.

Welcome to ArmA mission making. You need a lot of scripting knowledge to make a lag-proof mission and i presume that is the reason we only have 3 or 4 main community game modes.(Domination, Insurgency, patrol ops)

Share this post


Link to post
Share on other sites

You did a pretty good job of listing why your mission has lag. :)

I'm sure all of those things work fine, but they are also why you're all so laggy. Maybe check out this page for some ideas of optimizing some of your code?

Share this post


Link to post
Share on other sites

This are two scripts examples.

This is called via init.sqf, is a loop of player, set fatigue 0 if variable fati is 1, measuring the distance with marker and more things.

if (player == player) then
{ 
While {true} do
  {

   if (fati == 1) then {
   player setFatigue 0;	  };      


        _posi = player distance getMarkerPos "colorzone";
        if (_posi > 300) then 
        {
         experiencia = experiencia + 1;
   };
   if (_posi <= 300) then 
   {
	   experiencia = experiencia + 11;
	   euros = euros + 30;
   };
//* Comprobando nivel y otorgando mejoras *//
   if ((nivel == 1) and (nivel == 1)) then {nextlevelexp = 840};
   if ((nivel == 2) and (nivel == 2)) then {nextlevelexp = 1200};
   if ((nivel == 3) and (nivel == 3)) then {nextlevelexp = 1560};
   if ((nivel >= 4) and (nivel <= 6)) then {nextlevelexp = 2160};
   if ((nivel >= 7) and (nivel <= 10)) then {nextlevelexp = 3100};
   if ((nivel >= 11) and (nivel <= 14)) then {nextlevelexp = 4700};
   if ((nivel >= 15) and (nivel <= 18)) then {nextlevelexp = 6000};
   if ((nivel >= 19) and (nivel <= 25)) then {nextlevelexp = 9000};
   if ((nivel >= 26) and (nivel <= 31)) then {nextlevelexp = 13000};
   if ((nivel >= 32) and (nivel <= 37)) then {nextlevelexp = 19000};
   if ((nivel >= 38) and (nivel <= 45)) then {nextlevelexp = 26000};
   if ((nivel >= 46) and (nivel <= 50)) then {nextlevelexp = 48000};
   if (nivel >= 50) then {nextlevelexp = 10000000};


        if ( experiencia >= nextlevelexp) then 
        {
         nivel = nivel + 1;
         experiencia = 0;
         playSound "trompetas"; 
         _text4 = format["Rank up!! n/You are rank %1 now!!", nivel];
         titleText [_text4,"PLAIN", 1]; titleFadeOut 15;
   };

{	clearItemCargoGlobal _x;
	clearBackpackCargoGlobal _x;
	clearMagazineCargoGlobal _x;
	clearWeaponCargoGlobal _x;} ForEach allMissionObjects "All";
  sleep 5;
  };
};

This is not my script, but I modified very much to adecuate to my mission. Check variable when people enter on car and depending variable, eject or not.

while {nivel < 50} do
{     
waitUntil {sleep 0.5; alive player};

	private "_v";

	while {((alive player) and (nivel >= 1) and (nivel < 3))} do
	{
		_firstlvl = nivel;
		waitUntil {sleep 0.5; vehicle player != player};
		_newlvl = nivel;
		if (_firstlvl != _newlvl) exitWith {};

		_v = vehicle player;
		_v1 = typeOf _v;
		if !(_v1 in Disponible_1) then
		{
			if ((driver _v == player) or (gunner _v == player) or (_v turretUnit [0] == player) or (_v turretUnit [1] == player) or (_v turretUnit [2] == player))then
			{
				player action ["eject", _v];
				waitUntil {sleep 0.5; vehicle player == player};
				player action ["engineOff", _v];
				titleText ["Insufficient rank to use that vehicle position","PLAIN", 1]; 
				titleFadeOut 5;
			};
		};
	};
	while {((alive player) and (nivel >= 3) and (nivel < 5))} do
	{
		_firstlvl = nivel;
		waitUntil {sleep 0.5; vehicle player != player};
		_newlvl = nivel;
		if (_firstlvl != _newlvl) exitWith {};

		_v = vehicle player;
		_v1 = typeOf _v;
		if !(_v1 in Disponible_3) then
		{
			if ((driver _v == player) or (gunner _v == player) or (_v turretUnit [0] == player) or (_v turretUnit [1] == player) or (_v turretUnit [2] == player)) then
			{
				player action ["eject", _v];
				waitUntil {sleep 0.5; vehicle player == player};
				player action ["engineOff", _v];
				titleText ["Insufficient rank to use that vehicle position","PLAIN", 1]; 
				titleFadeOut 5;
			};
		};


	};
	while {((alive player) and (nivel >= 5) and (nivel < 9))} do
	{
		_firstlvl = nivel;
		waitUntil {sleep 0.5; vehicle player != player};
		_newlvl = nivel;
		if (_firstlvl != _newlvl) exitWith {};

		_v = vehicle player;
		_v1 = typeOf _v;
		if !(_v1 in Disponible_3) then
		{
			if (driver _v == player) then
			{
				player action ["eject", _v];
				waitUntil {sleep 0.5; vehicle player == player};
				player action ["engineOff", _v];
				titleText ["Insufficient rank to use that vehicle position","PLAIN", 1]; 
				titleFadeOut 5;
			};
		};
	};
	while {((alive player) and (nivel >= 9) and (nivel < 11))} do
	{
		_firstlvl = nivel;
		waitUntil {sleep 0.5; vehicle player != player};
		_newlvl = nivel;
		if (_firstlvl != _newlvl) exitWith {};

		_v = vehicle player;
		_v1 = typeOf _v;
		if !(_v1 in Disponible_9) then
		{
			if (driver _v == player) then
			{
				player action ["eject", _v];
				waitUntil {sleep 0.5; vehicle player == player};
				player action ["engineOff", _v];
				titleText ["Insufficient rank to use that vehicle position","PLAIN", 1]; 
				titleFadeOut 5;
			};
		};
	};
	while {((alive player) and (nivel >= 11) and (nivel < 20))} do
	{
		_firstlvl = nivel;
		waitUntil {sleep 0.5; vehicle player != player};
		_newlvl = nivel;
		if (_firstlvl != _newlvl) exitWith {};

		_v = vehicle player;
		_v1 = typeOf _v;
		if !(_v1 in Disponible_11) then
		{
			if (driver _v == player) then
			{
				player action ["eject", _v];
				waitUntil {sleep 0.5; vehicle player == player};
				player action ["engineOff", _v];
				titleText ["Insufficient rank to use that vehicle position","PLAIN", 1]; 
				titleFadeOut 5;
			};
		};
	};
	while {((alive player) and (nivel >= 20) and (nivel < 26))} do
	{
		_firstlvl = nivel;
		waitUntil {sleep 0.5; vehicle player != player};
		_newlvl = nivel;
		if (_firstlvl != _newlvl) exitWith {};

		_v = vehicle player;
		_v1 = typeOf _v;
		if !(_v1 in Disponible_20) then
		{
			if (driver _v == player) then
			{
				player action ["eject", _v];
				waitUntil {sleep 0.5; vehicle player == player};
				player action ["engineOff", _v];
				titleText ["Insufficient rank to use that vehicle position","PLAIN", 1]; 
				titleFadeOut 5;
			};
		};
	};
	while {((alive player) and (nivel >= 26) and (nivel < 35))} do
	{
		_firstlvl = nivel;
		waitUntil {sleep 0.5; vehicle player != player};
		_newlvl = nivel;
		if (_firstlvl != _newlvl) exitWith {};

		_v = vehicle player;
		_v1 = typeOf _v;
		if !(_v1 in Disponible_26) then
		{
			if (driver _v == player) then
			{
				player action ["eject", _v];
				waitUntil {sleep 0.5; vehicle player == player};
				player action ["engineOff", _v];
				titleText ["Insufficient rank to use that vehicle position","PLAIN", 1]; 
				titleFadeOut 5;
			};
		};
	};
	while {((alive player) and (nivel >= 35) and (nivel < 45))} do
	{
		_firstlvl = nivel;
		waitUntil {sleep 0.5; vehicle player != player};
		_newlvl = nivel;
		if (_firstlvl != _newlvl) exitWith {};

		_v = vehicle player;
		_v1 = typeOf _v;
		if !(_v1 in Disponible_35) then
		{
			if (driver _v == player) then
			{
				player action ["eject", _v];
				waitUntil {sleep 0.5; vehicle player == player};
				player action ["engineOff", _v];
				titleText ["Insufficient rank to use that vehicle position","PLAIN", 1]; 
				titleFadeOut 5;
			};
		};
	};
	while {((alive player) and (nivel >= 45) and (nivel < 50))} do
	{
		_firstlvl = nivel;
		waitUntil {sleep 0.5; vehicle player != player};
		_newlvl = nivel;
		if (_firstlvl != _newlvl) exitWith {};

		_v = vehicle player;
		_v1 = typeOf _v;
		if !(_v1 in Disponible_45) then
		{
			if (driver _v == player) then
			{
				player action ["eject", _v];
				waitUntil {sleep 0.5; vehicle player == player};
				player action ["engineOff", _v];
				titleText ["Insufficient rank to use that vehicle position","PLAIN", 1]; 
				titleFadeOut 5;
			};
		};
	};

};

If I remove all the loops, solve the problem?

Share this post


Link to post
Share on other sites

It'll help, but won't solve all lag. But getting rid of entirely useless "only pilots can fly" style loops and waits will certainly help. Then again you'll probably need to worry about additional destroyed vehicles depending on the type of people playing, which can be just as bad. :)

Share this post


Link to post
Share on other sites

If I use triggers instead of measuring distances with the command "while" and distance "would help? Would cause LAG if I put many Triggers??

Also I use eventhandler MPkilled MP.

I do not understand is that when I look at other scripts Wasteland, etc ... seem much larger, with many whiles and other things and do not cause lag.

Share this post


Link to post
Share on other sites
If I use triggers instead of measuring distances with the command "while" and distance "would help? Would cause LAG if I put many Triggers??

Also I use eventhandler MPkilled MP.

I do not understand is that when I look at other scripts Wasteland, etc ... seem much larger, with many whiles and other things and do not cause lag.

I was told by somebody with a lot of arma scripting knowledge that the number of triggers won't effect performance until you have 10,000 or some ridiculous number, depends what's in them though i guess.

Share this post


Link to post
Share on other sites

After reading everything with my low level of English, I understand that I have to optimize the code a lot.

I have 2 easy questions

Is there any difference affecting LAG between CASE 3 A and CASE 3 B?

which is better in next cases?

CASE 1

A:

if (( _a == 0 ) and ( _b == 0 ) and ( _c == 0 )) then {something};

B:

if ( _a == 0 ) then 
{
if ( _b == 0 ) then 
{
	if ( _c == 0 ) then 
	{
		something;
	};
};
};

CASE 2

A:

While {true} do 
{
if ( player hasWeapon "Weaponclass" ) then { player removeWeapon "Weaponclass" };
sleep 10;
};

B:

Trigger ( anybody, repeatedly, game logic )

condition: player hasWeapon "Weaponclass";

onAct : player removeWeapon "Weaponclass";

CASE 3:

A:

if ( _a == 0 ) then 
{
if ( _b == 0 ) then 
{
	if ( _c == 0 ) then 
	{
		something;
	};
};
};

B:

if ( _a == 0 ) then {if ( _b == 0 ) then {if ( _c == 0 ) then {something;};};};

Share this post


Link to post
Share on other sites

I'd say that's extremely small performance increases.

If-statements are evaluated all the way no matter if the first statement is false, CASE1B is better than 1A. Still, it's related to the type of evaluation that is performed. Checking 3 boolean variables that way won't give any increase in performance.

CASE3 B just makes the thing impossible to read. Not having newline breaks etc will barely give you any performance increase, since scripts are compiled (spaces, linebreak etc are removed for the engine afaik).

CASE2: triggers are checked if the condition is met every 0.5 seconds. so A is actually better.

while {true} loops should always sleep unless they're extremely important and needs to be executed instantly. They run several frames per second and a lot of them can certainly affect performance. An alternative if you can't have sleep is waitUntil {// code; false}.

As an example, try this

while {true}do {player sideChat (str time)};

and

waitUntil {player sideChat (str time); false}

This "lag" that you're talking about, is it server lag, client FPS drop, desync?

Make sure that only clients run client scripts and server only runs server scripts (unless local host).

See here: http://www.kylania.com/ex/?p=26

Share this post


Link to post
Share on other sites

If-statements are evaluated all the way no matter if the first statement is false

That is not what the link posted by kylania says (depending on how you do it):

http://community.bistudio.com/wiki/Code_Optimisation#Conditions

if (group knowsAbout vehicle object > 0) then { if ( (alive object) && (canMove object) && (count (magazines object) > 0) ) then { ... }; };

Now the engine will only continue reading the condition after the group has some knowledge about the object.

Share this post


Link to post
Share on other sites

That's 2 if-statements.

This:

if (( _a == 0 ) and ( _b == 0 ) and ( _c == 0 )) then {something};

is fully evaluated, even if _a is false.

Share this post


Link to post
Share on other sites

Thanks to you I managed to remove my mission LAG. Everything works correctly. Especially thanks to kylania .;);):D:D:D:D:D:D:D

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  

×