lsft/modules/server/sv_teleport.txt

126 lines
No EOL
4.5 KiB
Text

--@name
--@author
--@server
teleport = {}
do
local function findSafeCoords(coordsin)
local MULTIPLIER = 50 -- How spaced apart the teleport checks are
local CHECKPOINTS = 3 -- How many points to check per axis, MUST BE ODD!
local min = -math.floor(CHECKPOINTS/2)
local max = math.floor(CHECKPOINTS/2)
for x = min,max do
for y = min,max do
for z = min,max do
local teleportcoords = coordsin + Vector(x,y,z)*MULTIPLIER + Vector(0,0,10)
local cornersw = teleportcoords - Vector(17,17,0)
local cornerne = teleportcoords + Vector(17,17,0)
-- TraceHull was being stupid, this is good enough probably
local traceresult = (
trace.trace(cornersw, cornerne+Vector(0,0,90), nil, nil, nil, false).Hit
or
trace.trace(cornerne, cornersw+Vector(0,0,90), nil, nil, nil, false).Hit
)
local testresult = (
trace.pointContents(cornersw) == 1
or
trace.pointContents(cornerne) == 1
or
trace.pointContents(cornersw+Vector(0,0,90)) == 1
or
trace.pointContents(cornerne+Vector(0,0,90)) == 1
or
trace.pointContents(teleportcoords) == 1
)
if not traceresult and not testresult then
--print(trace.pointContents(teleportcoords))
return teleportcoords
--holograms.create(teleportcoords, Angle(0,0,0), "models/hunter/misc/sphere025x025.mdl", Vector(0.5,0.5,0.5)):setColor(Color(0,255,0))
else
--holograms.create(teleportcoords, Angle(0,0,0), "models/hunter/misc/sphere025x025.mdl", Vector(0.5,0.5,0.5)):setColor(Color(255,0,0))
end
end
end
end
return false
end
function teleport:tpteleport(args)
local coords = chip():getPos()
if args[1] ~= nil and args[2] ~= nil and args[3] ~= nil then
coords = Vector(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]))
else
coords = owner():getEyeTrace().HitPos
local offset = Vector(40,40,40)
offset:rotate(owner():getEyeAngles())
coords = coords-offset
end
coords = findSafeCoords(coords)
if not coords then
core:log(log.WARNING, "Could not find a safe position to teleport to!")
return false
end
local seat = prop.createSent(coords, Angle(0,0,0), "Seat_Airboat", true)
seat:setColor(Color(255,255,255,0))
seat:setSolid(false)
seat:use()
seat:remove()
return true
end
function teleport:tpgoto(args)
local targets = find.playersByName(args[1])
if #targets == 0 or targets == nil then
core:log(log.ERROR, "No targets found!")
return
elseif #targets > 1 then
local list = ""
for i, v in pairs(target) do
list = list..v..", "
end
list:sub(1, -2)
core:log(log.ERROR, "Muliple targets found! ("..list..")")
return
end
local targetpos = findSafeCoords(targets[1]:getPos())
local result = teleport:tpteleport({targetpos.x, targetpos.y, targetpos.z})
if result then
core:log(log.INFO, "Successfully teleported to \""..targets[1]:getName().."\".")
end
end
core.modules.teleport = {
version = 1,
desc = "Move player to somewhere else.",
commands = {
goto = {
func = function(args) teleport:tpgoto(args) end, -- Fuck you Lua
usage = "goto <ply>",
desc = "Send yourself to player ply.",
},
teleport = {
func = function(args) teleport:tpteleport(args) end, -- :(
usage = "teleport [x] [y] [z]",
desc = "Send yourself to either your aimpos or the specified coordinates.",
},
},
}
end