So hi. I'm making a gamemode, and trying to use applejack's SpawnPoints plugin. (It works, but it just don't save the spawnpoints, I can place them, they all work for all jobs I set the points for, then I restart server and it don't make the .txt docuement with the spawnpoints, so I have to re-place them. No LUA Errors either, and yes. I have GLON.)
[lua]
PLUGIN.Name = "Spawnpoints"
PLUGIN.Spawnpoints = {};
function PLUGIN:LoadData()
local path, data, status, results;
path = GM.LuaFolder.."/spawnpoints/"..game.GetMap()..".txt";
if (not file.Exists(path, "DATA")) then
return
end
data = file.Read(path, "DATA");
status, results = pcall(glon.decode,data);
if (status == false) then
error("Error GLON decoding '"..path.."': "..results);
elseif (not results) then
return
end
for name, spawns in pairs(results) do
data = cider.team.get(name);
if (data) then
self.Spawnpoints[data.index] = spawns;
end
end
end
function PLUGIN:SaveData()
local data,tocode,status,result,path;
tocode = {};
for index, spawns in pairs(self.Spawnpoints) do
data = cider.team.get(index);
if (data) then
tocode[data.name] = spawns;
end
end
status, result = pcall(glon.encode,tocode);
if (status == false) then
error("["..os.date().."] Spawnpoints Plugin: Error GLON encoding spawnpoints : "..results);
end
path = GM.LuaFolder.."/spawnpoints/"..game.GetMap()..".txt";
if (not result or result == "") then
if (file.Exists(path, "DATA")) then
print("deleted");
file.Delete(path);
end
return;
end
file.Write(path,result);
end
function PLUGIN:PostPlayerSpawn(ply, light)
local data,spawn;
data = self.Spawnpoints[ply:Team()];
if (data and table.Count(data) > 0) then
spawn = table.Random(data);
ply:SetPos(spawn.pos);
ply:SetEyeAngles(spawn.ang);
end
end
local plugin = PLUGIN;
local points = plugin.Spawnpoints;
-- A command to add a player spawn point.
cider.command.add("spawnpoint", "a", 2, function(ply,action,name)
local target,index,pos,count,left;
target = cider.team.get(name);
if (not target) then
return false, "Could not locate team '"..name.."'!";
end
action = action:lower();
index = target.index;
if (action == "add") then
points[index] = points[index] or {};
table.insert(points[index],{pos = ply:GetPos(), ang = ply:GetAngles()});
ply:Notify("You have added a spawnpoint for "..target.name.." where you are standing.");
elseif (action == "remove") then
if (not points[index]) then
return false, "'"..name.."' does not have any spawnpoints!";
end
pos = ply:GetEyeTraceNoCursor().HitPos;
count = 0;
for k,data in pairs(points[index]) do
if ((pos - data.pos):LengthSqr() <= 65536) then
points[index][k] = nil;
count = count + 1;
end
end
left = table.Count(points[index]);
if (count > 0) then
ply:Notify("You removed "..count.." "..target.name.." spawnpoints from where you were looking, leaving "..left.." left.");
else
ply:Notify("There are no "..target.name.." spawnpoints where you are looking!");
end
if (left == 0) then
points[index] = nil;
end
else
return false,"Invalid action specified! Syntax is /spawnpoint <add|remove> <team>!";
end
plugin:SaveData();
end, "Admin Commands", "<add|remove> <team>", "Add a spawnpoint where you are standing or remove spawnpoints where you look.",true);
[/lua] That's the LUA. Thanks in advanced.
error("Error GLON decoding '"..path.."': "..results);
you're missing a close "
edit: Guess not. I just said that because the code he's showing highlights a vast portion of his code as a string.
[QUOTE=CallMePyro;44687625]error("Error GLON decoding '"..path.."': "..results);
you're missing a close "[/QUOTE]
No, he is not. He even specifically said that he had no Lua errors, and lacking a closing quote would produce one.
[QUOTE=CallMePyro;44687625]error("Error GLON decoding '"..path.."': "..results);
you're missing a close "[/QUOTE]
Thank's for trying to help buddy, but A) I'm not missing it, B) It's read like that, but it's not. It's [b]"[/b]Error Glon Decoding [b]"[/b]..path..[b]": "[/b]..results);
Try adding a print into the SaveData function, print the path, and add a print at the end to see if it made it to the end
I can't see any obvious reason why it wouldn't save, but I see you have a check for the file to delete it before using file.Write. Just use file.Write alone as it deletes the file before writing. file.Append will add to the file with out deleting it if you need that.
Are you sure there isn't any weird file permissions? On Linux if the user doesn't have write access to sv.db you cannot save pdata, I assume the issue could happen if the user doesn't have access to the data folder.
after file.Write(path,result);
put:
[lua]print("debugstart")
print(path)
print(result)
print("debugend")
[/lua]
and let use see what it says.
Sorry, you need to Log In to post a reply to this thread.