Jump to content
Mike El

Scheduled base destruction

Recommended Posts

I'm currently working on adding scheduled base destruction to my server using this mod https://steamcommunity.com/sharedfiles/filedetails/?id=1601078531 

It works great but I would like to modify it so that it works only on specific days of the week. Could someone point me in the right direction

This is the current script from the mod

modded class Construction
{
    override bool CanDestroyPart( string part_name )
    {
        if ( IsPartConstructed( part_name ) && !HasDependentPart( part_name ) )
        {
            static int tbdhour;
            static int tbdminute;
            static int tbdsecond;
            GetHourMinuteSecondUTC(tbdhour, tbdminute, tbdsecond);

            if ((tbdhour >= 18) && (tbdhour <= 23))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        
        return false;
    }    
}

 

Edited by Mike El

Share this post


Link to post
Share on other sites

hi, nice idea

u could determine the day of the week with the Zeller's Congruence in C.

alternativly u can make an multi array with the specific dates and check the array elements in a loop if its equal to the current date

u can get current date by using this command instead:

static int sysTimeYear;
static int sysTimeMonth;
static int sysTimeDay;
GetYearMonthDayUTC(sysTimeYear, sysTimeMonth, systimeDay);

u can try it like this if the engine let u use two-dimensional arrays..

modded class Construction {
	override bool CanDestroyPart( string part_name ) {
		if ( IsPartConstructed( part_name ) && !HasDependentPart( part_name ) )	{
				static int sysTimeYear;
				static int sysTimeMonth;
				static int sysTimeDay;
				GetYearMonthDayUTC(sysTimeYear, sysTimeMonth, sysTimeDay);

				TIntArray baseDestrDatLst[5][2] = {1,28,1,30,2,3,2,6,2,7};
				for (int i = 0; i < 5; i++ ) {
  					if (sysTimeMonth == baseDestrDatLst[i][0]) {
						if (sysTimeDay == baseDestrDatLst[i][1]) {
							return true;
							break;
						}
						else {
							return false;
						}
					}
				}
			}
		return false;
	}
}

 

EDIT: u can also use a normal array then loop execution is i=i+2 for the month and u can also use array brackets in rows for better view of the date list. have not much time at the moment to test this.. so feedback would be nice

Edited by Funkdoc

Share this post


Link to post
Share on other sites

so i found out that 2d arrays doesnt work... using the following should work.

modded class Construction {
	override bool CanDestroyPart( string part_name ) {
		if ( IsPartConstructed( part_name ) && !HasDependentPart( part_name ) )	{
				int sysTimeYear;
				int sysTimeMonth;
				int sysTimeDay;
      		  		TIntArray baseDestrDatLst = {2,5,2,6,2,7,2,10,2,11};	//{2,5,..,.. means 2 =February 5=day
				int ListCount = baseDestrDatLst.Count();
          
				GetYearMonthDayUTC(sysTimeYear, sysTimeMonth, sysTimeDay);
     	     			for (int i = 0; i <= ListCount - 2; i += 2) {
  					if (sysTimeMonth == baseDestrDatLst.Get(i)) {
						if (sysTimeDay == baseDestrDatLst.Get(i + 1)) {
							return true;
						}
						else {
							return false;
						}
					}
				}
			}
		return false;
	}
}

if someone still needs to determine the day of the week, i will look deeper in it. its mainly possible with some lines of calculation...

Edited by Funkdoc

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

×