@@ -41,6 +41,68 @@ do -- Random timer crew stuff
4141 end
4242end
4343
44+ --- Configures a lua seat generated by the crew entity
45+ --- Called when first creating the seat, or when reusing it from a dupe
46+ local function ConfigureLuaSeat (Entity , Pod )
47+ Entity .AlreadyHasSeat = true
48+
49+ Entity :SetUseType (SIMPLE_USE )
50+ Entity .Pod = Pod
51+
52+ local Found = constraint .Find ( Entity , Pod , " NoCollide" , 0 , 0 )
53+ if not Found then print (" Creating NoCollide" , constraint .NoCollide (Entity , Pod , 0 , 0 ), Entity , Pod ) else print (" Found NoCollide" , Found ) end
54+
55+ hook .Add (" PlayerEnteredVehicle" , " ACFBaseplateSeatEnter" .. Entity :EntIndex (), function (Ply , Veh )
56+ if Veh == Pod then
57+ -- Ply:GodEnable() -- Remove this if aliases are removed?
58+ Ply :SetNoDraw (true )
59+ end
60+ end )
61+
62+ -- Make the player visible and vulnerable when they leave the seat
63+ hook .Add (" PlayerLeaveVehicle" , " ACFBaseplateSeatExit" .. Entity :EntIndex (), function (Ply , Veh )
64+ if Veh == Pod then
65+ -- Ply:GodDisable() -- Remove this if aliases are removed?
66+ Ply :SetNoDraw (false )
67+ end
68+ end )
69+
70+ -- Allow players to enter the seat externally by pressing use on a prop on the same contraption as the baseplate
71+ hook .Add (" PlayerUse" , " ACFBaseplateSeatEnterExternal" .. Entity :EntIndex (), function (Ply , Ent )
72+ if not Ply :KeyDown (IN_SPEED ) then return end
73+ if IsValid (Ent ) then
74+ local Contraption = Ent :GetContraption ()
75+ if Contraption then
76+ local Base = Contraption .Base
77+ if Base == Entity and Pod :GetDriver () ~= Ply then
78+ Ply :EnterVehicle (Pod )
79+ end
80+ end
81+ end
82+ end )
83+
84+ -- Cleanup hooks and stuff when the baseplate is removed
85+ Entity :CallOnRemove (" ACF_RemoveVehiclePod" , function (Ent )
86+ hook .Remove (" PlayerEnteredVehicle" , " ACFBaseplateSeatEnter" .. Entity :EntIndex ())
87+ hook .Remove (" PlayerLeaveVehicle" , " ACFBaseplateSeatExit" .. Entity :EntIndex ())
88+ hook .Remove ( " PlayerUse" , " ACFBaseplateSeatEnterExternal" .. Entity :EntIndex ())
89+
90+ local Owner = Entity :CPPIGetOwner ()
91+ if IsValid (Owner ) then Owner :GodDisable () end
92+
93+ SafeRemoveEntity (Ent .Pod )
94+
95+ if Entity .Crews and next (Entity .Crews ) then
96+ for Crew in pairs (Entity .Crews ) do
97+ if IsValid (Crew ) then Entity :Unlink (Crew ) end
98+ end
99+ end
100+ end )
101+
102+ WireLib .TriggerOutput (Entity , " Vehicles" , {Pod })
103+ end
104+
105+
44106-- Might be a good idea to put this somewhere else later
45107ACF .ActiveBaseplatesTable = ACF .ActiveBaseplatesTable or {}
46108
@@ -71,77 +133,10 @@ function ENT:ACF_PostSpawn(_, _, _, ClientData)
71133 WireLib .TriggerOutput (self , " Entity" , self )
72134
73135 -- Add seat support for baseplates
74- local Pod = ents .Create (" prop_vehicle_prisoner_pod" )
75136 local Owner = self :CPPIGetOwner ()
76- if IsValid (Pod ) and IsValid (Owner ) then
77- self :SetUseType (SIMPLE_USE ) -- Avoid running activator function constantly...
78- self .Pod = Pod
79- Pod :SetAngles (self :GetAngles ())
80- Pod :SetModel (" models/vehicles/pilot_seat.mdl" )
81- Pod :SetPos (self :GetPos ())
82- Pod :Spawn ()
83- Pod :SetParent (self )
84- Pod .Owner = Owner
85- Pod :SetKeyValue (" vehiclescript" , " scripts/vehicles/prisoner_pod.txt" ) -- I don't know what this does, but for good measure...
86- Pod :SetKeyValue (" limitview" , 0 ) -- Let the player look around
87- Pod :SetNoDraw (true ) -- Don't render the seat
88- Pod :SetMoveType (MOVETYPE_NONE )
89- Pod :SetCollisionGroup (COLLISION_GROUP_IN_VEHICLE )
90- Pod .Vehicle = self
91- Pod .ACF = Pod .ACF or {}
92- Pod .ACF .LegalSeat = true
93- Pod .DoNotDuplicate = true -- Don't duplicate cause baseplate will generate one on spawn
94- Pod .ACF_InvisibleToBallistics = true -- Baseplate seat
95-
96- -- Make the player invisible and invincible while in the seat
97- hook .Add (" PlayerEnteredVehicle" , " ACFBaseplateSeatEnter" .. self :EntIndex (), function (Ply , Veh )
98- if Veh == Pod then
99- -- Ply:GodEnable() -- Remove this if aliases are removed?
100- Ply :SetNoDraw (true )
101- end
102- end )
103-
104- -- Make the player visible and vulnerable when they leave the seat
105- hook .Add (" PlayerLeaveVehicle" , " ACFBaseplateSeatExit" .. self :EntIndex (), function (Ply , Veh )
106- if Veh == Pod then
107- -- Ply:GodDisable() -- Remove this if aliases are removed?
108- Ply :SetNoDraw (false )
109- end
110- end )
111-
112- -- Allow players to enter the seat externally by pressing use on a prop on the same contraption as the baseplate
113- hook .Add (" PlayerUse" , " ACFBaseplateSeatEnterExternal" .. self :EntIndex (), function (Ply , Ent )
114- if not Ply :KeyDown (IN_SPEED ) then return end
115- if IsValid (Ent ) then
116- local Contraption = Ent :GetContraption ()
117- if Contraption then
118- local Base = Contraption .Base
119- if Base == self and Pod :GetDriver () ~= Ply then
120- Ply :EnterVehicle (Pod )
121- end
122- end
123- end
124- end )
125-
126- -- Cleanup hooks and stuff when the baseplate is removed
127- self :CallOnRemove (" ACF_RemoveVehiclePod" , function (Ent )
128- hook .Remove (" PlayerEnteredVehicle" , " ACFBaseplateSeatEnter" .. self :EntIndex ())
129- hook .Remove (" PlayerLeaveVehicle" , " ACFBaseplateSeatExit" .. self :EntIndex ())
130- hook .Remove ( " PlayerUse" , " ACFBaseplateSeatEnterExternal" .. self :EntIndex ())
131-
132- local Owner = self :CPPIGetOwner ()
133- if IsValid (Owner ) then Owner :GodDisable () end
134-
135- SafeRemoveEntity (Ent .Pod )
136-
137- if self .Crews and next (self .Crews ) then
138- for Crew in pairs (self .Crews ) do
139- if IsValid (Crew ) then self :Unlink (Crew ) end
140- end
141- end
142- end )
143-
144- WireLib .TriggerOutput (self , " Vehicles" , {Pod })
137+ if not self .AlreadyHasSeat then
138+ local Pod = ACF .GenerateLuaSeat (self , Owner , self :GetPos (), self :GetAngles (), self :GetModel (), true )
139+ if IsValid (Pod ) then ConfigureLuaSeat (self , Pod ) end
145140 end
146141
147142 ACF .AugmentedTimer (function (cfg ) self :UpdateAccuracyMod (cfg ) end , function () return IsValid (self ) end , nil , {MinTime = 0.5 , MaxTime = 1 })
@@ -156,7 +151,7 @@ function ENT:Use(Activator)
156151end
157152
158153do
159- -- Maintain a record in the contraption of its current crew
154+ -- Maintain a record in the contraption of its current baseplate
160155 hook .Add (" cfw.contraption.entityAdded" , " ACF_CFWBaseIndex" , function (contraption , ent )
161156 if ent :GetClass () == " acf_baseplate" then
162157 contraption .Base = ent
0 commit comments