Guest User

Untitled

a guest
Aug 9th, 2015
9
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. if ( SERVER ) then AddCSLuaFile() return end
  3.  
  4. /* --------------------------------------------------------- Presets --------------------------------------------------------- */
  5.  
  6. /*
  7.  
  8. This should be moved to the tool, into the Options={} stuff
  9.  
  10. */
  11.  
  12. // Sith
  13. presets.Add( "rb655_lightsaber", "Darth Maul Saberstaff", {
  14. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_maul_saber_staff_hilt.mdl",
  15. rb655_lightsaber_red = "255",
  16. rb655_lightsaber_green = "0",
  17. rb655_lightsaber_blue = "0",
  18. rb655_lightsaber_dark = "0",
  19. rb655_lightsaber_bladew = "2.4",
  20. rb655_lightsaber_bladel = "45",
  21. rb655_lightsaber_humsound = "lightsaber/SaberLoop7.wav",
  22. rb655_lightsaber_swingsound = "lightsaber/SaberSwing2.wav",
  23. rb655_lightsaber_onsound = "lightsaber/SaberOn2.wav",
  24. rb655_lightsaber_offsound = "lightsaber/SaberOff2.wav"
  25. } )
  26.  
  27. presets.Add( "rb655_lightsaber", "Darth Maul Lightsaber", {
  28. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_maul_saber_half_hilt.mdl",
  29. rb655_lightsaber_red = "255",
  30. rb655_lightsaber_green = "0",
  31. rb655_lightsaber_blue = "0",
  32. rb655_lightsaber_dark = "0",
  33. rb655_lightsaber_bladew = "2.4",
  34. rb655_lightsaber_bladel = "45",
  35. rb655_lightsaber_humsound = "lightsaber/SaberLoop7.wav",
  36. rb655_lightsaber_swingsound = "lightsaber/SaberSwing2.wav",
  37. rb655_lightsaber_onsound = "lightsaber/SaberOn2.wav",
  38. rb655_lightsaber_offsound = "lightsaber/SaberOff2.wav"
  39. } )
  40.  
  41. presets.Add( "rb655_lightsaber", "Darth Tyrannus Lightsaber (Count Dooku)", {
  42. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_dooku_saber_hilt.mdl",
  43. rb655_lightsaber_red = "255",
  44. rb655_lightsaber_green = "0",
  45. rb655_lightsaber_blue = "0",
  46. rb655_lightsaber_dark = "0",
  47. rb655_lightsaber_bladew = "2",
  48. rb655_lightsaber_bladel = "42",
  49. rb655_lightsaber_humsound = "lightsaber/SaberLoop8.wav",
  50. rb655_lightsaber_swingsound = "lightsaber/SaberSwing2.wav",
  51. rb655_lightsaber_onsound = "lightsaber/SaberOn2.wav",
  52. rb655_lightsaber_offsound = "lightsaber/SaberOff2.wav"
  53. } )
  54.  
  55. presets.Add( "rb655_lightsaber", "Darth Sidious Lightsaber", {
  56. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_sidious_saber_hilt.mdl",
  57. rb655_lightsaber_red = "255",
  58. rb655_lightsaber_green = "0",
  59. rb655_lightsaber_blue = "0",
  60. rb655_lightsaber_dark = "0",
  61. rb655_lightsaber_bladew = "2.2",
  62. rb655_lightsaber_bladel = "43",
  63. rb655_lightsaber_humsound = "lightsaber/SaberLoop5.wav",
  64. rb655_lightsaber_swingsound = "lightsaber/SaberSwing2.wav",
  65. rb655_lightsaber_onsound = "lightsaber/SaberOn2.wav",
  66. rb655_lightsaber_offsound = "lightsaber/SaberOff2.wav"
  67. } )
  68.  
  69. presets.Add( "rb655_lightsaber", "Darth Vader Lightsaber", {
  70. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_vader_saber_hilt.mdl",
  71. rb655_lightsaber_red = "255",
  72. rb655_lightsaber_green = "0",
  73. rb655_lightsaber_blue = "0",
  74. rb655_lightsaber_dark = "0",
  75. rb655_lightsaber_bladew = "2.25",
  76. rb655_lightsaber_bladel = "43",
  77. rb655_lightsaber_humsound = "lightsaber/SaberLoop6.wav",
  78. rb655_lightsaber_swingsound = "lightsaber/SaberSwing2.wav",
  79. rb655_lightsaber_onsound = "lightsaber/SaberOn2.wav",
  80. rb655_lightsaber_offsound = "lightsaber/SaberOff2.wav"
  81. } )
  82.  
  83. // Jedi
  84. presets.Add( "rb655_lightsaber", "Master Yoda Lightsaber", {
  85. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_yoda_saber_hilt.mdl",
  86. rb655_lightsaber_red = "64",
  87. rb655_lightsaber_green = "255",
  88. rb655_lightsaber_blue = "64",
  89. rb655_lightsaber_dark = "0",
  90. rb655_lightsaber_bladew = "2.3",
  91. rb655_lightsaber_bladel = "40",
  92. rb655_lightsaber_humsound = "lightsaber/SaberLoop3.wav",
  93. rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav",
  94. rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav",
  95. rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav"
  96. } )
  97.  
  98. presets.Add( "rb655_lightsaber", "Qui-Gon Jinn Lightsaber", {
  99. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_quigon_gin_saber_hilt.mdl",
  100. rb655_lightsaber_red = "32",
  101. rb655_lightsaber_green = "255",
  102. rb655_lightsaber_blue = "32",
  103. rb655_lightsaber_dark = "0",
  104. rb655_lightsaber_bladew = "2.2",
  105. rb655_lightsaber_bladel = "42",
  106. rb655_lightsaber_humsound = "lightsaber/SaberLoop1.wav",
  107. rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav",
  108. rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav",
  109. rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav"
  110. } )
  111.  
  112. presets.Add( "rb655_lightsaber", "Mace Windu Lightsaber", {
  113. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_mace_windu_saber_hilt.mdl",
  114. rb655_lightsaber_red = "127",
  115. rb655_lightsaber_green = "0",
  116. rb655_lightsaber_blue = "255",
  117. rb655_lightsaber_dark = "0",
  118. rb655_lightsaber_bladew = "2",
  119. rb655_lightsaber_bladel = "42",
  120. rb655_lightsaber_humsound = "lightsaber/SaberLoop1.wav",
  121. rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav",
  122. rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav",
  123. rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav"
  124. } )
  125.  
  126. presets.Add( "rb655_lightsaber", "[EP3] Obi-Wan Kenobi Lightsaber", {
  127. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_obiwan_ep3_saber_hilt.mdl",
  128. rb655_lightsaber_red = "48",
  129. rb655_lightsaber_green = "255",
  130. rb655_lightsaber_blue = "48",
  131. rb655_lightsaber_dark = "0",
  132. rb655_lightsaber_bladew = "2.1",
  133. rb655_lightsaber_bladel = "42",
  134. rb655_lightsaber_humsound = "lightsaber/SaberLoop1.wav",
  135. rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav",
  136. rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav",
  137. rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav"
  138. } )
  139.  
  140. presets.Add( "rb655_lightsaber", "[EP1] Obi-Wan Kenobi Lightsaber", {
  141. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_obiwan_ep1_saber_hilt.mdl",
  142. rb655_lightsaber_red = "48",
  143. rb655_lightsaber_green = "255",
  144. rb655_lightsaber_blue = "48",
  145. rb655_lightsaber_dark = "0",
  146. rb655_lightsaber_bladew = "2.1",
  147. rb655_lightsaber_bladel = "42",
  148. rb655_lightsaber_humsound = "lightsaber/SaberLoop1.wav",
  149. rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav",
  150. rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav",
  151. rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav"
  152. } )
  153.  
  154. presets.Add( "rb655_lightsaber", "[EP6] Luke Skywalker Lightsaber", {
  155. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_luke_ep6_saber_hilt.mdl",
  156. rb655_lightsaber_red = "32",
  157. rb655_lightsaber_green = "255",
  158. rb655_lightsaber_blue = "32",
  159. rb655_lightsaber_dark = "0",
  160. rb655_lightsaber_bladew = "2.1",
  161. rb655_lightsaber_bladel = "42",
  162. rb655_lightsaber_humsound = "lightsaber/SaberLoop1.wav",
  163. rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav",
  164. rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav",
  165. rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav"
  166. } )
  167.  
  168. presets.Add( "rb655_lightsaber", "[EP2] Anakin Skywalker Lightsaber", {
  169. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_anakin_ep2_saber_hilt.mdl",
  170. rb655_lightsaber_red = "0",
  171. rb655_lightsaber_green = "100",
  172. rb655_lightsaber_blue = "255",
  173. rb655_lightsaber_dark = "0",
  174. rb655_lightsaber_bladew = "2.1",
  175. rb655_lightsaber_bladel = "42",
  176. rb655_lightsaber_humsound = "lightsaber/SaberLoop1.wav",
  177. rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav",
  178. rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav",
  179. rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav"
  180. } )
  181.  
  182. presets.Add( "rb655_lightsaber", "[EP3] Anakin Skywalker Lightsaber", {
  183. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_anakin_ep3_saber_hilt.mdl",
  184. rb655_lightsaber_red = "0",
  185. rb655_lightsaber_green = "100",
  186. rb655_lightsaber_blue = "255",
  187. rb655_lightsaber_dark = "0",
  188. rb655_lightsaber_bladew = "2.1",
  189. rb655_lightsaber_bladel = "42",
  190. rb655_lightsaber_humsound = "lightsaber/SaberLoop1.wav",
  191. rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav",
  192. rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav",
  193. rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav"
  194. } )
  195.  
  196. presets.Add( "rb655_lightsaber", "Common Jedi Lightsaber", {
  197. rb655_lightsaber_model = "models/sgg/starwars/weapons/w_common_jedi_saber_hilt.mdl",
  198. rb655_lightsaber_dark = "0",
  199. rb655_lightsaber_bladew = "2.2",
  200. rb655_lightsaber_bladel = "42",
  201. rb655_lightsaber_humsound = "lightsaber/SaberLoop1.wav",
  202. rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav",
  203. rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav",
  204. rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav"
  205. } )
  206.  
  207. // The Pre Vizsla's darksaber from clone wars, I LOVE IT
  208. presets.Add( "rb655_lightsaber", "Dark Saber", {
  209. rb655_lightsaber_red = "255",
  210. rb655_lightsaber_green = "255",
  211. rb655_lightsaber_blue = "255",
  212. rb655_lightsaber_dark = "1",
  213. rb655_lightsaber_humsound = "lightsaber/DarkSaberLoop.wav",
  214. rb655_lightsaber_swingsound = "lightsaber/DarkSaberSwing.wav",
  215. rb655_lightsaber_onsound = "lightsaber/DarkSaberOn.wav",
  216. rb655_lightsaber_offsound = "lightsaber/DarkSaberOff.wav"
  217. } )
  218.  
  219. /* --------------------------------------------------------- Hilt On a Belt --------------------------------------------------------- */
  220.  
  221. hook.Add( "PostPlayerDraw", "rb655_lightsaber", function( ply )
  222. for id, wep in pairs( ply:GetWeapons() ) do
  223. if ( IsValid( wep ) && wep:GetClass() == "weapon_lightsaber" && wep != ply:GetActiveWeapon() ) then
  224. if ( !ply.LightsaberMDL ) then
  225. ply.LightsaberMDL = ClientsideModel( wep.WorldModel, RENDERGROUP_BOTH ) --wep.WorldModel is nil?
  226. ply.LightsaberMDL:SetNoDraw( true )
  227. end
  228. ply.LightsaberMDL:SetModel( wep.WorldModel )
  229.  
  230. local pos, ang = ply:GetBonePosition( 0 )
  231. ang:RotateAroundAxis( ang:Up(), 80 )
  232.  
  233. local len = ply:GetVelocity():Length()
  234. if ( ply:GetVelocity():Distance( ply:GetForward() * len ) < ply:GetVelocity():Distance( ply:GetForward() * -len ) ) then
  235. ang:RotateAroundAxis( ang:Right(), math.min( ply:GetVelocity():Length() / 8, 55 ) - 5 ) // Forward
  236. else
  237. ang:RotateAroundAxis( ang:Right(), -math.min( ply:GetVelocity():Length() / 8, 55 ) + 5 )
  238. end
  239.  
  240. if ( ply:GetVelocity():Distance( ply:GetRight() * len ) < ply:GetVelocity():Distance( ply:GetRight() * -len ) ) then
  241. //ang:RotateAroundAxis( ang:Right(), math.min( ply:GetVelocity():Length() / 8, 55 ) - 5 ) // Right
  242. else
  243. ang:RotateAroundAxis( ang:Up(), -math.min( ply:GetVelocity():Length() / 16, 30 ) + 5 )
  244. end
  245.  
  246. pos = pos - ang:Right() * 8 - ang:Forward() * 16
  247. if ( wep.WorldModel == "models/sgg/starwars/weapons/w_maul_saber_hilt.mdl" ) then
  248. pos = pos - ang:Forward() * 10
  249. end
  250.  
  251. ply.LightsaberMDL:SetPos( pos )
  252. ply.LightsaberMDL:SetAngles( ang )
  253.  
  254. ply.LightsaberMDL:DrawModel()
  255. end
  256. end
  257. end)
  258.  
  259. /* --------------------------------------------------------- Lightsaber blade rendering --------------------------------------------------------- */
  260.  
  261. local HardLaser = Material( "lightsaber/hard_light" )
  262. local HardLaserInner = Material( "lightsaber/hard_light_inner" )
  263.  
  264. local HardLaserTrail = Material( "lightsaber/hard_light_trail" )
  265. local HardLaserTrailInner = Material( "lightsaber/hard_light_trail_inner" )
  266.  
  267. local HardLaserTrailEnd = Material( "lightsaber/hard_light_trail_end" )
  268. local HardLaserTrailEndInner = Material( "lightsaber/hard_light_trail_end_inner" )
  269.  
  270. local gOldPositions = {}
  271. local gTrailLength = 1
  272. local lastTime = 0
  273.  
  274. function rb655_RenderBlade( pos, dir, len, maxlen, width, color, black_inner, eid, underwater )
  275. //render.DrawLine( pos + dir * len*-5, pos + dir * len*10, color, true )
  276.  
  277. if ( len <= 0 ) then rb655_SaberClean( eid ) return end
  278.  
  279. if ( underwater ) then
  280. local ed = EffectData()
  281. ed:SetOrigin( pos )
  282. ed:SetNormal( dir )
  283. ed:SetRadius( len )
  284. util.Effect( "rb655_saber_underwater", ed )
  285. end
  286.  
  287. local inner_color = color_white
  288. if ( black_inner ) then inner_color = Color( 0, 0, 0 ) end
  289.  
  290. render.SetMaterial( HardLaser )
  291. render.DrawBeam( pos, pos + dir * len, width, 1, 0.01, color )
  292.  
  293. render.SetMaterial( HardLaserInner )
  294. render.DrawBeam( pos, pos + dir * len, width * 1.2, 1, 0.01, inner_color )
  295.  
  296. /* Dynamic light */
  297. local SaberLight = DynamicLight( eid )
  298. if ( SaberLight ) then
  299. SaberLight.Pos = pos + dir * ( len / 2 )
  300. SaberLight.r = color.r
  301. SaberLight.g = color.g
  302. SaberLight.b = color.b
  303. SaberLight.Brightness = 0.6
  304. SaberLight.Size = 176 * ( len / maxlen )
  305. SaberLight.Decay = 0
  306. SaberLight.DieTime = CurTime() + 0.1
  307. end
  308.  
  309. local prevB = pos
  310. local prevT = pos + dir * len
  311.  
  312. if ( !gOldPositions[ eid ] ) then gOldPositions[ eid ] = {} end
  313.  
  314. for id, prevpos in ipairs( gOldPositions[ eid ] ) do
  315. if ( id == gTrailLength ) then
  316. HardLaserTrailEnd:SetVector( "$color", Vector( color.r / 255, color.g / 255, color.b / 255 ) )
  317. render.SetMaterial( HardLaserTrailEnd )
  318. else
  319. HardLaserTrail:SetVector( "$color", Vector( color.r / 255, color.g / 255, color.b / 255 ) )
  320. render.SetMaterial( HardLaserTrail )
  321. end
  322. render.DrawQuad( prevpos.pos, prevB, prevT, prevpos.pos + prevpos.dir * prevpos.len )
  323.  
  324. if ( id == gTrailLength ) then
  325. HardLaserTrailEndInner:SetVector( "$color", Vector( inner_color.r / 255, inner_color.g / 255, inner_color.b / 255 ) )
  326. render.SetMaterial( HardLaserTrailEndInner )
  327. else
  328. HardLaserTrailInner:SetVector( "$color", Vector( inner_color.r / 255, inner_color.g / 255, inner_color.b / 255 ) )
  329. render.SetMaterial( HardLaserTrailInner )
  330. end
  331. //render.DrawQuad( prevpos.b, prevB, prevT, prevpos.t )
  332. render.DrawQuad( prevpos.pos, prevB, prevT, prevpos.pos + prevpos.dir * prevpos.len )
  333.  
  334. prevB = prevpos.pos
  335. prevT = prevpos.pos + prevpos.dir * prevpos.len
  336. end
  337. end
  338.  
  339. function rb655_SaberClean( eid )
  340. gOldPositions[ eid ] = nil
  341. gOldPositions[ eid + 655 ] = nil
  342. end
  343.  
  344. // Extremely ugly hack workaround :(
  345. function rb655_ProcessEntity( eid, pos, dir, len )
  346. if ( !gOldPositions[ eid ] ) then gOldPositions[ eid ] = {} end
  347.  
  348. for i = 0, gTrailLength - 1 do
  349. gOldPositions[ eid ][ gTrailLength - i ] = gOldPositions[ eid ][ gTrailLength - i - 1 ]
  350. if ( gTrailLength - i == 1 ) then
  351. gOldPositions[ eid ][ 1 ] = { dir = dir, len = len, pos = pos }
  352. //gOldPositions[ eid ][ 1 ] = { b = pos, t = pos + dir * len }
  353. end
  354. end
  355. end
  356.  
  357. hook.Add( "Think", "rb655_lightsaber_ugly_fixes", function()
  358. for id, ent in pairs( ents.FindByClass( "weapon_lightsaber" ) ) do
  359. if ( !IsValid( ent:GetOwner() ) || ent:GetOwner():GetActiveWeapon() != ent || !ent.GetBladeLength || ent:GetBladeLength() <= 0 ) then continue end
  360. local pos, ang = ent:GetSaberPosAng()
  361. rb655_ProcessEntity( ent:EntIndex(), pos, ang, ent:GetBladeLength() )
  362. if ( ent:LookupAttachment( "blade2" ) > 0 ) then
  363. local pos, ang = ent:GetSaberPosAng( 2 )
  364. rb655_ProcessEntity( ent:EntIndex() + 655, pos, ang, ent:GetBladeLength() )
  365. end
  366. end
  367.  
  368. for id, ent in pairs( ents.FindByClass( "ent_lightsaber" ) ) do
  369. if ( !ent.GetBladeLength || ent:GetBladeLength() <= 0 ) then continue end
  370.  
  371. local pos, ang = ent:GetSaberPosAng()
  372. rb655_ProcessEntity( ent:EntIndex(), pos, ang, ent:GetBladeLength() )
  373. if ( ent:LookupAttachment( "blade2" ) > 0 ) then
  374. local pos, ang = ent:GetSaberPosAng( 2 )
  375. rb655_ProcessEntity( ent:EntIndex() + 655, pos, ang, ent:GetBladeLength() )
  376. end
  377. end
  378. end)
RAW Paste Data