So I made this;
[LUA]
local function AntiSpawnBlock()
local props = {}
props = ent.FindInBox(Vector(-215,-693,-193), Vector(1338,-365,175))
for i = 0, table.Count(props) do
if (props[i]:GetClass() == "prop_physics") then
props[i]:Remove()
end
end
timer.Simple(0.5,AntiSpawnBlock)
end
timer.Simple(0.5,AntiSpawnBlock)
[/LUA]
And it doesn't work, it gives me this;
[LUA]
Timer Error: [lua\autorun\server\antispawnblock.lua:3] attempt to index global 'ent' (a nil value)
[/LUA]
Help!
its ents , not ent.
[code]
local function AntiSpawnBlock()
local props = ents.FindInBox(Vector(-215,-693,-193), Vector(1338,-365,175))
for i = 1, #props do
if (props[i]:GetClass() == "prop_physics") then
props[i]:Remove()
end
end
timer.Simple(0.5,AntiSpawnBlock)
end
timer.Simple(0.5,AntiSpawnBlock)
[/code]
[code]local min = Vector(-215,-693,-193)
local max = Vector(1338,-365,175)
local function AntiSpawnBlock()
local props = {}
props = ents.FindInBox(min, max)
for i = 1, #props do
if (props[i]:GetClass() == "prop_physics") then
props[i]:Remove()
end
end
timer.Simple(0.5,AntiSpawnBlock)
end
timer.Simple(0.5,AntiSpawnBlock)[/code]
Localize the vectors.
You do not even need [I]table.Count(props)[/I]. Use [i]#props[/i]. It is quicker and it is what you actually need.
[editline]asd[/editline] And of course, ents, not ent.
[editline]...[/editline] Array indices start at 1, not 0.
Fixed the code.
[QUOTE=vercas;37507440][code]local min = Vector(-215,-693,-193)
local max = Vector(1338,-365,175)
local function AntiSpawnBlock()
local props = {}
props = ents.FindInBox(min, max)
for i = 1, #props do
if (props[i]:GetClass() == "prop_physics") then
props[i]:Remove()
end
end
timer.Simple(0.5,AntiSpawnBlock)
end
timer.Simple(0.5,AntiSpawnBlock)[/code]
Localize the vectors.
You do not even need [I]table.Count(props)[/I]. Use [i]#props[/i]. It is quicker and it is what you actually need.
[editline]asd[/editline] And of course, ents, not ent.
[editline]...[/editline] Array indices start at 1, not 0.
Fixed the code.[/QUOTE]
Ah i didn't notice the array indices.
As for the locals, they are not needed. You are referencing data that is only used once. You can keep them as they are.
Sorry, you need to Log In to post a reply to this thread.