I'm trying to make a redie thing for Deathrun. The problem is that while in redie, players can activate auto traps. I tried to fix the problem with this:
[code]
function sccc()
for k, v in pairs(team.GetPlayers(4)) do
v:SetCustomCollisionCheck(true)
end
end
hook.Add("Think", "test", sccc)
function ShouldCollideTestHook( ent1, ent2 )
if ( ent1 == ents.FindByClass("func_breakable") and ent2:IsPlayer() ) then
return false
end
end
hook.Add( "ShouldCollide", "ShouldCollideTestHook", ShouldCollideTestHook )
[/code]
when set to true, players in redie can activate auto traps, but they can still walk over any other trap without a problem. when set to false players in redie will fall through the auto traps without activating them, but they will also fall through every trap. If I wasn't clear on anything , please leave a reply. I've been trying to figure this out for a while and any help would be appreciated.
The following code *should* prevent players on TEAM_GHOST from triggering autotraps. The downside of this is that it disables ghosts from moving through teleporters, so I also replaced teleporter functionality for the ghost team. Maybe this will put you on the right track or at least give some background on which hooks to use and how to use them.
I actually wrote this originally for niandra's ghostmode addon I don't think she actually looked at it so it was never added.
[code]hook.Add("AcceptInput", "TeleporterFix", function( ent, input, activator, caller, value )
--print( ent, input, activator, caller, value )
local preventTriggers = { "Enable", "Disable", "Break", "Lock" }
if IsValid( activator ) then
if activator:IsPlayer() then
if (activator:Team() == TEAM_GHOST or activator:IsGhostMode()) 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_GHOST ) ) 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 #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]
Thank you! This helps me a lot
[QUOTE=Arizard;49670163]The following code *should* prevent players on TEAM_GHOST from triggering autotraps. The downside of this is that it disables ghosts from moving through teleporters, so I also replaced teleporter functionality for the ghost team. Maybe this will put you on the right track or at least give some background on which hooks to use and how to use them.
I actually wrote this originally for niandra's ghostmode addon I don't think she actually looked at it so it was never added.
[code]hook.Add("AcceptInput", "TeleporterFix", function( ent, input, activator, caller, value )
--print( ent, input, activator, caller, value )
local preventTriggers = { "Enable", "Disable", "Break", "Lock" }
if IsValid( activator ) then
if activator:IsPlayer() then
if (activator:Team() == TEAM_GHOST or activator:IsGhostMode()) 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_GHOST ) ) 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 #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][/QUOTE]
How did you know to use *trigger_teleport in ents.findbyclass? I couldn't find anything like that when I used ents.GetAll. Also, that code works great on most auto traps, but in some areas of maps the ghost will get teleported to the end for no reason and some of the auto traps still go off. Could I use a program like Hammer to open a map and find specific entities, then translate the entities to code where it would restrict ghosts from interacting with those entities?
This is quite a while ago, but if I recall correctly I figure out I needed to find trigger_teleport entities when I was printing the "input" argument in the AcceptInput hook after I went through a teleport. Then I printed the ent:GetKeyValues() table to figure out which keyvalue stored the teleport destination.
As for being teleported randomly, I think some maps actually have teleports over certain areas that are only activated when a player finishes the map. You may have to investigate the keyvalues of the teleports that activate on ghosts at the wrong time to check whether or not you can determine if they are enabled or disabled, or whether there is a filter for non-player entities.
[QUOTE=Arizard;49676039]This is quite a while ago, but if I recall correctly I figure out I needed to find trigger_teleport entities when I was printing the "input" argument in the AcceptInput hook after I went through a teleport. Then I printed the ent:GetKeyValues() table to figure out which keyvalue stored the teleport destination.
As for being teleported randomly, I think some maps actually have teleports over certain areas that are only activated when a player finishes the map. You may have to investigate the keyvalues of the teleports that activate on ghosts at the wrong time to check whether or not you can determine if they are enabled or disabled, or whether there is a filter for non-player entities.[/QUOTE]
I notice when I use ent:GetKeyValues(), each teleport has a different target. Could I get the targets of the teleporters causing problems and disable them? Something like
[code]
hook.Add("AcceptInput", "TeleporterFix", function( ent, input, activator, caller, value )
if (target == e1t2a and activator:IsPlayer()) then
return false
end) [/code]
sure, but you would have to somehow record the MapCreationIDs for all these problem triggers for every map you play on
also you should return true to disable, and not false (weird right?)
I think I lost the code and was too embarrassed to ask for it again LOL
Thank you for posting it here though, I'll see abput actually implementing it
[QUOTE=Arizard;49676039]This is quite a while ago, but if I recall correctly I figure out I needed to find trigger_teleport entities when I was printing the "input" argument in the AcceptInput hook after I went through a teleport. Then I printed the ent:GetKeyValues() table to figure out which keyvalue stored the teleport destination.
As for being teleported randomly, I think some maps actually have teleports over certain areas that are only activated when a player finishes the map. You may have to investigate the keyvalues of the teleports that activate on ghosts at the wrong time to check whether or not you can determine if they are enabled or disabled, or whether there is a filter for non-player entities.[/QUOTE]
I tried to check whenever a teleporter is activated or not but in the keyvalues I do not find any useful information about the state of it. Could you help me finding a workaround :quotes: please?
Thanks
Sorry, you need to Log In to post a reply to this thread.