|
1 | 1 | addonName = "Dynamic Light Controller - Entities"
|
| 2 | +import IsValid, GetClass from FindMetaTable( "Entity" ) |
2 | 3 | PRE_HOOK = PRE_HOOK or HOOK_MONITOR_HIGH
|
3 | 4 | CreateClientConVar = CreateClientConVar
|
4 | 5 | entities = list.GetForEdit( addonName )
|
5 |
| -:GetClass = FindMetaTable( "Entity" ) |
6 | 6 | import CreateClientside from ents
|
| 7 | +import TraceLine from util |
| 8 | +import Simple from timer |
7 | 9 | import Add from hook
|
8 | 10 |
|
| 11 | +traceResult = {} |
| 12 | +trace = { output: traceResult } |
| 13 | + |
9 | 14 | blacklist = {}
|
10 | 15 |
|
11 | 16 | do
|
|
33 | 38 | Add( "NotifyShouldTransmit", addonName, ( entity, shouldtransmit ) ->
|
34 | 39 | if shouldtransmit and dlight_controllers_entities\GetBool! and not entity.DLightController
|
35 | 40 | dlight = entity.__dlight
|
36 |
| - if dlight and dlight\IsValid! |
| 41 | + if dlight and IsValid( dlight ) |
37 | 42 | return
|
38 | 43 |
|
39 | 44 | className = GetClass( entity )
|
|
45 | 50 | return
|
46 | 51 |
|
47 | 52 | dlight = CreateClientside( "dlight_controller" )
|
| 53 | + unless dlight and IsValid( dlight ) |
| 54 | + return |
| 55 | + |
48 | 56 | dlight\SetEnabled( true )
|
49 | 57 |
|
50 | 58 | if func( entity, dlight ) == false
|
|
56 | 64 | return
|
57 | 65 |
|
58 | 66 | dlight = entity.__dlight
|
59 |
| - if dlight and dlight\IsValid! |
| 67 | + if dlight and IsValid( dlight ) |
60 | 68 | dlight\Remove!
|
61 | 69 |
|
62 | 70 | PRE_HOOK )
|
|
66 | 74 | return
|
67 | 75 |
|
68 | 76 | dlight = entity.__dlight
|
69 |
| - if dlight and dlight\IsValid! |
| 77 | + if dlight and IsValid( dlight ) |
70 | 78 | return
|
71 | 79 |
|
72 | 80 | className = GetClass( entity )
|
|
78 | 86 | return
|
79 | 87 |
|
80 | 88 | dlight = CreateClientside( "dlight_controller" )
|
| 89 | + unless dlight and IsValid( dlight ) |
| 90 | + return |
| 91 | + |
81 | 92 | dlight\SetEnabled( true )
|
82 | 93 |
|
83 | 94 | if func( entity, dlight ) == false
|
|
95 | 106 | return
|
96 | 107 |
|
97 | 108 | dlight = entity.__dlight
|
98 |
| - if dlight and dlight\IsValid! |
| 109 | + if dlight and IsValid( dlight ) |
99 | 110 | dlight\Remove!
|
100 | 111 |
|
101 |
| - unless dlight_controllers_entities\GetBool! |
| 112 | + bdlight = entity.__beam_dlight |
| 113 | + if bdlight and IsValid( dlight ) |
| 114 | + bdlight\Remove! |
| 115 | + |
| 116 | + unless dlight_controllers_entities\GetBool! and IsValid( entity ) |
102 | 117 | return
|
103 | 118 |
|
104 | 119 | className = GetClass( entity )
|
|
110 | 125 | return
|
111 | 126 |
|
112 | 127 | dlight = CreateClientside( "dlight_controller" )
|
| 128 | + unless dlight and IsValid( dlight ) |
| 129 | + return |
| 130 | + |
113 | 131 | dlight\SetEnabled( true )
|
114 | 132 |
|
115 | 133 | if func( entity, dlight ) == false
|
|
125 | 143 | Add( "EntityRemoved", addonName, ( entity, fullUpdate ) ->
|
126 | 144 | dlight = entity.__dlight
|
127 | 145 | if dlight
|
128 |
| - if dlight\IsValid! |
| 146 | + if IsValid( dlight ) |
129 | 147 | dlight\Remove!
|
130 | 148 |
|
131 | 149 | entity.__dlight = nil
|
132 | 150 |
|
133 | 151 | dlight = entity.m_eFireDLight
|
134 | 152 | if dlight
|
135 |
| - if dlight\IsValid! |
| 153 | + if IsValid( dlight ) |
136 | 154 | dlight\Remove!
|
137 | 155 |
|
138 | 156 | entity.m_eFireDLight = nil
|
139 | 157 |
|
| 158 | + if entity\IsPlayer! |
| 159 | + dlight = entity.__beam_dlight |
| 160 | + if dlight |
| 161 | + if IsValid( dlight ) |
| 162 | + dlight\Remove! |
| 163 | + |
| 164 | + entity.__beam_dlight = nil |
| 165 | + |
140 | 166 | PRE_HOOK )
|
141 | 167 |
|
| 168 | +do |
| 169 | + |
| 170 | + physgun_maxrange = GetConVar( "physgun_maxrange" ) |
| 171 | + |
| 172 | + Add "DrawPhysgunBeam", addonName .. " - Physgun", ( ply, wep, enabled, entity, physBone, localPos ) -> |
| 173 | + bdlight = wep.__beam_dlight |
| 174 | + unless bdlight and IsValid( bdlight ) |
| 175 | + return |
| 176 | + |
| 177 | + bdlight\SetEnabled( enabled ) |
| 178 | + |
| 179 | + unless enabled |
| 180 | + return |
| 181 | + |
| 182 | + bdlight\SetLightColor( ply\GetWeaponColor! ) |
| 183 | + |
| 184 | + unless IsValid( entity ) |
| 185 | + trace.start = ply\GetShootPos! |
| 186 | + trace.endpos = trace.start + ply\GetAimVector! * physgun_maxrange\GetInt! |
| 187 | + trace.filter = ply |
| 188 | + TraceLine( trace ) |
| 189 | + |
| 190 | + bdlight\SetPos( traceResult.HitPos + traceResult.HitNormal ) |
| 191 | + return |
| 192 | + |
| 193 | + if physBone ~= 0 |
| 194 | + matrix = entity\GetBoneMatrix( entity\TranslatePhysBoneToBone( physBone ) ) |
| 195 | + if matrix |
| 196 | + bdlight\SetPos( LocalToWorld( localPos, angle_zero, matrix\GetTranslation!, matrix\GetAngles! ) ) |
| 197 | + return |
| 198 | + |
| 199 | + bdlight\SetPos( entity\LocalToWorld( localPos ) ) |
| 200 | + return |
| 201 | + |
142 | 202 | do
|
143 | 203 |
|
144 | 204 | dlight_controllers_env_fire = CreateClientConVar( "dlight_controllers_env_fire", "0", true, false, "Enables creation dynamic light emitters for env_fire.", 0, 1 )
|
|
156 | 216 | dlight\SetStyle( 5 )
|
157 | 217 |
|
158 | 218 | dlight.LightThink = ->
|
159 |
| - if entity\IsValid! |
| 219 | + if IsValid( entity ) |
160 | 220 | dlight\SetPos( entity\GetPos! )
|
161 | 221 |
|
162 | 222 | return true
|
|
297 | 357 | dlight\SetLocalPos( entity\OBBCenter! )
|
298 | 358 |
|
299 | 359 | dlight.LightThink = ->
|
300 |
| - unless entity\IsValid! |
| 360 | + unless IsValid( entity ) |
301 | 361 | dlight\Remove!
|
302 | 362 | return
|
303 | 363 |
|
|
308 | 368 |
|
309 | 369 | entities[ "env_sprite" ] = ( entity, dlight ) ->
|
310 | 370 | parent = entity\GetParent!
|
311 |
| - unless parent and parent\IsValid! |
| 371 | + unless parent and IsValid( parent ) |
312 | 372 | return false
|
313 | 373 |
|
314 | 374 | old = parent.__dlight
|
315 |
| - if old and old\IsValid! |
| 375 | + if old and IsValid( old ) |
316 | 376 | old\Remove!
|
317 | 377 |
|
318 | 378 | parent.__dlight = dlight
|
|
372 | 432 | dlight_controllers_bullets_radius = CreateClientConVar( "dlight_controllers_bullets_radius", "64", true, false, "", 16, 4096 )
|
373 | 433 | dlight_controllers_bullets_color = CreateClientConVar( "dlight_controllers_bullets_color", "255 100 0", true, false, "" )
|
374 | 434 |
|
375 |
| - r, g, b = unpack( string.Split( dlight_controllers_bullets_color\GetString!, " " ) ) |
| 435 | + r, g, b = unpack( string.Split( dlight_controllers_bullets_color\GetString!, " " ), nil ) |
376 | 436 | cvars.AddChangeCallback( dlight_controllers_bullets_color\GetName!, ( _, __, value ) ->
|
377 |
| - r, g, b = unpack( string.Split( value, " " ) ) |
| 437 | + r, g, b = unpack( string.Split( value, " " ), nil ) |
378 | 438 | addonName )
|
379 | 439 |
|
380 | 440 | Add( "EntityFireBullets", addonName, ( data ) =>
|
381 | 441 | unless dlight_controllers_bullets\GetBool!
|
382 | 442 | return
|
383 | 443 |
|
384 |
| - unless r and g and b |
385 |
| - r, g, b = 255, 100, 0 |
| 444 | + Simple 0, -> |
| 445 | + trace.start = data.Src |
| 446 | + trace.endpos = data.Src + data.Dir * data.Distance |
| 447 | + trace.filter = data.Entity |
| 448 | + TraceLine( trace ) |
| 449 | + |
| 450 | + dlight = CreateClientside( "dlight_controller" ) |
| 451 | + unless dlight and IsValid( dlight ) |
| 452 | + return |
| 453 | + |
| 454 | + dlight\SetLifetime( dlight_controllers_bullets_lifetime\GetFloat! ) |
| 455 | + dlight\SetPos( traceResult.HitPos + traceResult.HitNormal * 2 ) |
| 456 | + dlight\SetLightColor( r or 255, g or 100, b or 0 ) |
| 457 | + dlight\SetParent( traceResult.Entity ) |
| 458 | + dlight\SetBrightness( 0.1 ) |
| 459 | + dlight\SetEnabled( true ) |
| 460 | + dlight\SetRadius( 16 ) |
| 461 | + dlight\Spawn! |
| 462 | + return |
386 | 463 |
|
387 | 464 | dlight = CreateClientside( "dlight_controller" )
|
| 465 | + unless dlight and IsValid( dlight ) |
| 466 | + return |
| 467 | + |
388 | 468 | dlight\SetBrightness( dlight_controllers_bullets_brightness\GetFloat! )
|
389 | 469 | dlight\SetLifetime( dlight_controllers_bullets_lifetime\GetFloat! )
|
390 | 470 | dlight\SetRadius( dlight_controllers_bullets_radius\GetInt! )
|
391 |
| - dlight\SetLightColor( r, g, b ) |
| 471 | + dlight\SetLightColor( r or 255, g or 100, b or 0 ) |
392 | 472 | dlight\SetEnabled( true )
|
393 | 473 | dlight\SetPos( data.Src )
|
394 | 474 | dlight\SetParent( @ )
|
|
405 | 485 | for _, entity in Iterator!
|
406 | 486 | if entity\IsOnFire!
|
407 | 487 | dlight = entity.m_eFireDLight
|
408 |
| - if dlight and dlight\IsValid! |
| 488 | + if dlight and IsValid( dlight ) |
409 | 489 | continue
|
410 | 490 |
|
411 | 491 | dlight = CreateClientside( "dlight_controller" )
|
| 492 | + unless dlight and IsValid( dlight ) |
| 493 | + return |
| 494 | + |
412 | 495 | entity.m_eFireDLight = dlight
|
413 | 496 |
|
414 | 497 | dlight\SetStyle( 5 )
|
|
423 | 506 |
|
424 | 507 | dlight = entity.m_eFireDLight
|
425 | 508 | if dlight
|
426 |
| - if dlight\IsValid! |
| 509 | + if IsValid( dlight ) |
427 | 510 | dlight\Remove!
|
428 | 511 |
|
429 | 512 | dlight.m_eFireDLight = nil
|
|
446 | 529 | return
|
447 | 530 |
|
448 | 531 | dlight = CreateClientside( "dlight_controller" )
|
| 532 | + unless dlight and IsValid( dlight ) |
| 533 | + return |
| 534 | + |
449 | 535 | dlight\SetBrightness( dlight_controllers_explosions_brightness\GetFloat! )
|
450 | 536 | dlight\SetLifetime( dlight_controllers_explosions_lifetime\GetFloat! )
|
451 | 537 | dlight\SetRadius( dlight_controllers_explosions_radius\GetInt! )
|
|
465 | 551 | attachmentID = 0
|
466 | 552 |
|
467 | 553 | entities[ "weapon_physgun" ] = ( entity, dlight ) ->
|
| 554 | + bdlight = CreateClientside( "dlight_controller" ) |
| 555 | + entity.__beam_dlight = bdlight |
| 556 | + bdlight\SetBrightness( 0.01 ) |
| 557 | + bdlight\SetRadius( 128 ) |
| 558 | + bdlight\SetStyle( 5 ) |
| 559 | + bdlight\Spawn! |
| 560 | + |
468 | 561 | dlight\SetLightColor( Vector( cvars.String( "cl_weaponcolor" ) ) )
|
469 | 562 | dlight\SetBrightness( 0.5 )
|
470 | 563 | dlight\SetRadius( 64 )
|
471 | 564 | dlight\SetStyle( 5 )
|
472 | 565 |
|
473 | 566 | dlight.LightThink = ->
|
474 |
| - unless entity\IsValid! |
| 567 | + unless IsValid( entity ) |
475 | 568 | dlight\Remove!
|
476 | 569 | return
|
477 | 570 |
|
478 | 571 | owner = entity\GetOwner!
|
479 |
| - unless owner and owner\IsValid! and owner\IsPlayer! |
| 572 | + unless owner and IsValid( owner ) and owner\IsPlayer! |
480 | 573 | dlight\SetPos( entity\WorldSpaceCenter! )
|
481 | 574 | dlight\SetEnabled( true )
|
482 | 575 | return
|
|
500 | 593 | dlight\SetStyle( 5 )
|
501 | 594 |
|
502 | 595 | dlight.LightThink = ->
|
503 |
| - unless entity\IsValid! |
| 596 | + unless IsValid( entity ) |
504 | 597 | dlight\Remove!
|
505 | 598 | return
|
506 | 599 |
|
507 | 600 | owner = entity\GetOwner!
|
508 |
| - unless owner and owner\IsValid! and owner\IsPlayer! |
| 601 | + unless owner and IsValid( owner ) and owner\IsPlayer! |
509 | 602 | dlight\SetPos( entity\WorldSpaceCenter! )
|
510 | 603 | dlight\SetEnabled( true )
|
511 | 604 | return
|
|
527 | 620 | dlight\SetRadius( 32 )
|
528 | 621 |
|
529 | 622 | dlight.LightThink = ->
|
530 |
| - unless entity\IsValid! |
| 623 | + unless IsValid( entity ) |
531 | 624 | dlight\Remove!
|
532 | 625 | return
|
533 | 626 |
|
534 | 627 | owner = entity\GetOwner!
|
535 |
| - unless owner and owner\IsValid! and owner\IsPlayer! |
| 628 | + unless owner and IsValid( owner ) and owner\IsPlayer! |
536 | 629 | dlight\SetPos( entity\WorldSpaceCenter! )
|
537 | 630 | dlight\SetEnabled( true )
|
538 | 631 | return
|
|
571 | 664 | dlight\SetStyle( 5 )
|
572 | 665 |
|
573 | 666 | dlight.LightThink = ->
|
574 |
| - unless entity\IsValid! |
| 667 | + unless IsValid( entity ) |
575 | 668 | dlight\Remove!
|
576 | 669 | return
|
577 | 670 |
|
578 | 671 | owner = entity\GetOwner!
|
579 |
| - unless owner and owner\IsValid! and owner\IsPlayer! |
| 672 | + unless owner and IsValid( owner ) and owner\IsPlayer! |
580 | 673 | dlight\SetPos( entity\WorldSpaceCenter! )
|
581 | 674 | dlight\SetEnabled( true )
|
582 | 675 | return
|
|
610 | 703 | dlight\SetLocalPos( offset1 )
|
611 | 704 |
|
612 | 705 | dlight.LightThink = ->
|
613 |
| - unless entity\IsValid! |
| 706 | + unless IsValid( entity ) |
614 | 707 | dlight\Remove!
|
615 | 708 | return
|
616 | 709 |
|
|
627 | 720 | dlight\SetLocalPos( offset2 )
|
628 | 721 |
|
629 | 722 | dlight.LightThink = ->
|
630 |
| - unless entity\IsValid! |
| 723 | + unless IsValid( entity ) |
631 | 724 | dlight\Remove!
|
632 | 725 | return
|
633 | 726 |
|
|
0 commit comments