mirror of
https://github.com/Xerasin/Sit-Anywhere.git
synced 2025-03-04 03:13:07 -05:00
Cleanup and refactor
This commit is contained in:
parent
fa222e96b7
commit
66eabac7d6
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
* text=auto eol=lf
|
@ -1,13 +1,13 @@
|
||||
{
|
||||
"title": "The Sit Anywhere Script!",
|
||||
"type": "tool",
|
||||
"tags": ["roleplay", "realism"],
|
||||
"ignore": [
|
||||
"*.psd",
|
||||
"*.vcproj",
|
||||
"*.svn*",
|
||||
".git/*",
|
||||
".gitignore",
|
||||
"*.gma"
|
||||
]
|
||||
"title": "The Sit Anywhere Script!",
|
||||
"type": "tool",
|
||||
"tags": ["roleplay", "realism"],
|
||||
"ignore": [
|
||||
"*.psd",
|
||||
"*.vcproj",
|
||||
"*.svn*",
|
||||
".git/*",
|
||||
".gitignore",
|
||||
"*.gma"
|
||||
]
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
if SERVER then
|
||||
AddCSLuaFile("sitanywhere/client/sit.lua")
|
||||
AddCSLuaFile("sitanywhere/helpers.lua")
|
||||
include("sitanywhere/helpers.lua")
|
||||
include("sitanywhere/server/sit.lua")
|
||||
AddCSLuaFile("sitanywhere/client/sit.lua")
|
||||
AddCSLuaFile("sitanywhere/helpers.lua")
|
||||
include("sitanywhere/helpers.lua")
|
||||
include("sitanywhere/server/sit.lua")
|
||||
|
||||
AddCSLuaFile("sitanywhere/ground_sit.lua")
|
||||
include("sitanywhere/server/unstuck.lua")
|
||||
include("sitanywhere/ground_sit.lua")
|
||||
AddCSLuaFile("sitanywhere/ground_sit.lua")
|
||||
include("sitanywhere/server/unstuck.lua")
|
||||
include("sitanywhere/ground_sit.lua")
|
||||
else
|
||||
include("sitanywhere/helpers.lua")
|
||||
include("sitanywhere/client/sit.lua")
|
||||
include("sitanywhere/helpers.lua")
|
||||
include("sitanywhere/client/sit.lua")
|
||||
|
||||
include("sitanywhere/ground_sit.lua")
|
||||
include("sitanywhere/ground_sit.lua")
|
||||
end
|
@ -1,11 +1,11 @@
|
||||
local TAG = "SitAny_"
|
||||
local useAlt = CreateClientConVar("sitting_use_alt", "1.00", true, true)
|
||||
local forceBinds = CreateClientConVar("sitting_force_binds", "0", true, true)
|
||||
local useAlt = CreateClientConVar("sitting_use_alt", "1.00", true, true)
|
||||
local forceBinds = CreateClientConVar("sitting_force_binds", "0", true, true)
|
||||
local SittingNoAltServer = CreateConVar("sitting_force_no_alt","0", {FCVAR_NOTIFY, FCVAR_ARCHIVE, FCVAR_REPLICATED})
|
||||
|
||||
|
||||
CreateClientConVar("sitting_ground_sit", "1.00", true, true)
|
||||
CreateClientConVar("sitting_disallow_on_me", "0.00", true, true)
|
||||
CreateClientConVar("sitting_ground_sit", "1.00", true, true)
|
||||
CreateClientConVar("sitting_disallow_on_me", "0.00", true, true)
|
||||
|
||||
local function ShouldSit(ply)
|
||||
return hook.Run("ShouldSit", ply)
|
||||
|
@ -1,16 +1,16 @@
|
||||
SitAnywhere = SitAnywhere or {}
|
||||
SitAnywhere.NET = {
|
||||
["SitWantedAng"] = 0,
|
||||
["SitRequestExit"] = 1,
|
||||
["SitWantedAng"] = 0,
|
||||
["SitRequestExit"] = 1,
|
||||
}
|
||||
|
||||
SitAnywhere.ClassBlacklist = {
|
||||
["gmod_wire_keyboard"] = true,
|
||||
["prop_combine_ball"] = true
|
||||
["gmod_wire_keyboard"] = true,
|
||||
["prop_combine_ball"] = true
|
||||
}
|
||||
|
||||
SitAnywhere.DoNotParent = {
|
||||
["yava_chunk"] = true
|
||||
["yava_chunk"] = true
|
||||
}
|
||||
SitAnywhere.ModelBlacklist = {
|
||||
}
|
||||
@ -18,52 +18,52 @@ SitAnywhere.ModelBlacklist = {
|
||||
local EMETA = FindMetaTable"Entity"
|
||||
|
||||
function SitAnywhere.GetAreaProfile(pos, resolution, simple)
|
||||
local filter = player.GetAll()
|
||||
local dists = {}
|
||||
local distsang = {}
|
||||
local ang_smallest_hori = nil
|
||||
local smallest_hori = 90000
|
||||
local angPerIt = (360 / resolution)
|
||||
for I = 0, 360, angPerIt do
|
||||
local rad = math.rad(I)
|
||||
local dir = Vector(math.cos(rad), math.sin(rad), 0)
|
||||
local trace = util.QuickTrace(pos + dir * 20 + Vector(0,0,5), Vector(0,0,-15000), filter)
|
||||
trace.HorizontalTrace = util.QuickTrace(pos + Vector(0,0,5), dir * 1000, filter)
|
||||
trace.Distance = trace.StartPos:Distance(trace.HitPos)
|
||||
trace.Distance2 = trace.HorizontalTrace.StartPos:Distance(trace.HorizontalTrace.HitPos)
|
||||
trace.ang = I
|
||||
local filter = player.GetAll()
|
||||
local dists = {}
|
||||
local distsang = {}
|
||||
local ang_smallest_hori = nil
|
||||
local smallest_hori = 90000
|
||||
local angPerIt = (360 / resolution)
|
||||
for I = 0, 360, angPerIt do
|
||||
local rad = math.rad(I)
|
||||
local dir = Vector(math.cos(rad), math.sin(rad), 0)
|
||||
local trace = util.QuickTrace(pos + dir * 20 + Vector(0,0,5), Vector(0,0,-15000), filter)
|
||||
trace.HorizontalTrace = util.QuickTrace(pos + Vector(0,0,5), dir * 1000, filter)
|
||||
trace.Distance = trace.StartPos:Distance(trace.HitPos)
|
||||
trace.Distance2 = trace.HorizontalTrace.StartPos:Distance(trace.HorizontalTrace.HitPos)
|
||||
trace.ang = I
|
||||
|
||||
if (not trace.Hit or trace.Distance > 14) and (not trace.HorizontalTrace.Hit or trace.Distance2 > 20) then
|
||||
if simple then return true end
|
||||
table.insert(dists, trace)
|
||||
end
|
||||
if trace.Distance2 < smallest_hori and (not trace.HorizontalTrace.Hit or trace.Distance2 > 3) then
|
||||
smallest_hori = trace.Distance2
|
||||
ang_smallest_hori = I
|
||||
end
|
||||
distsang[I] = trace
|
||||
end
|
||||
if (not trace.Hit or trace.Distance > 14) and (not trace.HorizontalTrace.Hit or trace.Distance2 > 20) then
|
||||
if simple then return true end
|
||||
table.insert(dists, trace)
|
||||
end
|
||||
if trace.Distance2 < smallest_hori and (not trace.HorizontalTrace.Hit or trace.Distance2 > 3) then
|
||||
smallest_hori = trace.Distance2
|
||||
ang_smallest_hori = I
|
||||
end
|
||||
distsang[I] = trace
|
||||
end
|
||||
|
||||
if simple then return false end
|
||||
return dists, distsang, ang_smallest_hori, smallest_hori
|
||||
if simple then return false end
|
||||
return dists, distsang, ang_smallest_hori, smallest_hori
|
||||
end
|
||||
|
||||
function SitAnywhere.CheckValidAngForSit(pos, surfaceAng, ang)
|
||||
local rad = math.rad(ang)
|
||||
local dir = Vector(math.cos(rad), math.sin(rad), 0)
|
||||
local trace2 = util.TraceLine({
|
||||
start = pos - dir * (20 - .5) + surfaceAng:Forward() * 5,
|
||||
endpos = pos - dir * (20 - .5) + surfaceAng:Forward() * -160,
|
||||
filter = player.GetAll()
|
||||
})
|
||||
local rad = math.rad(ang)
|
||||
local dir = Vector(math.cos(rad), math.sin(rad), 0)
|
||||
local trace2 = util.TraceLine({
|
||||
start = pos - dir * (20 - .5) + surfaceAng:Forward() * 5,
|
||||
endpos = pos - dir * (20 - .5) + surfaceAng:Forward() * -160,
|
||||
filter = player.GetAll()
|
||||
})
|
||||
|
||||
local hor_trace = util.TraceLine({
|
||||
start = pos + Vector(0, 0, 5),
|
||||
endpos = pos + Vector(0, 0, 5) - dir * 1600,
|
||||
filter = player.GetAll()
|
||||
})
|
||||
local hor_trace = util.TraceLine({
|
||||
start = pos + Vector(0, 0, 5),
|
||||
endpos = pos + Vector(0, 0, 5) - dir * 1600,
|
||||
filter = player.GetAll()
|
||||
})
|
||||
|
||||
return hor_trace.StartPos:Distance(hor_trace.HitPos) > 20 and trace2.StartPos:Distance(trace2.HitPos) > 14
|
||||
return hor_trace.StartPos:Distance(hor_trace.HitPos) > 20 and trace2.StartPos:Distance(trace2.HitPos) > 14
|
||||
end
|
||||
|
||||
|
||||
@ -78,113 +78,119 @@ local SitOnEntsMode = CreateConVar("sitting_ent_mode","3", {FCVAR_NOTIFY, FCVAR_
|
||||
local blacklist = SitAnywhere.ClassBlacklist
|
||||
local model_blacklist = SitAnywhere.ModelBlacklist
|
||||
function SitAnywhere.ValidSitTrace(ply, EyeTrace)
|
||||
if not EyeTrace.Hit then return false end
|
||||
if EyeTrace.HitPos:Distance(EyeTrace.StartPos) > 100 then return false end
|
||||
local t = hook.Run("CheckValidSit", ply, EyeTrace)
|
||||
if not EyeTrace.Hit then return false end
|
||||
if EyeTrace.HitPos:Distance(EyeTrace.StartPos) > 100 then return false end
|
||||
local t = hook.Run("CheckValidSit", ply, EyeTrace)
|
||||
|
||||
if t == false or t == true then
|
||||
return t
|
||||
end
|
||||
if t == false or t == true then
|
||||
return t
|
||||
end
|
||||
|
||||
if not EyeTrace.HitWorld and SitOnEntsMode:GetInt() == 0 then return false end
|
||||
if not EyeTrace.HitWorld and blacklist[string.lower(EyeTrace.Entity:GetClass())] then return false end
|
||||
if not EyeTrace.HitWorld and EyeTrace.Entity:GetModel() and model_blacklist[string.lower(EyeTrace.Entity:GetModel())] then return false end
|
||||
if not EyeTrace.HitWorld and SitOnEntsMode:GetInt() == 0 then return false end
|
||||
if not EyeTrace.HitWorld and blacklist[string.lower(EyeTrace.Entity:GetClass())] then return false end
|
||||
if not EyeTrace.HitWorld and EyeTrace.Entity:GetModel() and model_blacklist[string.lower(EyeTrace.Entity:GetModel())] then return false end
|
||||
|
||||
|
||||
if EMETA.CPPIGetOwner and SitOnEntsMode:GetInt() >= 1 then
|
||||
if SitOnEntsMode:GetInt() == 1 then
|
||||
if not EyeTrace.HitWorld then
|
||||
local owner = EyeTrace.Entity:CPPIGetOwner()
|
||||
if type(owner) == "Player" and owner ~= nil and owner:IsValid() and owner:IsPlayer() then
|
||||
return false
|
||||
end
|
||||
end
|
||||
elseif SitOnEntsMode:GetInt() == 2 then
|
||||
if not EyeTrace.HitWorld then
|
||||
local owner = EyeTrace.Entity:CPPIGetOwner()
|
||||
if type(owner) == "Player" and owner ~= nil and owner:IsValid() and owner:IsPlayer() and owner ~= ply then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
if EMETA.CPPIGetOwner and SitOnEntsMode:GetInt() >= 1 then
|
||||
if SitOnEntsMode:GetInt() == 1 then
|
||||
if not EyeTrace.HitWorld then
|
||||
local owner = EyeTrace.Entity:CPPIGetOwner()
|
||||
if type(owner) == "Player" and owner ~= nil and owner:IsValid() and owner:IsPlayer() then
|
||||
return false
|
||||
end
|
||||
end
|
||||
elseif SitOnEntsMode:GetInt() == 2 then
|
||||
if not EyeTrace.HitWorld then
|
||||
local owner = EyeTrace.Entity:CPPIGetOwner()
|
||||
if type(owner) == "Player" and owner ~= nil and owner:IsValid() and owner:IsPlayer() and owner ~= ply then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local seatClass = "prop_vehicle_prisoner_pod"
|
||||
local PMETA = FindMetaTable"Player"
|
||||
function PMETA:GetSitters()
|
||||
local seats, holders = {}, {}
|
||||
local seats, holders = {}, {}
|
||||
|
||||
local function processSeat(seat, depth)
|
||||
depth = (depth or 0) + 1
|
||||
if IsValid(seat:GetDriver()) and seat:GetDriver() ~= self then
|
||||
table.insert(seats, seat)
|
||||
end
|
||||
for _, v in pairs(seat:GetChildren()) do
|
||||
if IsValid(v) and v:GetClass() == seatClass and IsValid(v:GetDriver()) and #v:GetChildren() > 0 and depth <= 128 then
|
||||
processSeat(v, depth)
|
||||
end
|
||||
end
|
||||
end
|
||||
local function processSeat(seat, depth)
|
||||
depth = (depth or 0) + 1
|
||||
if IsValid(seat:GetDriver()) and seat:GetDriver() ~= self then
|
||||
table.insert(seats, seat)
|
||||
end
|
||||
for _, v in pairs(seat:GetChildren()) do
|
||||
if IsValid(v) and v:GetClass() == seatClass and IsValid(v:GetDriver()) and #v:GetChildren() > 0 and depth <= 128 then
|
||||
processSeat(v, depth)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local plyVehicle = self:GetVehicle()
|
||||
if IsValid(plyVehicle) and plyVehicle:GetClass() == seatClass then
|
||||
processSeat(plyVehicle)
|
||||
end
|
||||
local plyVehicle = self:GetVehicle()
|
||||
if IsValid(plyVehicle) and plyVehicle:GetClass() == seatClass then
|
||||
processSeat(plyVehicle)
|
||||
end
|
||||
|
||||
for _, v in pairs(self:GetChildren()) do
|
||||
if IsValid(v) and v:GetClass() == seatClass then
|
||||
processSeat(v)
|
||||
end
|
||||
end
|
||||
for _, v in pairs(self:GetChildren()) do
|
||||
if IsValid(v) and v:GetClass() == seatClass then
|
||||
processSeat(v)
|
||||
end
|
||||
end
|
||||
|
||||
for _, v in pairs(ents.FindByClass("sit_holder")) do
|
||||
if v.GetTargetPlayer and v:GetTargetPlayer() == self then
|
||||
table.insert(holders, v)
|
||||
if v.GetSeat and IsValid(v:GetSeat()) then
|
||||
processSeat(v:GetSeat())
|
||||
end
|
||||
end
|
||||
end
|
||||
return seats, holders
|
||||
for _, v in pairs(ents.FindByClass("sit_holder")) do
|
||||
if v.GetTargetPlayer and v:GetTargetPlayer() == self then
|
||||
table.insert(holders, v)
|
||||
if v.GetSeat and IsValid(v:GetSeat()) then
|
||||
processSeat(v:GetSeat())
|
||||
end
|
||||
end
|
||||
end
|
||||
return seats, holders
|
||||
end
|
||||
|
||||
function PMETA:IsPlayerSittingOn(ply)
|
||||
local seats = ply:GetSitters()
|
||||
for _,v in pairs(seats) do
|
||||
if IsValid(v:GetDriver()) and v:GetDriver() == self then return true end
|
||||
end
|
||||
return false
|
||||
local seats = ply:GetSitters()
|
||||
for _,v in pairs(seats) do
|
||||
if IsValid(v:GetDriver()) and v:GetDriver() == self then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function PMETA:GetSitting()
|
||||
if not IsValid(self:GetVehicle()) then return false end
|
||||
local veh = self:GetVehicle()
|
||||
if veh:GetNWBool("playerdynseat", false) then
|
||||
local parent = veh:GetParent()
|
||||
if IsValid(parent) and parent:GetClass() == "sit_holder" then
|
||||
return veh, parent
|
||||
else
|
||||
return veh
|
||||
end
|
||||
end
|
||||
return false
|
||||
if not IsValid(self:GetVehicle()) then return false end
|
||||
local veh = self:GetVehicle()
|
||||
if veh:GetNWBool("playerdynseat", false) then
|
||||
local parent = veh:GetParent()
|
||||
if IsValid(parent) and parent:GetClass() == "sit_holder" then
|
||||
return veh, parent
|
||||
else
|
||||
return veh
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function PMETA:ExitSit()
|
||||
if CLIENT then
|
||||
if self ~= LocalPlayer() then return end
|
||||
net.Start("SitAnywhere")
|
||||
net.WriteInt(SitAnywhere.NET.SitRequestExit, 4)
|
||||
net.SendToServer()
|
||||
else
|
||||
local seat, holder = self:GetSitting()
|
||||
SafeRemoveEntity(seat)
|
||||
SafeRemoveEntity(holder)
|
||||
if CLIENT then
|
||||
if self ~= LocalPlayer() then return end
|
||||
net.Start("SitAnywhere")
|
||||
net.WriteInt(SitAnywhere.NET.SitRequestExit, 4)
|
||||
net.SendToServer()
|
||||
else
|
||||
local seat, holder = self:GetSitting()
|
||||
SafeRemoveEntity(seat)
|
||||
SafeRemoveEntity(holder)
|
||||
|
||||
if SitAnywhere.GroundSit and self:GetNWBool("SitGroundSitting", false) then
|
||||
self:SetNWBool("SitGroundSitting", false)
|
||||
end
|
||||
end
|
||||
if SitAnywhere.GroundSit and self:GetNWBool("SitGroundSitting", false) then
|
||||
self:SetNWBool("SitGroundSitting", false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function EMETA:IsSitAnywhereSeat()
|
||||
if self:GetClass() ~= "prop_vehicle_prisoner_pod" then return false end
|
||||
if SERVER and self.playerdynseat then return true end
|
||||
return self:GetNWBool("playerdynseat", false)
|
||||
end
|
@ -1,15 +1,15 @@
|
||||
if CLIENT then return end
|
||||
local TAG = "SitAny_"
|
||||
SitAnywhere = SitAnywhere or {}
|
||||
|
||||
--Oh my god I can sit anywhere! by Xerasin--
|
||||
local NextUse = setmetatable({},{__mode = 'k', __index = function() return 0 end})
|
||||
local NextUse = setmetatable({}, {__mode = 'k', __index = function() return 0 end})
|
||||
|
||||
local SittingOnPlayer = CreateConVar("sitting_can_sit_on_players","1",{FCVAR_ARCHIVE})
|
||||
local SittingOnPlayer2 = CreateConVar("sitting_can_sit_on_player_ent","1",{FCVAR_ARCHIVE})
|
||||
local PlayerDamageOnSeats = CreateConVar("sitting_can_damage_players_sitting","0",{FCVAR_ARCHIVE})
|
||||
local AllowWeaponsInSeat = CreateConVar("sitting_allow_weapons_in_seat","0",{FCVAR_ARCHIVE})
|
||||
local AdminOnly = CreateConVar("sitting_admin_only","0",{FCVAR_ARCHIVE})
|
||||
local FixLegBug = CreateConVar("sitting_fix_leg_bug","1",{FCVAR_ARCHIVE})
|
||||
local AntiPropSurf = CreateConVar("sitting_anti_prop_surf","1",{FCVAR_ARCHIVE})
|
||||
local AntiToolAbuse = CreateConVar("sitting_anti_tool_abuse","1",{FCVAR_ARCHIVE})
|
||||
local AllowSittingTightPlaces = CreateConVar("sitting_allow_tight_places","0",{FCVAR_ARCHIVE})
|
||||
@ -37,8 +37,7 @@ net.Receive("SitAnywhere", function(len, ply)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
local function Sit(ply, pos, ang, parent, parentbone, func, exit)
|
||||
local function Sit(ply, pos, ang, parent, parentbone, func, exit)
|
||||
if IsValid(ply:GetVehicle()) then
|
||||
local veh = ply:GetVehicle()
|
||||
if veh:GetClass() == "prop_vehicle_prisoner_pod" and IsValid(veh.holder) then
|
||||
@ -76,14 +75,14 @@ local function Sit(ply, pos, ang, parent, parentbone, func, exit)
|
||||
|
||||
vehicle.playerdynseat = true
|
||||
vehicle:SetNWBool("playerdynseat", true)
|
||||
vehicle.sittingPly = ply
|
||||
vehicle.oldpos = vehicle:WorldToLocal(ply:GetPos())
|
||||
vehicle.oldang = vehicle:WorldToLocalAngles(ply:EyeAngles())
|
||||
vehicle.wasCrouching = ply:Crouching()
|
||||
|
||||
vehicle:SetModel("models/nova/airboat_seat.mdl") -- DO NOT CHANGE OR CRASHES WILL HAPPEN
|
||||
|
||||
vehicle:SetKeyValue("vehiclescript", "scripts/vehicles/prisoner_pod.txt")
|
||||
vehicle:SetKeyValue("limitview","0")
|
||||
vehicle:SetKeyValue("limitview", "0")
|
||||
vehicle:Spawn()
|
||||
vehicle:Activate()
|
||||
|
||||
@ -159,20 +158,11 @@ local function Sit(ply, pos, ang, parent, parentbone, func, exit)
|
||||
ply:CollisionRulesChanged()
|
||||
end
|
||||
|
||||
vehicle.removeonexit = true
|
||||
vehicle.sittingPly = ply
|
||||
if func then
|
||||
func(ply)
|
||||
end
|
||||
|
||||
ply.seatExit = function(exitPly)
|
||||
if PlayerDamageOnSeats:GetBool() then
|
||||
exitPly:SetCollisionGroup(COLLISION_GROUP_PLAYER)
|
||||
exitPly:CollisionRulesChanged()
|
||||
end
|
||||
if exit then exit(exitPly) end
|
||||
end
|
||||
|
||||
ply.seatExit = exit
|
||||
ply:SetEyeAngles(Angle(0,90,0))
|
||||
|
||||
return vehicle
|
||||
@ -186,6 +176,16 @@ local SittingOnPlayerPoses =
|
||||
{
|
||||
Pos = Vector(-33,13,7),
|
||||
Ang = Angle(0,90,90),
|
||||
Func = function(ply)
|
||||
if not ply:LookupBone("ValveBiped.Bip01_R_Thigh") then return end
|
||||
ply:ManipulateBoneAngles(ply:LookupBone("ValveBiped.Bip01_R_Thigh"), Angle(0,90,0))
|
||||
ply:ManipulateBoneAngles(ply:LookupBone("ValveBiped.Bip01_L_Thigh"), Angle(0,90,0))
|
||||
end,
|
||||
OnExitFunc = function(ply)
|
||||
if not ply:LookupBone("ValveBiped.Bip01_R_Thigh") then return end
|
||||
ply:ManipulateBoneAngles(ply:LookupBone("ValveBiped.Bip01_R_Thigh"), Angle(0,0,0))
|
||||
ply:ManipulateBoneAngles(ply:LookupBone("ValveBiped.Bip01_L_Thigh"), Angle(0,0,0))
|
||||
end,
|
||||
FindAng = 90,
|
||||
},
|
||||
{
|
||||
@ -272,7 +272,6 @@ function META.Sit(ply, EyeTrace, ang, parent, parentbone, func, exit, wantedAng)
|
||||
end
|
||||
|
||||
local valid, ent = SitAnywhere.ValidSitTrace(ply, EyeTrace)
|
||||
if ent then return ent end
|
||||
if not valid then return end
|
||||
local surfaceAng = EyeTrace.HitNormal:Angle() + Angle(-270, 0, 0)
|
||||
ang = surfaceAng
|
||||
@ -290,7 +289,6 @@ function META.Sit(ply, EyeTrace, ang, parent, parentbone, func, exit, wantedAng)
|
||||
end
|
||||
|
||||
if SittingOnPlayer:GetBool() then -- Sitting on SITTING Players
|
||||
|
||||
local veh
|
||||
if not EyeTrace.HitWorld and IsValid(EyeTrace.Entity) and EyeTrace.Entity:IsPlayer() and IsValid(EyeTrace.Entity:GetVehicle()) and EyeTrace.Entity:GetVehicle().playerdynseat then
|
||||
local safe = 256
|
||||
@ -357,9 +355,9 @@ function META.Sit(ply, EyeTrace, ang, parent, parentbone, func, exit, wantedAng)
|
||||
|
||||
ent = Sit(ply, vec, ang2, veh, 0, pose.Func, pose.OnExitFunc)
|
||||
|
||||
ent:SetNWVector("SitPosePos", veh:WorldToLocal(ent:GetPos()))
|
||||
--[[ent:SetNWVector("SitPosePos", veh:WorldToLocal(ent:GetPos()))
|
||||
ent:SetNWVector("SitPoseAng", veh:WorldToLocalAngles(ent:GetAngles()))
|
||||
ent:SetNWBool("SitPose", true)
|
||||
ent:SetNWBool("SitPose", true)]]
|
||||
|
||||
if ent and IsValid(ent) then
|
||||
ent.PlayerOnPlayer = true
|
||||
@ -370,7 +368,7 @@ function META.Sit(ply, EyeTrace, ang, parent, parentbone, func, exit, wantedAng)
|
||||
end
|
||||
else
|
||||
for k, v in pairs(ents.FindInSphere(EyeTrace.HitPos, 5)) do
|
||||
if v.removeonexit then
|
||||
if v.playerdynseat then
|
||||
return false
|
||||
end
|
||||
end
|
||||
@ -402,7 +400,6 @@ function META.Sit(ply, EyeTrace, ang, parent, parentbone, func, exit, wantedAng)
|
||||
return vehicle
|
||||
end
|
||||
|
||||
|
||||
if math.abs(surfaceAng.pitch) <= 15 then
|
||||
ang = Angle()
|
||||
local sampleResolution = 24
|
||||
@ -517,18 +514,22 @@ concommand.Add("sit",function(ply, cmd, args)
|
||||
end)
|
||||
|
||||
local function UndoSitting(ply)
|
||||
if IsValid(ply) then
|
||||
local prev = ply.sitting_allowswep
|
||||
if not IsValid(ply) then return end
|
||||
|
||||
if prev ~= nil then
|
||||
ply.sitting_allowswep = nil
|
||||
ply:SetAllowWeaponsInVehicle(prev)
|
||||
end
|
||||
local prev = ply.sitting_allowswep
|
||||
if prev ~= nil then
|
||||
ply.sitting_allowswep = nil
|
||||
ply:SetAllowWeaponsInVehicle(prev)
|
||||
end
|
||||
|
||||
if ply.seatExit then
|
||||
ply.seatExit(ply)
|
||||
ply.seatExit = nil
|
||||
end
|
||||
if PlayerDamageOnSeats:GetBool() then
|
||||
ply:SetCollisionGroup(COLLISION_GROUP_PLAYER)
|
||||
ply:CollisionRulesChanged()
|
||||
end
|
||||
|
||||
if ply.seatExit then
|
||||
ply.seatExit(ply)
|
||||
ply.seatExit = nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -598,32 +599,36 @@ hook.Add("CanTool", TAG .. "CanTool", function(ply, tr)
|
||||
end
|
||||
end)
|
||||
|
||||
local checked = {}
|
||||
hook.Add("CanExitVehicle", TAG .. "CanExitVehicle", function(self, ply)
|
||||
if not IsValid(self) or not IsValid(ply) then return end
|
||||
if not self.playerdynseat then return end
|
||||
|
||||
hook.Add("CanExitVehicle", TAG .. "CanExitVehicle", function(seat, ply)
|
||||
if not IsValid(seat) or not IsValid(ply) then return end
|
||||
if not seat.playerdynseat then return end
|
||||
|
||||
if CurTime() < NextUse[ply] then return false end
|
||||
end)
|
||||
|
||||
hook.Add("PlayerLeaveVehicle", TAG .. "PlayerLeaveVehicle", function(ply, seat)
|
||||
if not IsValid(seat) or not IsValid(ply) then return end
|
||||
if not seat.playerdynseat then return end
|
||||
|
||||
NextUse[ply] = CurTime() + 1
|
||||
|
||||
if checked[self] then return end
|
||||
checked[self] = true
|
||||
local oldpos = self:LocalToWorld(self.oldpos), self:LocalToWorldAngles(self.oldang)
|
||||
local oldpos = seat:LocalToWorld(seat.oldpos)
|
||||
|
||||
if IsValid(self) then
|
||||
SafeRemoveEntity(self)
|
||||
ply:SetPos(oldpos)
|
||||
if ply.UnStuck then
|
||||
ply:UnStuck()
|
||||
end
|
||||
|
||||
timer.Create("SitThe_" .. ply:EntIndex(), 0, 1, function()
|
||||
ply:SetPos(oldpos)
|
||||
timer.Create("FDown_" .. ply:EntIndex(), 1, 1, function()
|
||||
if ply.UnStuck then
|
||||
ply:UnStuck()
|
||||
end
|
||||
UndoSitting(ply)
|
||||
end)
|
||||
end)
|
||||
|
||||
for _, v in next, seat:GetChildren() do
|
||||
if IsValid(v) and v.playerdynseat and IsValid(v.sittingPly) then
|
||||
v.sittingPly:ExitVehicle()
|
||||
end
|
||||
end
|
||||
|
||||
SafeRemoveEntityDelayed(seat, 1)
|
||||
UndoSitting(ply)
|
||||
end)
|
||||
|
||||
hook.Add("AllowPlayerPickup", TAG .. "AllowPlayerPickup", function(ply)
|
||||
@ -639,47 +644,42 @@ hook.Add("PlayerDeath", TAG .. "PlayerDeath", function(pl)
|
||||
end
|
||||
|
||||
for k, v in next, pl:GetChildren() do
|
||||
if IsValid(v) and v.playerdynseat then
|
||||
SafeRemoveEntity(v)
|
||||
if IsValid(v) and v.playerdynseat and IsValid(v.sittingPly) then
|
||||
v.sittingPly:ExitVehicle()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
hook.Add("PlayerEnteredVehicle", TAG .. "PlayerEnteredVehicle",function(pl, veh)
|
||||
for k,v in next, pl:GetChildren() do
|
||||
if IsValid(v) and v.playerdynseat then
|
||||
if IsValid(v.sittingPly) then
|
||||
v.sittingPly:ExitVehicle()
|
||||
end
|
||||
SafeRemoveEntity(v)
|
||||
if IsValid(v) and v.playerdynseat and IsValid(v.sittingPly) then
|
||||
v.sittingPly:ExitVehicle()
|
||||
end
|
||||
end
|
||||
|
||||
DropEntityIfHeld( veh )
|
||||
|
||||
if veh:GetParent():IsValid() then
|
||||
DropEntityIfHeld( veh:GetParent() )
|
||||
local parent = veh:GetParent()
|
||||
if IsValid(parent) then
|
||||
DropEntityIfHeld(parent)
|
||||
end
|
||||
end)
|
||||
|
||||
hook.Add("EntityRemoved", TAG .. "EntityRemoved", function(ent)
|
||||
if FixLegBug:GetBool() and ent.playerdynseat and IsValid(ent.sittingPly) then
|
||||
if ent.playerdynseat and IsValid(ent.sittingPly) then
|
||||
UndoSitting(ent.sittingPly)
|
||||
end
|
||||
|
||||
for k,v in next, ent:GetChildren() do
|
||||
if v.playerdynseat then
|
||||
if IsValid(v.sittingPly) then
|
||||
v.sittingPly:ExitVehicle()
|
||||
end
|
||||
SafeRemoveEntity(v)
|
||||
for _, v in next, ent:GetChildren() do
|
||||
if IsValid(v) and v.playerdynseat and IsValid(v.sittingPly) then
|
||||
v.sittingPly:ExitVehicle()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
timer.Create(TAG .. "RemoveSeats", 15, 0, function()
|
||||
for k,v in pairs(ents.FindByClass("prop_vehicle_prisoner_pod")) do
|
||||
if v.removeonexit and (not IsValid(v.sittingPly) or v:GetDriver() == nil or not v:GetDriver():IsValid() or v:GetDriver():GetVehicle() ~= v --[[???]]) then
|
||||
if v.playerdynseat and (not IsValid(v.sittingPly) or v:GetDriver() == nil or not v:GetDriver():IsValid() or v:GetDriver():GetVehicle() ~= v --[[???]]) then
|
||||
v:Remove()
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user