• Deathrun !ghost triggers certain traps
    0 replies, posted
I'm using this code to prevent ghosts in deathrun from activating auto traps: [code]hook.Add("AcceptInput", "TeleporterFix", function( ent, input, activator, caller, value ) print( ent, input, activator, caller, value ) local preventTriggers = { "Enable", "Disable", "Break", "Lock" } if (ent == "env_entity_maker") then return true end if IsValid( activator ) then if activator:IsPlayer() then if (activator:Team() == TEAM_RUNER) and table.HasValue( preventTriggers, input ) then print( "Suppressed input for", ent ) return true end end end end) local teleport_triggers = {} teleport_triggers = ents.FindByClass("*trigger_teleport*") hook.Add("InitPostEntity", "TeleportFix", function() teleport_triggers = ents.FindByClass("*trigger_teleport*") end) timer.Create("TeleportFix", 1, 0, function() teleport_triggers = ents.FindByClass("*trigger_teleport*") end) local function VectorMinMax( vec1, vec2 ) local min = Vector(0,0,0) local max = Vector(0,0,0) if vec1.x > vec2.x then max.x = vec1.x min.x = vec2.x else max.x = vec2.x min.x = vec1.x end if vec1.y > vec2.y then max.y = vec1.y min.y = vec2.y else max.y = vec2.y min.y = vec1.y end if vec1.z > vec2.z then max.z = vec1.z min.z = vec2.z else max.z = vec2.z min.z = vec1.z end return min, max end local function VectorInCuboid( pos, min, max ) -- check if vector is within cuboid local min, max = VectorMinMax( min, max ) -- get the min and max of the two corners if (pos.x > min.x and pos.x < max.x) and (pos.y > min.y and pos.y < max.y) and (pos.z > min.z and pos.z < max.z) then return true else return false end end hook.Add("Tick", "TeleportFix", function() -- tick hook so it's probably really heavy but it means that teleports happen as soon as possible for k,v in ipairs( teleport_triggers ) do if IsValid( v ) then local trigmax, trigmin = v:GetPos()+v:OBBMaxs(), v:GetPos()+v:OBBMins() for _, ply in ipairs( team.GetPlayers( TEAM_RUNER ) ) do local plymax, plymin = ply:GetPos()+ply:OBBMaxs(), ply:GetPos()+ply:OBBMins() --PrintTable( v:GetKeyValues() ) local collide = false collide = VectorInCuboid( plymin, trigmin, trigmax ) or VectorInCuboid( plymax, trigmin, trigmax ) or false if collide == true then -- ShouldCollide doesnt get called for trigger_teleport :( local keyvals = v:GetKeyValues() local targetname = keyvals["target"] local results = ents.FindByName( targetname ) if (targetname == "trap_14_tele") then return true end if (targetname == "TTELEPORT") then return true end if (targetname == "TFloor") then return true end if (targetname == "e1t2") then return true end if (targetname == "e1t2a") then return true end if #results == 1 and keyvals["TeamNum"] ~= 2 then -- ignore death teleports --PrintTable( v:GetKeyValues() ) --print( keyvals["EnableDisable"] ) print( "Simulating player teleport to", targetname ) local target = results[1] ply:SetPos( target:GetPos() ) ply:SetVelocity( -ply:GetVelocity() ) end end end end end end)[/code] The problem is this prevents traps that only use break, enable, disable, and lock triggers. It does not prevent auto traps that use break on touch, break on pressure, and break on physics. Is there any way I can fix this?
Sorry, you need to Log In to post a reply to this thread.