I am coding something for my server, but I keep getting an error:
Bad argument #1 to 'FindByClass' (string expected, got table)
I'm trying to find a number of classes by a table.
I tried converting it to a string using tostring but to no avail.
I would prefer not to post my code, as it is classified.
We can't help you if you don't post your code.
[quote]
local PropsRemove = {
"prop_physics",
"phys_ragdoll",
"weapon_*"
}
function remove()
for k,v in pairs(ents.FindByClass(PropsRemove)) do
v:Remove()
end
end
concommand.Add("remove", remove)
[/quote]
That is the code i'm trying
Try this.
[lua]
local PropsRemove = ents.FindByClass("prop_physics")
PropsRemove = table.Add(PropsRemove, ents.FindByClass("phys_ragdoll"))
PropsRemove = table.Add(PropsRemove, ents.FindByClass("weapon_*"))
function remove()
for k,v in pairs(ents.FindByClass(PropsRemove)) do v:Remove() end end
concommand.Add("remove", remove)[/lua]
That will get all the entities (and never refresh them) right when the script runs. Also, you're still making the same mistake he is.
[lua]
local PropsRemove = { "prop_physics", "phys_ragdoll", "weapon_*" }
concommand.Add( "remove", function( ply )
for _, Type in pairs( PropsRemove ) do
for k, v in pairs( ents.FindByClass( Type ) ) do
v:Remove()
end
end
end )[/lua]
Still the same error :(
Well try looping through the indeces instead of giving it a table then
Sorry, I totally was looking at your code when I typed the do statement
Try this instead.
[lua]
local PropsRemove = ents.FindByClass("prop_physics")
PropsRemove = table.Add(PropsRemove, ents.FindByClass("phys_ragdoll"))
PropsRemove = table.Add(PropsRemove, ents.FindByClass("weapon_*"))
function remove()
for _,PropsRemove in pairs(PropsRemove) do do v:Remove() end end
concommand.Add("remove", remove)[/lua] I've had it working this way for a while.
Sorry, you need to Log In to post a reply to this thread.