[SCRIPT] Auto Map Save
Posted: Sun Apr 13, 2014 7:10 am
I don't know if a script like this existed, so I made this after seeing this request (link) So this script automatically saves the map after every certain minutes (30 by default). To change it open the .py file with notepad and change "save_time_min = 30" to something else like "save_time_min = 60" (every hour). Just dump the file in the scripts folder and add its name in config. It saves the map in the maps folder with the time it was saved in.
(some of the code is taken from savemap.py by mat^2)
(some of the code is taken from savemap.py by mat^2)
Code: Select all
#Auto Save Map By Kuma
#Automatically saves the current map in the maps folder
#Some functions are copied and edited from mat^2's savemap.py
#Version 1
from time import strftime, localtime
from twisted.internet.task import LoopingCall
from twisted.internet.reactor import callLater
save_time_min = 30 #Saves the map every X minutes. (Set to 30 by default)
save_time_sec = save_time_min * 60.0 #Don't touch this.
def get_name(map):
return './maps/{}.{}.vxl'.format(map.rot_info.name, strftime('%d %b %Y %H-%M-%S', localtime()))
def apply_script(protocol, connection, config):
class AutoMapSaveProtocol(protocol):
def __init__(self, *arg, **kwargs):
protocol.__init__(self, *arg, **kwargs)
self.save_loop = LoopingCall(self.save_map)
callLater(save_time_sec, self.start_save_loop) #To prevent the loop from saving the map at the start.
def start_save_loop(self, time = save_time_sec):
self.save_loop.start(time)
def save_map(self):
open(get_name(self.map_info), 'wb').write(self.map.generate())
return AutoMapSaveProtocol, connection