Cycle wait time and Set_Priority()

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
Harley
Forum Regular
Posts: 360
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Cycle wait time and Set_Priority()

Post by Harley »

Hi there!
I have an issue! I use for my shard ore vein regeneration system from Austin Heilman.
I don't understand some things. Wish you can help me.

In my settings.cfg

Code: Select all

Elem	Settings
{
	// Minutes the ore vein regeneration waits between cycles.
	RegenWait	10
}
In my regenOre.src

Code: Select all

/*
 * $Id: regenOre.src 563 2006-07-04 13:20:27Z austinheilman $
 *
 */
use uo;
use os;
use polsys;
use util;

include ":datafile:inc_public/datafile";
include ":mining:inc_public/settings";
include ":mining:inc_public/report";

program GlobalControl()
	MSP_ReportText("---=[ GLOBAL ORE REGENERATOR HAS STARTED UP ]=---", MSP_REPORT_SYSLOG);

	var settings := MSP_GetSettingsCfgElem("Settings");
	var cycle_wait := CInt(settings.RegenWait);
	if ( cycle_wait < 1 )
		cycle_wait := 3;
	endif

	cycle_wait *= 60;

	// 1 = 1 min 20 sec
	// 2 = 1 min 20 sec
	// 3 = 1 min 26 sec
	// 5 = 1 min 28 sec
	// 10 = 1 min 34 sec
	//cycle_wait := 3;

	SetGlobalProperty("#GlobalOreRegenPId", GetPid());

	Set_Priority(1);

	while( 1 )
		foreach realm_name in ( Realms().Keys() )
			RegenVeins(realm_name);
		endforeach
		syslog(" GlobalControl() | cycle_wait : " + cycle_wait + " | Time: " + StrFormatTime("%Y-%m-%d %H:%M:%S") ); // DEBUG
		Sleep( cycle_wait );
	endwhile
endprogram

function RegenVeins( realm_name )
	MSP_ReportText("Running global ore regeneration cycle for realm '"+realm_name+"'...", MSP_REPORT_SYSLOG);
	var data_file := DFOpenDataFile(realm_name+"-OreSpots", DF_CREATE);

	foreach elem_name in DFGetElemNames(data_file)
		var data_elem := DFFIndElement(data_file, elem_name);
		var amount := CInt(data_elem.GetProp("RemainingOre"));
		if( amount < 30 )
			//amount += 1;
			amount += 5;

			print(" regenOre.src | RegenVeins() | amount : " + amount ); // DEBUG
			data_elem.SetProp("RemainingOre", amount);
		else
			data_elem.SetProp("RemainingOre", 30 );
		endif

		Sleep(1);
	endforeach

	return 1;
endfunction
At my start.src

Code: Select all

	var script := Start_Script("oreGlobal/regenOre");
	if ( script.errortext )
		SysLog("Error starting global ore vein regen ->"+script.errortext);
	else
		//Print("Starting global ore regeneration controller... OK.");
		SysLog("Starting global ore regeneration controller... OK.");
	endif

	set_critical(0);
Like you can see in regenOre.src, I tested some else time:

// 1 = 1 min 20 sec
// 2 = 1 min 20 sec
// 3 = 1 min 26 sec
// 5 = 1 min 28 sec
// 10 = 1 min 34 sec

And I don't understand why it's so?!
I set up 1, 2, 3, 5 & 10 seconds, but sleep were more then 80 seconds!!!!

How can I fix it to make true values and seconds?

With best regards!
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Re: Cycle wait time and Set_Priority()

Post by DevGIB »

Firstly are you setting the cycle_wait on that exact same line where its commented out now?
If so you're setting it after the original calculation converts the minutes into seconds:

Code: Select all

cycle_wait *= 60;
The reason why it would be somewhat consistently the same is in RegenVeins you have a for each which also has a sleep of 1 second. If you have roughly 80 of veins thats going to be about 1 minute 20.

If you are testing with that line you are changing the time from waiting 1,2,3,4 minutes to actually 1,2,3,4 seconds which is why the time is going to increment by only second when you test.

Try the below:

Code: Select all

/*
 * $Id: regenOre.src 563 2006-07-04 13:20:27Z austinheilman $
 *
 */
use uo;
use os;
use polsys;
use util;

include ":datafile:inc_public/datafile";
include ":mining:inc_public/settings";
include ":mining:inc_public/report";

program GlobalControl()
	MSP_ReportText("---=[ GLOBAL ORE REGENERATOR HAS STARTED UP ]=---", MSP_REPORT_SYSLOG);

	var settings := MSP_GetSettingsCfgElem("Settings");
	var cycle_wait := CInt(settings.RegenWait);
	if ( cycle_wait < 1 )
		cycle_wait := 3;
	endif
	
	//MOVED ABOVE THE MINUTE->SECOND MULTIPLIER
	// 1 = 1 min 20 sec
	// 2 = 1 min 20 sec
	// 3 = 1 min 26 sec
	// 5 = 1 min 28 sec
	// 10 = 1 min 34 sec
	
	cycle_wait := 3; //SETTING MINUTES TO 3
	
	cycle_wait *= 60;


	SetGlobalProperty("#GlobalOreRegenPId", GetPid());

	Set_Priority(1);

	while( 1 )
		foreach realm_name in ( Realms().Keys() )
			RegenVeins(realm_name);
		endforeach
		syslog(" GlobalControl() | cycle_wait : " + cycle_wait + " | Time: " + StrFormatTime("%Y-%m-%d %H:%M:%S") ); // DEBUG
		Sleep( cycle_wait );
	endwhile
endprogram

function RegenVeins( realm_name )
	MSP_ReportText("Running global ore regeneration cycle for realm '"+realm_name+"'...", MSP_REPORT_SYSLOG);
	var data_file := DFOpenDataFile(realm_name+"-OreSpots", DF_CREATE);

	foreach elem_name in DFGetElemNames(data_file)
		var data_elem := DFFIndElement(data_file, elem_name);
		var amount := CInt(data_elem.GetProp("RemainingOre"));
		if( amount < 30 )
			//amount += 1;
			amount += 5;

			print(" regenOre.src | RegenVeins() | amount : " + amount ); // DEBUG
			data_elem.SetProp("RemainingOre", amount);
		else
			data_elem.SetProp("RemainingOre", 30 );
		endif

		Sleep(1);
	endforeach

	return 1;
endfunction
Harley
Forum Regular
Posts: 360
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Re: Cycle wait time and Set_Priority()

Post by Harley »

DevGIB wrote: Sun Aug 06, 2017 4:57 am The reason why it would be somewhat consistently the same is in RegenVeins you have a for each which also has a sleep of 1 second. If you have roughly 80 of veins thats going to be about 1 minute 20.
DevGIB, thanks! I completely lost sight of this moment!
You were right.
Best regards!!!
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Re: Cycle wait time and Set_Priority()

Post by DevGIB »

All good, i can't count the amount of times i've spent far too long looking at a script and can't work out why it doesn't work like it should in my head, only to leave it and come back a day or two later and have it suddenly click i've got something in the wrong position or have used the wrong variable name or something silly.

Glad to help :)
Post Reply