@@ -4,6 +4,7 @@ include( "shared.lua" )
44DEFINE_BASECLASS ( " base_streamradio_gui" )
55
66local StreamRadioLib = StreamRadioLib
7+ local LIBPrint = StreamRadioLib .Print
78local LIBError = StreamRadioLib .Error
89local LIBWire = StreamRadioLib .Wire
910local LIBUtil = StreamRadioLib .Util
@@ -208,25 +209,49 @@ function ENT:OnTakeDamage( dmg )
208209 self :TakePhysicsDamage ( dmg )
209210end
210211
211- function ENT :OnReloaded ( )
212- if not IsValid ( self ) then return end
212+ function ENT :OnReloaded ()
213+ if not IsValid (self ) then return end
213214 if not g_isLoaded then return end
214215
215- local ply , model , pos , ang = self :GetRealRadioOwner (), self :GetModel ( ), self :GetPos ( ), self :GetAngles ( )
216- StreamRadioLib .Print .Msg (ply , " Reloaded %s" , tostring (self ))
217- self :Remove ( )
218-
219- StreamRadioLib .Timedcall ( function ( ply , model , pos , ang )
220- local ent = StreamRadioLib .SpawnRadio ( ply , model , pos , ang )
221- if ( not IsValid ( ent ) ) then return end
222- if ( not IsValid ( ply ) ) then return end
223- local TOOL_Class = " streamradio"
224- undo .Create ( TOOL_Class )
225- undo .AddEntity ( ent )
226- undo .SetPlayer ( ply )
227- undo .Finish ( )
228- ply :AddCleanup ( TOOL_Class , ent )
229- end , ply , model , pos , ang )
216+ local ply = self :GetRealRadioOwner ()
217+ local model = self :GetModel ()
218+ local pos = self :GetPos ()
219+ local ang = self :GetAngles ()
220+ local radioName = LIBPrint .GetRadioEntityString (self )
221+
222+ local motion = false
223+
224+ local selfPhys = self :GetPhysicsObject ()
225+ if IsValid (selfPhys ) then
226+ motion = selfPhys :IsMotionEnabled ()
227+ end
228+
229+ self :Remove ()
230+
231+ StreamRadioLib .Timedcall (function (ply , model , pos , ang )
232+ local ent = StreamRadioLib .SpawnRadio (ply , model , pos , ang )
233+ if not IsValid (ent ) then
234+ return
235+ end
236+
237+ local entPhys = ent :GetPhysicsObject ()
238+ if IsValid (entPhys ) then
239+ entPhys :EnableMotion (motion )
240+ end
241+
242+ LIBPrint .Msg (ply , " %s respawned after reload." , radioName )
243+
244+ if IsValid (ply ) then
245+ local TOOL_Class = " streamradio"
246+
247+ undo .Create (TOOL_Class )
248+ undo .AddEntity (ent )
249+ undo .SetPlayer (ply )
250+ undo .Finish ()
251+
252+ ply :AddCleanup (TOOL_Class , ent )
253+ end
254+ end , ply , model , pos , ang )
230255end
231256
232257function ENT :UpdateVolume ()
0 commit comments