#2
8th Nov 2019 at 9:54 PM
Posts: 156
Thanks: 24365 in 36 Posts
19 Achievements
Hey! That's a lot of different things. I don't have the time to go into details, but I can tell you the basics.
Running something after a set amount of time and repeating it can be achieved with an Alarm. There are other ways, but this is the safest simulation-wise approach. Look for the usage of the "alarms.add_alarm" function in the game code, it should include everything you need. Set the TimeSpan to 90000 ticks (1500 * 60, one in-game minute is 1500ms) and set it to repeat. You need to remember that the handle instance that gets returned after creating an alarm using this function has to be stored somewhere or the garbage collector will automatically stop it and remove it.
Detecting zone teardown (exiting) and game saving require injecting. You can find a tutorial about it on this forum made by Scumbumbo. You need to inject into the "on_teardown" method in the "Zone" class for detecting the zone teardown, it's required to run your code before the original code. For saving you need to inject into the "save_zone" method in the Zone class, same thing. I would recommend learning about catching exceptions and making sure to return the result of the original methods, as well as passing all of the arguments and keyword arguments safely, as breaking these functions breaks the game as well.
Good Luck!