[QUES] Random event

I’m trying to create a random event, but whenever I test it, it constantly activates the event. Here’s the code:

var randomCrashLevel1 = {     id: "F413351E-2108-4967-A989-A7E98D4DEFA5",     isRandom: true,     maxTriggers: 2,     trigger: function (company) {         return company.currentLevel == 1 && company.isGameProgressBetween(0.2,0.9);     },     getNotification: function (company) {         company.adjustCash(-(750 + 500 * company.getRandom()), "restoring code");         return new Notification({             header: "Computer Crash".localize(),             text: "Uh oh! Your computer has crashed! You will have to pay to restore the code!".localize()         })     } } GDT.addEvent(randomCrashLevel1);

Whats wrong with it? Also would there be a way to reset the max triggers every time a game is created?

1 Like

I think you have to use:

isRandomEvent: true,

not:

isRandom: true,

:slight_smile:

Edit: To reset the trigger count every time a new game is created, you have to hack the “UI.closeGameDefinition” method (or another method that is called upon starting development of a new game). I haven’t tested this code, but it might work. Put it in the same function you put the random event code.

var oriCloseGameDef = UI.closeGameDefinition; //store original function to a variable
var myCloseGameDef = function()
{
    oriCloseGameDef(); //perform original code by calling the variable we set
    GameManager.company.eventTriggerCounts[“F413351E-2108-4967-A989-A7E98D4DEFA5”] = 0; //reset counter for the event by its ID
};
UI.closeGameDefinition = myCloseGameDef; //replace original function

4 Likes

I believe having to reset “maxTriggers” is a bug and hopefully will be patched soon :smile:
This behavior should only be apparent when you start a new game whilst already playing a game.

The API on “isRandomEvent” seemed to be incorrectly documented. This has been corrected though :smile:

3 Likes

@Darkly @SirEverard Thanks I’ll have to wait until thursday or Friday to test it out because I’m on vacation. Through the use of custom menus could I make it where you randomly have the choice to increase backup or data protection? And then instead of using the company level use a software protection level. Sorry typing uh is on an ipad so there’ll be spelling and gammar mistakes.

1 Like