If I have a map that has a lot of unfreezed props, how do I automatically freeze all of them on the server start?
Hook InitPostEntity then in there do the following loop
[lua]for k, v in pairs(ents.FindByClass("prop_physics")) do
local physobj = v:GetPhysicsObject()
if IsValid(physobj) then
physobj:EnableMotion(false)
end
end[/lua]
This gives me an error, not sure if I did something wrong
This is placed in the autorun/server folder
[CODE]function GM:InitPostEntity()
for k, v in pairs(ents.FindByClass("prop_physics")) do
local physobj = v:GetPhysicsObject()
if IsValid(physobj) then
physobj:EnableMotion(false)
print("All props have been frozen")
end
end[/CODE]
[QUOTE=MrGeekabit;49450383]This gives me an error, not sure if I did something wrong
This is placed in the autorun/server folder
[CODE]function GM:InitPostEntity()
for k, v in pairs(ents.FindByClass("prop_physics")) do
local physobj = v:GetPhysicsObject()
if IsValid(physobj) then
physobj:EnableMotion(false)
print("All props have been frozen")
end
end[/CODE][/QUOTE]
You're overriding the gamemodes InitPostEntity, use hook.Add instead. You're also missing an end.
If you still haven't figured it out, try this, it should work.
[CODE]
hook.Add( "InitPostEntity", "FreezeAllProps", function()
for k, v in pairs(ents.FindByClass("prop_physics")) do
local physobj = v:GetPhysicsObject()
if IsValid(physobj) then
physobj:EnableMotion(false)
print("All props have been frozen")
end
end
end )
[/CODE]
Sorry, you need to Log In to post a reply to this thread.