Hello. I’m new to modding and JavaScript(I have experience with other C-syntax languages).
I am not familiar with the API yet and I don’t really find what I’m looking for in the documentation.
How would I let a function be executed at the instant beginning of the game(the date 1/1/1, not that it executes every time I restart the game) and how would I let a function be executed monthly?
-tmch
Normally you would use the “gameplay.weekProceeded” event:
GDT.on(GDT.eventKeys.gameplay.weekProceeded, function(gamemanager) {
//handler code here
});
But since it doesn’t get fired just before 1/1/1 (the instant beginning) you will have to hack the “General.proceedOneWeek” function (executes every week and when you start a game) like this:
var originalProceedWeek = General.proceedOneWeek; //store the original function as a variable
var myProceedWeek = function(company, customweek) { //create a new function that will override the old one
//code that will be executed before original
originalProceedWeek(company, customweek); //call the original we stored
//code that will be executed after original
};
General.proceedOneWeek = myProceedWeek; //replace the original function
Now let’s tweak it to let it execute when you want it to…
var originalProceedWeek = General.proceedOneWeek; //store the original function as a variable
var myProceedWeek = function(company, customweek) //create a new function that will override the old one
{
originalProceedWeek(company, customweek); //call the original we stored
if (company.currentWeek < 1) { //check if the date is before 1/1/2
//do something at 1/1/1
}
else if (Math.floor(company.currentWeek) % 4 === 0) { //check if the current week is divisible by 4, the number of weeks a month
//do something every month
}
};
General.proceedOneWeek = myProceedWeek; //replace the original function
I hope this will help you
Edit: Here’s a Pastebin link for easier reading: http://pastebin.com/rBWKzcy7
Edit 2: If you don’t want to run the monthly code at the beginning of the game you’ll have to change the code a little: http://pastebin.com/sYzGNf0G