Skip to content

Instantly share code, notes, and snippets.

@OmegaExtern
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OmegaExtern/3e4c3efcfa9b2282fcea to your computer and use it in GitHub Desktop.
Save OmegaExtern/3e4c3efcfa9b2282fcea to your computer and use it in GitHub Desktop.
-- Run this on server, not client-side!
if not SERVER then
error('Run this on the server-side (lua_openscript)!')
end
-- Find all "func_breakable" entities, and store the result into local "func_breakables" variable.
local func_breakables = ents.FindByClass('func_breakable')
if #func_breakables < 1 then
-- Throws an error if none were founded.
error('No "func_breakable" entities were founded.')
end
-- Adds a function callback for each "func_breakable" entity in the game.
for k, v in pairs(func_breakables) do
v:AddCallback('PhysicsCollide', function(ent, data)
print(ent)
PrintTable(data)
if not IsValid(ent) or not IsValid(data.HitEntity) or not ent:IsPlayer() then
return
end
-- Do not use "v" here, instead use "data.HitEntity" which is the entity that ent is colliding with.
-- Assuming you have called your Player metamethod "CanPassThroughFuncBreakables", which returns either true or false.
-- ent is a collidee (it should be the player).
data.HitEntity:SetNotSolid(ent:CanPassThroughFuncBreakables())
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment