hoobonceagain

deathscreen

Sep 13th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. if SERVER then
  2. util.AddNetworkString( "StartFade" )
  3. CreateConVar( "glxy_blackouttime", 10, FCVAR_REPLICATED, "Set to any desired amount of seconds untill full blackout. (Going too low causes stuttery animations)" )
  4. -- Server pings client when player has died
  5. hook.Add( "PlayerDeath", "GalaxyPlayerDied", function( ply )
  6. net.Start( "StartFade" )
  7. net.WriteInt( GetConVar( "glxy_blackouttime"):GetInt(), 32 )
  8. net.Send( ply )
  9. end )
  10. -- Server pings client when player has spawned
  11. hook.Add( "PlayerSpawn", "GalaxyPlayerSpawned", function( ply )
  12. net.Start( "StartFade" )
  13. net.WriteInt( 0, 32 )
  14. net.Send( ply )
  15. end )
  16. end
  17.  
  18. if CLIENT then
  19. -- Remove red stuff
  20. hook.Add( "HUDShouldDraw", "RemoveRedScreenOnDeath", function( name )
  21. if ( name == "CHudDamageIndicator" ) then
  22. return false
  23. end
  24. end )
  25. -- Calculate the firstperson view attached to ragdoll
  26. local function CalcView( ply, origin, angles, fov )
  27. local ragdoll = ply:GetRagdollEntity()
  28. if( !ragdoll || ragdoll == NULL || !ragdoll:IsValid() ) then
  29. return
  30. end
  31. local eyes = ragdoll:GetAttachment( ragdoll:LookupAttachment( "eyes" ) )
  32. local view = {
  33. origin = eyes.Pos,
  34. angles = eyes.Ang,
  35. fov = 90,
  36. }
  37. return view
  38. end
  39. hook.Add( "CalcView", "DeathView", CalcView )
  40. -- Receive player dead/spawn status
  41. net.Receive( "StartFade", function()
  42. local BlackoutTime = net.ReadInt( 32 )
  43. local RemainingTime = 0
  44. local TimeInterval = 0
  45.  
  46. if BlackoutTime > 0 then
  47. TimeInterval = ( 255 / BlackoutTime ) * 0.1
  48. timer.Create( "BlackoutTimer", 0.1, BlackoutTime * 10, function()
  49. RemainingTime = RemainingTime + TimeInterval
  50. --print( RemainingTime ) ONLY ENABLE FOR DEBUG!
  51. end )
  52. end
  53.  
  54. hook.Add( "HUDPaint", "PaintBlack", function()
  55. if BlackoutTime > 0 then
  56. draw.RoundedBox( 0, 0, 0, ScrW(), ScrH(), Color( 0, 0, 0, RemainingTime ) )
  57. end
  58. end )
  59. end )
  60. endif SERVER then
  61. util.AddNetworkString( "StartFade" )
  62. CreateConVar( "glxy_blackouttime", 10, FCVAR_REPLICATED, "Set to any desired amount of seconds untill full blackout. (Going too low causes stuttery animations)" )
  63. -- Server pings client when player has died
  64. hook.Add( "PlayerDeath", "GalaxyPlayerDied", function( ply )
  65. net.Start( "StartFade" )
  66. net.WriteInt( GetConVar( "glxy_blackouttime"):GetInt(), 32 )
  67. net.Send( ply )
  68. end )
  69. -- Server pings client when player has spawned
  70. hook.Add( "PlayerSpawn", "GalaxyPlayerSpawned", function( ply )
  71. net.Start( "StartFade" )
  72. net.WriteInt( 0, 32 )
  73. net.Send( ply )
  74. end )
  75. end
  76.  
  77. if CLIENT then
  78. -- Remove red stuff
  79. hook.Add( "HUDShouldDraw", "RemoveRedScreenOnDeath", function( name )
  80. if ( name == "CHudDamageIndicator" ) then
  81. return false
  82. end
  83. end )
  84. -- Calculate the firstperson view attached to ragdoll
  85. local function CalcView( ply, origin, angles, fov )
  86. local ragdoll = ply:GetRagdollEntity()
  87. if( !ragdoll || ragdoll == NULL || !ragdoll:IsValid() ) then
  88. return
  89. end
  90. local eyes = ragdoll:GetAttachment( ragdoll:LookupAttachment( "eyes" ) )
  91. local view = {
  92. origin = eyes.Pos,
  93. angles = eyes.Ang,
  94. fov = 90,
  95. }
  96. return view
  97. end
  98. hook.Add( "CalcView", "DeathView", CalcView )
  99. -- Receive player dead/spawn status
  100. net.Receive( "StartFade", function()
  101. local BlackoutTime = net.ReadInt( 32 )
  102. local RemainingTime = 0
  103. local TimeInterval = 0
  104.  
  105. if BlackoutTime > 0 then
  106. TimeInterval = ( 255 / BlackoutTime ) * 0.1
  107. timer.Create( "BlackoutTimer", 0.1, BlackoutTime * 10, function()
  108. RemainingTime = RemainingTime + TimeInterval
  109. --print( RemainingTime ) ONLY ENABLE FOR DEBUG!
  110. end )
  111. end
  112.  
  113. hook.Add( "HUDPaint", "PaintBlack", function()
  114. if BlackoutTime > 0 then
  115. draw.RoundedBox( 0, 0, 0, ScrW(), ScrH(), Color( 0, 0, 0, RemainingTime ) )
  116. end
  117. end )
  118. end )
  119. end
Advertisement
Add Comment
Please, Sign In to add comment