Soo... I'm trying to use ents.FindInSphere... but failing at it.

So here’s what this code is SUPPOSED to do in my head, when the RoundEnd function starts, it’s supposed to find everything in the sphere located in that position and if the variable it finds is a player, then it kills them. After that, it starts another function to notify players the round has ended… I know this code is probably horribly wrong, but I’m new into programming so whoever can answer this, please leave a detailed description of what I did wrong (It might be lengthy!)


function RoundEnd() 
	for k, v in pairs(ents.FindInSphere( Vector(444.428680, -1874.961670, -79.968750), 224 )) do
		if v:IsPlayer() then 
			v:Kill() 
				RoundNotifyEnd(v) 
		end
	end
end

That looks fine to me. Line 5 is indented one tab too many but that doesn’t make any difference to the behaviour of the code.

What does this code actually do when you run it?

First of all, you need a hook or console command to run or call this. Or at least SOMETHING otherwise you will never kill the player OR notify the players.

Otherwise, I believe that will work. Except you are printing only the players that are in that sphere that the round ended? If you want it to print to all players, take it outside the ifstatement.

EDIT:

Ninja’d.

As long as its a hook or if he’s called RoundEnd then he should be fine.

^ Edited it right before you quoted that.

“Or at least SOMETHING otherwise you will never kill the player OR notify the players.”

Here’s some code from perp1 you can ponder, your’s should work just fine as long as you call that function.

[lua]
function ProtectCave ( )
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();
v:Notify(‘Do not get near the cave.’);
end
else
v:Remove();
end
end
end
for k, v in pairs(player.GetAll()) do
if v:IsPlayer() and v:WaterLevel() >= 3 then
v:Kill()
v:Notify(‘Do not get near the cave.’)
end
end
end

if string.find(game.GetMap(), ‘rp_evocity_v2d’) then
hook.Add(‘Think’, ‘ProtectCave’, ProtectCave);
end
[/lua]

Also you don’t need to put ; at the end of every line, some scripters tend to do that a lot but it actually doesn’t make a difference in Lua.

And your code seems perfectly fine, actually.