Freezing props on a map

I’m trying to make it so when these props are on a map they’re unmovable/frozen. Mainly as just a test. I’ve tried multiple variations of this code. Any ideas why it’s not working?

[lua]local banned_mdls = {
“models/props_junk/wood_crate001a.mdl”,
“models/props_wasteland/kitchen_counter001d.mdl”
}

function RemoveBannedModels()
for _, mdl in pairs( banned_mdls ) do
local found_ents = ents.FindByModel( mdl )
for _, ent in pairs( found_ents ) do
ent:GetPhysicsObject():EnableMotion( false )
end
end
end
hook.Add( “InitPostEntity”, “RemoveBannedModels”, RemoveBannedModels )[/lua]

Try this:



local banned_mdls = {
    ["models/props_junk/wood_crate001a.mdl"] = true,
    ["models/props_wasteland/kitchen_counter001d.mdl"] = true
}

local function RemoveBannedModels()
    for _, ent in pairs( ents.GetAll() ) do
        if banned_mdls[ ent:GetModel() ] then
            ent:GetPhysicsObject():EnableMotion( false )
        end
    end
end
hook.Add( "InitPostEntity", "RemoveBannedModels", RemoveBannedModels )


No clue if that works, but I think it would run faster :stuck_out_tongue:

[editline]10th May 2016[/editline]

Hang on, I’ll test…

[editline]10th May 2016[/editline]

The RemoveBannedModels function seems to work, but I don’t know if the hook does… your problem is probably that the hook isn’t working because of this:

Try using a different hook or adding a timer

What hook would you suggest using? I tried PostGamemode, it works fine on PlayerSpawn but that’s really inefficient to run it on every spawn.

PlayerInitialSpawn

Didn’t work, if it changes anything, I’m running Trouble in Terrorist Town.

I don’t really understand why InitPostEntity serverside wouldn’t work for you, but I guess you can just do OnEntityCreated and check if the prop has the model.

-snip- I thought your message was talking about PlayerInitialSpawn. Not really sure why InitPostEntity is not working either. I only have 2 addons so it couldn’t be that.

Are you absolutely sure you’re only running it serverside? Also, did you try adding a timer?

I have not tried adding a timer. It’s in serverside though. I’ll try adding a timer and see how it goes.

[editline]10th May 2016[/editline]

So it turns out, I did some testing, inside of the function ent:Remove() works but ent:GetPhysicsObject():EnableMotion(false) does not work. Any idea why I can’t just disable motion? Also, when there’s 2 people and the round starts, the props respawn.
[lua]function RemoveBannedModels()
for _, ent in pairs( ents.GetAll() ) do
if banned_mdls[ ent:GetModel() ] then
– ent:GetPhysicsObject():EnableMotion( false ) <-- This doesn’t work, but ent:Remove() does.
ent:Remove()
end
end
end
hook.Add(“InitPostEntity”, “RemoveBannedModels”, RemoveBannedModels)[/lua]

Try instead this ttt hook, wich runs instead after the gamemode manages the props.
TTTPrepareRound

game.CleanUpMap restores the props. You can detour this to remove the props after it is called. As for why EnableMotion doesn’t work, it’s probably because the engine is still doing stuff with constraints.

Yeah. I finally got it working. Here is the finish product for anyone who wants to do it in the future. I’m not really sure how to mark it as solved.
[lua]local banned_mdls = {
[“ttt_slender_v2”] = {
[“models/props_wasteland/kitchen_counter001d.mdl”] = true,
[“models/props_wasteland/kitchen_counter001b.mdl”] = true
},
[“ttt_richland”] = {
[“models/props_vehicles/car004a_physics.mdl”] = true,
[“models/props_vehicles/car003b_physics.mdl”] = true,
[“models/props_vehicles/car002a_physics.mdl”] = true,
[“models/props_vehicles/car005a_physics.mdl”] = true
}
}

function RemoveBannedModels()
local map = game.GetMap()
if not banned_mdls[map] then return end
for _, ent in pairs(ents.GetAll()) do
if banned_mdls[map][ent:GetModel()] then
ent:GetPhysicsObject():EnableMotion(false)
end
end
end

hook.Add(“TTTPrepareRound”, “RemoveBannedModels”, RemoveBannedModels)[/lua]

Mark As Solved in the upper-left corner of the thread. Ctrl+F “solve” if you can’t find it.

Thank you. I kept trying to go to edit and add a prefix that way.