How can I make all glasses on a map unbreakable?

Hello,

as in the title, im searching for a code making all glasses (windows) on a map unbreakble when map starts… :frowning:
Can’t find anything.

For everyone searching a solution, this should work:

Thanks lexic.

–Snip-- Ok I was wrong.

You can. ent:SetKeyValue(…) or ent:Fire(…)

Well… i don’t rly know how to do this to all windows :\

[lua]

local function unbreakable()

if CLIENT then return end
for k, v in pairs( ents.GetAll() )

if v:GetClass() == “func_breakable_surf” then

v:SetKeyValue( “Strength”, 0 ) --Makes shit unbreakable

end

end

end

hook.Add( “InitPostEntity”, “lolWindoesAerAwsum”, unbreakable )
[/lua]

Jamie already told everything necessary! (Note: code may not work)

You missed out a do on the loop line.

Did the do thing, but still doesnt work (no error in console) but windows still break.

[lua]
function UnBreakableShit()
if( SERVER ) then
local k,v
for k,v in pairs(ents.GetAll()) do
if( v:GetClass() == “func_breakable_surf” or v:GetClass() == “func_breakable” ) then
if( string.match(string.lower(v:GetMaterial()), “glass”) ) then
v:SetKeyValue( “Strength”, 0)
end
end
end
end
end
hook.Add(“InitPostEntity”, “GlassPwnage”, UnBreakableShit)
[/lua]

Try that.

I am putting that in my ini.lua (which gets loaded correctly, also print(“Unbreakble glass”) and my print(v) outputs corretly) but glass is still breakable. hmm wired.

Strength needs to be capitalized.

This man is right.

[lua]
function UnBreakableShit()
if( SERVER ) then
local k,v
for k,v in pairs(ents.GetAll()) do
if( v:GetClass() == “func_breakable_surf” or v:GetClass() == “func_breakable” ) then
if( string.match(string.lower(v:GetMaterial()), “glass”) ) then
v:SetKeyValue( “Strength”, 0)
end
end
end
end
end
hook.Add(“InitPostEntity”, “GlassPwnage”, UnBreakableShit)
[/lua]

Why do you need the material checking? If the glass is breakable, it has to be a func_breakable_surf.

What if he has other breakables in the map, and doesn’t want to make those invulnerable?

If you read, he said “Make all glass on the map unbreakable”
Anyhow, it was just a question.

Well he said all glass not everything so i decided to add in the check to make sure it doesn’t make shit that isn’t glass unbreakable.

I.E. wood

[editline]11:50PM[/editline]

My bad… rarely have the need to mess with keyvalues.

[lua]hook.Add(“InitPostEntity”,“disable glass break”,function()
local filtr = ents.Create(“filter_activator_name”);
if (not IsValid(filtr)) then
error"Damage filter is not valid!";
end
filtr:SetKeyValue(“targetname”,“nobreak”);
filtr:SetKeyValue(“negated”,“1”);
filtr:Spawn();
for _,ent in ipairs(ents.FindByClass(“func_breakable_surf”)) do
ent:Fire(“setdamagefilter”, “nobreak”, 0);
end
end)[/lua]
Why do you guys make shit so complicated?

Same here. Does not work. Loop seems to be working. (tested with print)

[editline]02:37PM[/editline]

GREAT, THANKS! WORKING :wink: Big thanks!

You know, setting Strength to 0 should make the entities unbreakable.
That obviously works, but it’s seriously more harder to understand if you don’t know shit about source’s entity I/O :stuck_out_tongue:

[editline]10:39PM[/editline]

Oh yeah, I forgot completely about ents.FindByClass >.< Why not just set the keyvalue in thar?

Setting keyvalues on pre-spawned ents doesn’t work.
I’m fairly sure it used to, but it hasn’t worked the last few times I’ve tried, so it may have been disabled in a source update.

[lua]
function DontShootTheGlass(ply, k)
local tr = ply:GetEyeTrace()
if( tr.Entity:GetClass() == “func_breakable_surf” ) then
if( ply:KeyDown(IN_ATTACK) or ply:KeyDown(IN_ATTACK2) ) then
ply:Kill()
ply:PrintMessage(3, “Don’t shoot the fucking glass.”);
end
end
end
hook.Add(“KeyPress”, “I_Know_Right”, DontShootTheGlass)
[/lua]