Jump to content
Sign in to follow this  
jshock

Executing Script on a Server in a Looping Fashion, or other?

Recommended Posts

Hello all,

I have my Redressing Script (link on my signature), and I have had a lot of requests for it to have functionality with systems such as EOS, Zeus, MCC, etc. in terms of units being spawned outside of those that are placed via the vanilla editor.

Here is a direct link as well: Redressing Script

To give you a basic overview of how the script functions (without looking at it), the mission creator defines the faction he/she would like to redress, that is passed to a function that counts all those units for that faction, within that function are also some arrays for units/groups that the mission creator would like to exclude from the "redressing" process. After that the array of units, minus the exclusions, is passed into the redressing process.

So, my question is, should I somehow put this process in a loop that executes in timed intervals on the server to redress the newly spawned units (via MCC, Zeus, etc.) or some other process? Eventhandlers?

I just haven't had time (newly in college) to sit and think on the issue enough to come up with a solution, and I know there are plenty of much better scripters than myself out there in the A3 community that have probably done this before :p.

All help is greatly appreciated!

Share this post


Link to post
Share on other sites

I can offer you some advice when it comes to college, you don't have to code for hours to come up with a brilliant solution.

http://cs.stanford.edu/people/eroberts/cs201/projects/crunchmode/econ-hours-productivity.html

The second a loop on the server you can use

if (isDedicated) or (isServer) then

{

while {some condition of truth} do {

};

};

if all you want it to do is run on the server then

if (isDedicated) then {

while {condition} do {

};

};

Else if this is going to be executed multiple times pre-compile it.

Edited by Polymath820

Share this post


Link to post
Share on other sites

Yeah I'm not overworking myself necessarily, :p, it's the mix of work and all the other "activities".

But anyhow, back to the point, I understand the server check and while do commands, however, I guess the second thing behind running the loop is making sure that it doesn't "blow-up" the server, which I know you can put a sleep command in, but I just don't know how long the sleep should be due to the fact that the units could come in at any number of different intervals, and what the sleep should be in the balance of server stress and script efficiency/effectivness.

Share this post


Link to post
Share on other sites

Why not loop through each of the units and count how many units there are and at the end of the count then put the script into sleep mode for x amount of time.

{

_counter = 0;

if ((count allUnits) < _counter) then { /* After this falls false it goes to the else condition so that the _counter == (count allUnits) goes to the else clause and sleeps the entire code for n seconds */

_counter = _counter + 1

} else {

sleep n; seconds

}

forEach allUnits;

Edited by Polymath820

Share this post


Link to post
Share on other sites

That's what I'm trying to get at, in a way, but I would really like to have the process between unit spawned and then unit redressed as quick as possible without bogging down the server, so any amount of x sleep time could lengthen that process. This is more for immersion sake than personal opinion, because seeing units "changing" right in front of you takes away from the mission. And if there is one thing I have learned from the realism units that I've been in immersion is everything.

Share this post


Link to post
Share on other sites

Pre-compile the code if you want that.

https://community.bistudio.com/wiki/Code_Optimisation

"Written it twice? Put it in a function

Pre-compilation by the game engine can save up 20x the amount of time processing, even if the initial time is slightly lengthened. If you've written it twice, or if there is a kind of loop consistently being compiled (perhaps a script run by execVM), make it into a function (FUNCVAR =compile preprocessfilelinenumbers "filename.sqf") "

Share this post


Link to post
Share on other sites

Could you not just pause the loop until there are units to redress so your not relying on the sleep. Something along the lines of..

while {true} do {

_unitsToRedress = allUnits;
NumberOfUnits = count _unitsToRedress;
{
	if (isNil {_x getVaraible "redressed"}) then {
		//redress unit
		_x setVariable ["redressed",true];
	};
}forEach _unitsToRedress;

waitUntil {count allUnits != NumberOfUnits};
};

You may need to add allDead in the count aswell , otherwise its going to forEach through all the units agian just because someone died, and there will not be someone needing a redress.

Edited by Larrow

Share this post


Link to post
Share on other sites

You can do that and again pre-compile because Larrow above is showing a "constantly running loop" pre-compiling it as stated will save 20x the computation time.

Share this post


Link to post
Share on other sites

Ok, so below is the function I already had, that pre-compiles, for the counting of the units, I have just added the variable array _previouslyDressed in to make sure that it only redresses the new units coming into the function:

_sideUnits = (_this select 0);

_countedSideUnits = [];
_previouslyDressed = [];
_excludedindv = [indv1, indv2];
//       	     ^Individual unit's variable names go here.
_grpLeads = [grp1];
//	      ^The group leader(s) variable names go here

{ 
   _currentUnit = _x; 
   if (side _currentUnit == _sideUnits && ({_currentUnit in (units group _x)}count _grpLeads == 0) ) then { 
       _countedSideUnits set [count _countedSideUnits, _currentUnit]; 
   }; 
}forEach allunits; 

_previouslyDressed = _previouslyDressed + _countedSideunits;


_countedSideUnits - _excludedindv - _previouslyDressed

So all I would need to do is something like this to implement your suggestion Larrow:

while (true) do {

_sideUnits = (_this select 0);

_countedSideUnits = [];
_previouslyDressed = [];
_excludedindv = [indv1, indv2];
//       	     ^Individual unit's variable names go here.
_grpLeads = [grp1];
//	      ^The group leader(s) variable names go here

{ 
   _currentUnit = _x; 
   if (side _currentUnit == _sideUnits && ({_currentUnit in (units group _x)}count _grpLeads == 0) ) then { 
       _countedSideUnits set [count _countedSideUnits, _currentUnit]; 
   }; 
}forEach allunits; 

_previouslyDressed = _previouslyDressed + _countedSideunits;


_countedSideUnits - _excludedindv - _previouslyDressed

waitUntil {_countedSideUnits != _previouslyDressed};

};

The function's return value then goes into another script with the redressing process.

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  

×