Applejack Spawnpoints

Hello,

Im running an applejack server called TownRP and my spawn save, but only the first spawn i set. Can someone help me. The one who does this will be rewarded all my steam cards (25 cards) and 1 red orchestra key

Regards,
Misterbobbie

[editline]7th November 2015[/editline]

This is the code btw:

–[[
~ Spawnpoints Plugin ~
~ Applejack ~
–]]

PLUGIN.Name = “Spawnpoints”
PLUGIN.Spawnpoints = {};

–[[
why is cider spawnpoints cancer?
]]–

function PLUGIN:LoadData()
local path, data, status, results;
path = game.GetMap()…".txt"

if !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 = {};
path = game.GetMap()…".txt"
for index, spawns in pairs(self.Spawnpoints) do
data = cider.team.get(index);
if (data) then
tocode[data.name] = spawns; --Indexes change, names tend not to.
end
end
status, result = pcall(glon.encode,tocode);
if (status == false) then
error("["…os.date()…"] Spawnpoints Plugin: Error GLON encoding spawnpoints : "…results);
end
file.Append(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);

GLON is old, JSON should be used.

[lua]
–[[
~ Spawnpoints Plugin ~
~ Applejack ~
–]]

PLUGIN.Name = “Spawnpoints”
PLUGIN.Spawnpoints = {};
–[[
TODO: Make it not spawn people if there’s someone
in the way.
–]]

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(util.JSONToTable,data);
if (status == false) then
	error("Error JSON decoding '"..path.."': "..results);
elseif (not results) then
	return
end
for name, spawns in pairs(results) do
	data = team.Get(name);
	if (data) then
		self.Spawnpoints[data.TeamID] = spawns;
	end
end

end

function PLUGIN:SaveData()
local data,tocode,status,result,path;
tocode = {};
for index, spawns in pairs(self.Spawnpoints) do
data = team.Get(index);
if (data) then
tocode[data.Name] = spawns; --Indexes change, names tend not to.
end
end
status, result = pcall(util.TableToJSON,tocode);
if (status == false) then
error("["…os.date()…"] Spawnpoints Plugin: Error JSON encoding spawnpoints : “…results);
end
path = GM.LuaFolder…”/spawnpoints/"…game.GetMap()…".txt";
if (not result or result == “”) then
if (file.Exists(path, “DATA”)) then
file.Delete(path, “DATA”);
end
return;
end
file.CreateDir( “sample” );
file.CreateDir(GM.LuaFolder … “/spawnpoints/”);
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.
GM:RegisterCommand{
Command = “spawnpoint”;
Access = “a”;
Arguments = “<Add|Remove> <Team>”;
Types = “Phrase String”;
function(ply, action, name)
local target,index,pos,count,left;
target = team.Get(name);
if (not target) then
return false, “Could not locate team '”…name…"’!";
end
index = target.TeamID;
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.”);
else
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
end
plugin:SaveData();
end
};
[/lua]

Code taken from: https://github.com/Lexicality/applejack/blob/master/gamemode/plugins/spawnpoints/sv_init.lua

I get that,
but im using a modified version of his old applejack
And even if i paste that code in it says there is no command

EDIT:



--[[
	~ Spawnpoints Plugin ~
	~ Applejack ~
--]]

PLUGIN.Name = "Spawnpoints"
PLUGIN.Spawnpoints = {};


--[[
	why is cider spawnpoints cancer?
]]--


function PLUGIN:LoadData()
	local path, data, status, results;
        path = GM.LuaFolder.."/spawnpoints/"..game.GetMap()..".txt"

	if !file.Exists(path, "DATA") then
		return
	end
	data = file.Read(path, "DATA");
	status, results = pcall(util.JSONToTable,data);
	if (status == false) then
		error("Error JSON 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 = {};
	path = game.GetMap()..".txt" 
	for index, spawns in pairs(self.Spawnpoints) do
		data = cider.team.get(index);
		if (data) then
			tocode[data.name] = spawns; --Indexes change, names tend not to.
		end
	end
	status, result = pcall(util.TableToJSON,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
            file.Delete(path, "DATA");
        end
        return;
    end
    file.CreateDir( "sample" );
    file.CreateDir(GM.LuaFolder .. "/spawnpoints/");
    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);


Try this, it didn’t take long to convert.

Error:

[11/07/15 13:36:57] Applejack Spawnpoints Plugin: Hook LoadData failed: gamemodes/applejack/gamemode/plugins/spawnpoints/sv_init.lua:19: bad argument #1 to ‘Exist’ <string expected, got nil>

Try copying and pasting the code from my post again.

I just made a quick edit.

Still doesnt work,

Add me on steam.

[TN] Misterbobbie,
Ill give you acces to the teamviewer :slight_smile:

[editline]7th November 2015[/editline]

SOLVED