我正在尝试创建一个系统来备份和恢复游戏服务器的点,因此它可以安全地重新启动而不会丢失任何东西。我已经编写了一个脚本来执行此操作,并且实际的备份部分工作正常,但恢复部分没有。
这是在使用“Backup(read)”时运行的脚本(Backup(write) 按照设计的方式完美运行):
if (source and read) then
System.LogAlways("[System] Restoring serverdata from file 'backup.CHK'");
for line in source:lines() do
Backup = {};
Backup.Date = (Date or line:match("File Last Modified: (.-)"));
Backup.Time = (Time or line:match("time: (.-)"));
US = tonumber((US or line:match("us: (.-)")));
NK = tonumber((NK or line:match("nk: (.-)")));
local params = {class = "Player";
position = {x = 1, y = 1, z = -1000};
Respawn = { bRespawn = 0; nTimer =0; bUnique = 1; };
bUsable = 0;
orientation = {0, 90, 135};
name = "BackupEntity"; };
local ent = System.SpawnEntity(params);
g_gameRules.game:SetTeam(1, ent.id);
g_gameRules.game:SetSynchedEntityValue(playerId, 100, (NK/3));
g_gameRules.game:SetTeam(2, ent.id);
g_gameRules.game:SetSynchedEntityValue(playerId, 100, (US/3));
System.RemoveEntity(params);
end
source:close();
return;
end
我不确定我做错了什么,而且我看过的大多数网站都没有太大帮助。问题是它没有从文件中读取任何值。
任何帮助将不胜感激 :)。
编辑:
我们必须将分数除以 3 的原因是因为服务器将所有分数乘以 3。如果我们不将分数除以 3,那么每次还原时分数总是大 3 倍。backup.CHK 文件的示例内容:
The server is dependent on this file, and writes to it every hour. Please do not edit.
File Last Modified: 11/07/2013
This file was generated by the servers' autobackup system.
--------------------------
time: 22:51
us: 453445
nk: 454567