Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera Controller Vehicles input (Pod's Vehicle like) #3120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions lua/entities/gmod_wire_cameracontroller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
local enabled = false
local self

local clientprop

Check warning on line 48 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: clientprop

-- Position
local pos = Vector(0,0,0)
Expand All @@ -53,8 +53,8 @@

-- Distance & zooming
local distance = 0
local curdistance = 0

Check warning on line 56 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: curdistance
local oldcurdistance = 0

Check warning on line 57 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: oldcurdistance
local smoothdistance = 0

local zoomdistance = 0
Expand All @@ -64,11 +64,11 @@
local ang = Angle(0,0,0)
local smoothang = Angle(0,0,0)

local oldeyeang = Angle(0,0,0)

Check warning on line 67 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: oldeyeang
local unroll = false

-- Options
local ParentLocal = false

Check warning on line 71 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: ParentLocal
local AutoMove = false
local FreeMove = false
local LocalMove = false
Expand Down Expand Up @@ -114,7 +114,7 @@
local tr = {
start = start,
endpos = endpos,
mask = (AutoUnclip_IgnoreWater and CONTENTS_SOLID or bit.bor(MASK_WATER, CONTENTS_SOLID)),

Check warning on line 117 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
mins = Vector(-8,-8,-8),
maxs = Vector(8,8,8)
}
Expand Down Expand Up @@ -150,7 +150,7 @@
smoothpos = LerpVector( FrameTime() * pos_speed, smoothpos, curpos )

local pos_speed = pos_speed_convar:GetFloat()
local ang_speed = pos_speed - 2

Check warning on line 153 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: ang_speed

if AllowZoom then
if zoombind ~= 0 then
Expand Down Expand Up @@ -378,7 +378,8 @@
"Parent (Parents the camera to this entity.) [ENTITY]",
"FilterEntities (In addition to ignoring the contraption of the 'Parent' entity, or the cam controller itself\nif parent isn't used, entities in this list will be ignored by the 'HitPos' and 'Trace' outputs) [ARRAY]",
"FLIR",
"FOV"
"FOV",
"Vehicles (Links all vehicles of passed array to this cam controller) [ARRAY]",
})

self.Activated = false -- Whether or not to activate the cam controller for all players sitting in linked vehicles, or as soon as a player sits in a linked vehicle
Expand Down Expand Up @@ -429,7 +430,7 @@
-- Setup
--------------------------------------------------

function ENT:Setup(ParentLocal,AutoMove,FreeMove,LocalMove,AllowZoom,AutoUnclip,DrawPlayer,AutoUnclip_IgnoreWater,DrawParent)
function ENT:Setup(ParentLocal,AutoMove,FreeMove,LocalMove,AllowZoom,AutoUnclip,DrawPlayer,AutoUnclip_IgnoreWater,DrawParent,Vehicles)
self.ParentLocal = tobool(ParentLocal)
self.AutoMove = tobool(AutoMove)
self.FreeMove = tobool(FreeMove)
Expand All @@ -440,6 +441,14 @@
self.DrawPlayer = tobool(DrawPlayer)
self.DrawParent = tobool(DrawParent)

if Vehicles then
for k,v in ipairs( Vehicles ) do
if( TypeID(v) ~= TYPE_ENTITY ) then continue end
if( not IsValid(v) ) then continue end
self:LinkEnt( v )
end
end

self:UpdateOverlay()
end

Expand Down Expand Up @@ -569,7 +578,7 @@
local tr = {
start = start,
endpos = endpos,
mask = (self.AutoUnclip_IgnoreWater and CONTENTS_SOLID or bit.bor(MASK_WATER, CONTENTS_SOLID)),

Check warning on line 581 in lua/entities/gmod_wire_cameracontroller.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
mins = Vector(-8,-8,-8),
maxs = Vector(8,8,8)
}
Expand Down Expand Up @@ -838,6 +847,13 @@
self.FLIR = value ~= 0
if not self.Activated then return end
self:SetFLIR()
elseif name == "Vehicles" then
self:ClearEntities()
for k, v in ipairs( value ) do
if( TypeID(v) ~= TYPE_ENTITY ) then continue end
if( not IsValid(v) ) then continue end
self:LinkEnt( v )
end
else
self:LocalizePositions(false)

