[SCRIPT] Auto Map Save

Small patches, updates, and extensions of preexisting code.
3 posts Page 1 of 1
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 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)
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 
Attachments
auto_savemap.py
(1.15 KiB) Downloaded 148 times
Last edited by Kuma on Mon Apr 14, 2014 4:23 pm, edited 2 times in total.
Lincent
Veterans
Veterans
Posts: 693
Joined: Wed Mar 27, 2013 9:47 pm


Kuma wrote:
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)
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 
Nice Job!
Scoper
Hoster
Hoster
Posts: 16
Joined: Sun Nov 17, 2013 4:36 pm


YAY purrfect for my buildserver
3 posts Page 1 of 1
Return to “Snippets”

Who is online

Users browsing this forum: No registered users and 1 guest