trigger_teleport

is there a hook called whenever a player is teleported by a trigger_teleport entity?

i suppose there’s not a hook then.

You could try using StartTouch. If i’m correct a player has to be in the trigger for it to teleport them so that should work.

There isn’t. You can use this entity I created for a gamemode that needed this function.

entities/entities/trigger_teleport_wrapper.lua
[lua]
ENT.Type = “anim”

AccessorFuncDT(ENT, “VectorMins”, “Vector”, 0)
AccessorFuncDT(ENT, “VectorMaxs”, “Vector”, 1)

function ENT:Initialize()
self:DrawShadow(false)
self:SetCustomCollisionCheck(true)

local phys = self:GetPhysicsObject()
if phys:IsValid() then
	phys:EnableCollisions(false)
end

if not self.BoundsSet then
	self:SetBounds(Vector(-128, -128, 0), Vector(128, 128, 128))
end

end

function ENT:SetBounds(mins, maxs)
self.BoundsSet = true

OrderVectors(mins, maxs)

self:SetVectorMins(mins)
self:SetVectorMaxs(maxs)

self:RefreshBounds()

end

function ENT:RefreshBounds()
self:PhysicsInitBox(Vector(-1, -1, -1), Vector(1, 1, 1))
self:SetCollisionBoundsWS(self:GetVectorMins(), self:GetVectorMaxs())
self:SetCollisionGroup(COLLISION_GROUP_DEBRIS_TRIGGER)
self:SetMoveType(MOVETYPE_NONE)
self:SetTrigger(true)

local phys = self:GetPhysicsObject()
if phys:IsValid() then
	phys:EnableCollisions(false)
end

end

function ENT:StartTouch(ent)
if not ent:IsPlayer() then return end

ent.TouchingTeleport = self:GetParent()

end

function ENT:EndTouch(ent)
if not ent:IsPlayer() or not ent:IsValid() or ent.TouchingTeleport ~= self:GetParent() then return end

ent.TouchingTeleport = nil

local pos = ent:LocalToWorld(ent:OBBCenter())
local nearest = self:GetParent():NearestPoint(pos)

if nearest:Distance(pos) >= ent:BoundingRadius() then
	gamemode.Call("PlayerStoppedTouchingTeleport", ent, self)
end

end

function ENT:ShouldNotCollide(ent)
return true
end

function ENT:UpdateTransmitState()
return TRANSMIT_NEVER
end
[/lua]

gamemode/init.lua
[lua]
function GM:InitPostEntity()
for _, trigger in pairs(ents.FindByClass(“trigger_teleport”)) do
local ent = ents.Create(“trigger_teleport_wrapper”)
if ent:IsValid() then
ent:SetPos(trigger:LocalToWorld(trigger:OBBCenter()))
ent:SetOwner(trigger)
ent:SetParent(trigger)
ent:Spawn()
ent:SetBounds(trigger:WorldSpaceAABB())
end
end
end

function GM:PlayerStoppedTouchingTeleport(pl, ent)
–Your code here.
end
[/lua]