Expand Down Expand Up @@ -1096,4 +1112,4 @@
WireLib.AddInputAlias( "Zoom", "FOV" )
WireLib.AddOutputAlias( "XYZ", "HitPos" )

duplicator.RegisterEntityClass("gmod_wire_cameracontroller", WireLib.MakeWireEnt, "Data", "ParentLocal","AutoMove","FreeMove","LocalMove","AllowZoom","AutoUnclip","DrawPlayer","AutoUnclip_IgnoreWater","DrawParent")
duplicator.RegisterEntityClass("gmod_wire_cameracontroller", WireLib.MakeWireEnt, "Data", "ParentLocal","AutoMove","FreeMove","LocalMove","AllowZoom","AutoUnclip","DrawPlayer","AutoUnclip_IgnoreWater","DrawParent","Vehicles")
30 changes: 21 additions & 9 deletions lua/wire/server/sents_registry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -985,16 +985,28 @@ register("gmod_wire_locator", {
})

register("gmod_wire_cameracontroller", {
_preFactory = function(ply, self)
-- Verifies that all entities are valid, all entities are vehicles, and that passed table is an array
local i = 0
for _ in pairs(self.Vehicles) do
i = i + 1
if self.Vehicles[i] == nil then return "Vehicles parameter must be of type array!" end
if TypeID(self.Vehicles[i]) ~= TYPE_ENTITY then return "Vehicles parameter must consist only of entities" end
if not self.Vehicles[i]:IsVehicle() then return "Vehicles parameter must consist only of vehicles" end
end
end,

["Model"] = {TYPE_STRING, "models/jaanus/wiretool/wiretool_siren.mdl", "Path to model"},
["ParentLocal"] = {TYPE_BOOL, false},
["AutoMove"] = {TYPE_BOOL, false},
["FreeMove"] = {TYPE_BOOL, false},
["LocalMove"] = {TYPE_BOOL, false},
["AllowZoom"] = {TYPE_BOOL, false},
["AutoUnclip"] = {TYPE_BOOL, false},
["DrawPlayer"] = {TYPE_BOOL, true},
["AutoUnclip_IgnoreWater"] = {TYPE_BOOL, false},
["DrawParent"] = {TYPE_BOOL, true},
["ParentLocal"] = {TYPE_BOOL, false, "Should the coordinates be local to the parent?"},
["AutoMove"] = {TYPE_BOOL, false, "Allow the player to rotate camera using their mouse? (Coordinaets becomes center of orbit)"},
["FreeMove"] = {TYPE_BOOL, false, "Allow 360 rotation? The 'UnRoll' input can be toggled to match the parent entity's roll. (NOTE: Only used if 'AutoMove' is enabled)"},
["LocalMove"] = {TYPE_BOOL, false, "Is client movement local to parent? (NOTE: Only used if 'AutoMove' is enabled)"},
["AllowZoom"] = {TYPE_BOOL, false, "Allow user to move camera in and out using mouse scroller? (NOTE: Only used if 'AutoMove' is enabled. NOTE: Some outputs may become wrong)"},
["AutoUnclip"] = {TYPE_BOOL, false, "Prevent the camera from clipping into world? (By moving it closer)"},
["DrawPlayer"] = {TYPE_BOOL, true, "Should user be able to see himself?"},
["AutoUnclip_IgnoreWater"] = {TYPE_BOOL, false, "Should camera clip into water? (NOTE: Only used if 'AutoUnclip' is enabled)"},
["DrawParent"] = {TYPE_BOOL, true, "Should the parent of camera be rendered?"},
["Vehicles"] = {TYPE_TABLE, {}, "Autolink cameras to array of vehicles/seats"}
})

register("gmod_wire_dual_input", {
Expand Down
Loading