Need help with FindInSphere



for k, v in pairs(ents.FindInSphere(Vector(-8951, 13034, 283), 1500)) do
		if v and v:IsValid() then
			if v:IsPlayer() then
				if v:Alive() then
					v:Kill();
				end
			else
				v:Remove();
			end
		end


It has to kill the person in that location, but it doesn’t… Anyone that can help me?

There’s no end after the loop. Are you posting the full code? Any errors?

This is the full code and it’s in lua/autorun/file.lua. It doesn’t give errors

So there is no function or anything calling the code, just that code in the lua file?

^Exactly, if you’re not hooking it into a entity, or a think hook, NOTHING will happen, it will only run the code once, then stop. Which would mean that the code will be run when the server starts or when opening with lua_openscript.

You need to include it with a SEnt

I have problems with ending the code, this is the code I have now:



--[[
Name: "sv_init.lua".
Product: "CityRP (Roleplay)".
--]]

local PLUGIN = {};

-- Create a variable to store the plugin for the shared file.
PLUGIN_SHARED = PLUGIN;

-- Include the shared file and add it to the client download list.
include("sh_init.lua");
AddCSLuaFile("sh_init.lua");

function PLUGIN.CaveBlock()
	for k, v in pairs(ents.FindInSphere(Vector(-8951, 13034, 283), 1500)) do
		if v and v:IsValid() then
			if v:IsPlayer() then
				if v:Alive() then
					v:Kill();
				end
			else
				v:Remove();
			end
		end
	end

-- Register the plugin.
cityrp.plugin.register(PLUGIN)


It’s now in gamemodes/CityRP/gamemode/core/plugins/

Error: file:34 ‘end’ expected (to close ‘function’ at line 15 near ‘<eof>’

[lua]–[[
Name: “sv_init.lua”.
Product: “CityRP (Roleplay)”.
–]]

local PLUGIN = {};

– Create a variable to store the plugin for the shared file.
PLUGIN_SHARED = PLUGIN;

– Include the shared file and add it to the client download list.
include(“sh_init.lua”);
AddCSLuaFile(“sh_init.lua”);

function PLUGIN.CaveBlock()
for k, v in pairs(ents.FindInSphere(Vector(-8951, 13034, 283), 1500)) do
if v and v:IsValid() then
if v:IsPlayer() then
if v:Alive() then
v:Kill();
end
else
v:Remove();
end
end
end
end

– Register the plugin.
cityrp.plugin.register(PLUGIN)[/lua]

You missed an end :slight_smile:

Thanks for the help, problem solved. :slight_smile:

Also, are you using Notepad++?

If you aren’t get it, because you can easily tell if you have gone wrong.

Yea, Notepad++ is really useful for spotting missing “ends” or brackets.

[editline]05:39PM[/editline]

Did you take Cider and replace cider with cityrp in all files?

I have Notepad++, I know how to find out where things as ) have to get added, but how can you see where ends have to be?

When you write function, a line will appear at the left.
Then press enter 2 times and write “end” and the line stops at end.

Everything inside that line, belongs to that function.

Why did people disagree? that’s a true statement, you have to include FindInSphere with an Sent, or at least tell it a position to start from.

You can’t just tell it to find something in a sphere, because it doesn’t have a position.