Guest User

Untitled

a guest
Aug 9th, 2015
294
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. TOOL.Category = "Robotboy655"
  3. TOOL.Name = "#tool.rb655_lightsaber"
  4.  
  5. TOOL.ClientConVar["model"] = "models/sgg/starwars/weapons/w_anakin_ep2_saber_hilt.mdl"
  6. TOOL.ClientConVar["red"] = "0"
  7. TOOL.ClientConVar["green"] = "127"
  8. TOOL.ClientConVar["blue"] = "255"
  9. TOOL.ClientConVar["bladew"] = "2"
  10. TOOL.ClientConVar["bladel"] = "42"
  11.  
  12. TOOL.ClientConVar["dark"] = "0"
  13. TOOL.ClientConVar["starton"] = "1"
  14. TOOL.ClientConVar["syncw"] = "1"
  15. TOOL.ClientConVar["synce"] = "1"
  16.  
  17. TOOL.ClientConVar["humsound"] = "lightsaber/SaberLoop1.wav"
  18. TOOL.ClientConVar["swingsound"] = "lightsaber/SaberSwing1.wav"
  19. TOOL.ClientConVar["onsound"] = "lightsaber/SaberOn1.wav"
  20. TOOL.ClientConVar["offsound"] = "lightsaber/SaberOff1.wav"
  21.  
  22. cleanup.Register( "ent_lightsabers" )
  23.  
  24. if ( SERVER ) then
  25. CreateConVar( "sbox_maxent_lightsabers", 2 )
  26.  
  27. function MakeLightsaber( ply, model, pos, ang, LoopSound, SwingSound, OnSound, OffSound )
  28. if ( IsValid( ply ) && !ply:CheckLimit( "ent_lightsabers" ) ) then return false end
  29.  
  30. local ent_lightsaber = ents.Create( "ent_lightsaber" )
  31. if ( !IsValid( ent_lightsaber ) ) then return false end
  32.  
  33. ent_lightsaber:SetModel( model )
  34. ent_lightsaber:SetAngles( ang )
  35. ent_lightsaber:SetPos( pos )
  36. //ent_lightsaber:SetCrystalColor( clr )
  37. //ent_lightsaber:SetColor( clr )
  38. //ent_lightsaber:SetEnabled( tobool( Enabled ) )
  39.  
  40. table.Merge( ent_lightsaber:GetTable(), {
  41. Owner = ply,
  42. //clr = clr,
  43. //Enabled = tobool( Enabled ),
  44. LoopSound = LoopSound,
  45. SwingSound = SwingSound,
  46. OnSound = OnSound,
  47. OffSound = OffSound,
  48. } )
  49.  
  50. ent_lightsaber:Spawn()
  51. ent_lightsaber:Activate()
  52.  
  53. if ( IsValid( ply ) ) then
  54. ply:AddCount( "ent_lightsabers", ent_lightsaber )
  55. ply:AddCleanup( "ent_lightsabers", ent_lightsaber )
  56. end
  57.  
  58. DoPropSpawnedEffect( ent_lightsaber )
  59.  
  60. return ent_lightsaber
  61. end
  62.  
  63. duplicator.RegisterEntityClass( "ent_lightsaber", MakeLightsaber, "model", "pos", "ang", "LoopSound", "SwingSound", "OnSound", "OffSound" )
  64. end
  65.  
  66. function TOOL:LeftClick( trace )
  67. if ( trace.HitSky or !trace.HitPos ) then return false end
  68. if ( IsValid( trace.Entity ) and ( trace.Entity:GetClass() == "ent_lightsaber" or trace.Entity:IsPlayer() ) ) then return false end
  69. if ( trace.Entity:IsNPC() && trace.Entity:GetClass() != "npc_metropolice" ) then return false end
  70. if ( CLIENT ) then return true end
  71.  
  72. local ply = self:GetOwner()
  73.  
  74. local ang = trace.HitNormal:Angle()
  75. ang.pitch = ang.pitch - 90
  76.  
  77. if ( trace.HitNormal.z > 0.99 ) then ang.y = ply:GetAngles().y end
  78.  
  79. local r = self:GetClientNumber( "red" )
  80. local g = self:GetClientNumber( "green" )
  81. local b = self:GetClientNumber( "blue" )
  82.  
  83. local hs = self:GetClientInfo( "humsound" )
  84. local ss = self:GetClientInfo( "swingsound" )
  85. local ons = self:GetClientInfo( "onsound" )
  86. local offs = self:GetClientInfo( "offsound" )
  87.  
  88. local dark = self:GetClientNumber( "dark" )
  89. local enabled = self:GetClientNumber( "starton" )
  90.  
  91. local bld_w = math.Clamp( self:GetClientNumber( "bladew" ), 2, 4 )
  92. local bld_len = math.Clamp( self:GetClientNumber( "bladel" ), 32, 64 )
  93.  
  94. local ent_lightsaber = MakeLightsaber( ply, self:GetClientInfo( "model" ), trace.HitPos, ang, hs, ss, ons, offs )
  95.  
  96. if ( !IsValid( ent_lightsaber ) ) then return end
  97.  
  98. ent_lightsaber:SetDarkInner( tobool( dark ) )
  99. ent_lightsaber:SetMaxLength( bld_len )
  100. ent_lightsaber:SetBladeWidth( bld_w )
  101. ent_lightsaber:SetCrystalColor( Vector( r, g, b ) / 255 )
  102. ent_lightsaber:SetEnabled( tobool( enabled ) )
  103.  
  104. local min = ent_lightsaber:OBBMins()
  105. ent_lightsaber:SetPos( trace.HitPos - trace.HitNormal * min.z )
  106.  
  107. local phys = ent_lightsaber:GetPhysicsObject()
  108. if ( IsValid( phys ) ) then phys:Wake() end
  109.  
  110. if ( trace.Entity:IsNPC() && trace.Entity:GetClass() == "npc_metropolice" ) then
  111. ent_lightsaber:SetParent( trace.Entity )
  112. ent_lightsaber:Fire( "SetParentAttachment", "RHand" )
  113.  
  114. timer.Simple( 0.1, function()
  115. ent_lightsaber:SetLocalAngles( Angle( -85, 40, 0 ) )
  116. ent_lightsaber:SetLocalPos( Vector( -1.3, -1.3, -12 ) )
  117. end )
  118. end
  119.  
  120. undo.Create( "ent_lightsaber" )
  121. undo.AddEntity( ent_lightsaber )
  122. undo.SetPlayer( ply )
  123. undo.Finish()
  124.  
  125. return true
  126. end
  127.  
  128. function TOOL:RightClick( trace )
  129. if ( trace.HitSky or !trace.HitPos ) then return false end
  130. if ( IsValid( trace.Entity ) and ( trace.Entity:GetClass() == "ent_lightsaber" ) ) then return false end
  131. if ( CLIENT ) then return true end
  132.  
  133. local ply = self:GetOwner()
  134. if ( IsValid( ply:GetEyeTrace().Entity ) && ply:GetEyeTrace().Entity:IsPlayer() ) then
  135. ply = ply:GetEyeTrace().Entity
  136. end
  137.  
  138. ply:StripWeapon( "weapon_lightsaber" )
  139. local w = ply:Give( "weapon_lightsaber" )
  140.  
  141. local pl = self:GetOwner()
  142. w:SetMaxLength( math.Clamp( pl:GetInfoNum( "rb655_lightsaber_bladel", 42 ), 32, 64 ) )
  143. w:SetCrystalColor( Vector( pl:GetInfo( "rb655_lightsaber_red" ), pl:GetInfo( "rb655_lightsaber_green" ), pl:GetInfo( "rb655_lightsaber_blue" ) ) )
  144. w:SetDarkInner( pl:GetInfo( "rb655_lightsaber_dark" ) == "1" )
  145. w:SetWorldModel( pl:GetInfo( "rb655_lightsaber_model" ) )
  146. w:SetBladeWidth( math.Clamp( pl:GetInfoNum( "rb655_lightsaber_bladew", 2 ), 2, 4 ) )
  147.  
  148. w.LoopSound = pl:GetInfo( "rb655_lightsaber_humsound" )
  149. w.SwingSound = pl:GetInfo( "rb655_lightsaber_swingsound" )
  150. w:SetOnSound( pl:GetInfo( "rb655_lightsaber_onsound" ) )
  151. w:SetOffSound( pl:GetInfo( "rb655_lightsaber_offsound" ) )
  152.  
  153. timer.Simple( 0.2, function() ply:SelectWeapon( "weapon_lightsaber" ) end )
  154.  
  155. return true
  156. end
  157.  
  158. function TOOL:UpdateGhostEntity( ent, ply )
  159. if ( !IsValid( ent ) ) then return end
  160.  
  161. local trace = ply:GetEyeTrace()
  162.  
  163. if ( !trace.Hit ) then ent:SetNoDraw( true ) return end
  164. if ( IsValid( trace.Entity ) && trace.Entity:GetClass() == "ent_lightsaber" || trace.Entity:IsPlayer() || trace.Entity:IsNPC() ) then ent:SetNoDraw( true ) return end
  165.  
  166. local ang = trace.HitNormal:Angle()
  167. ang.p = ang.p - 90
  168.  
  169. if ( trace.HitNormal.z > 0.99 ) then ang.y = ply:GetAngles().y end
  170.  
  171. local min = ent:OBBMins()
  172. ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
  173.  
  174. ent:SetAngles( ang )
  175. ent:SetNoDraw( false )
  176. end
  177.  
  178. function TOOL:Think()
  179. if ( !IsValid( self.GhostEntity ) || self.GhostEntity:GetModel() != self:GetClientInfo( "model" ) ) then
  180. self:MakeGhostEntity( self:GetClientInfo( "model" ), Vector( 0, 0, 0 ), Angle( 0, 0, 0 ) )
  181. end
  182.  
  183. self:UpdateGhostEntity( self.GhostEntity, self:GetOwner() )
  184. end
  185.  
  186. if ( SERVER ) then return end
  187.  
  188. language.Add( "tool.rb655_lightsaber", "Lightsabers" )
  189. language.Add( "tool.rb655_lightsaber.name", "Lightsabers" )
  190. language.Add( "tool.rb655_lightsaber.desc", "Spawn customized lightsabers" )
  191. language.Add( "tool.rb655_lightsaber.0", "Left click to spawn a Lightsaber.\nRight click to give yourself a Lightsaber" )
  192.  
  193. language.Add( "tool.rb655_lightsaber.model", "Hilt" )
  194. language.Add( "tool.rb655_lightsaber.color", "Crystal Color" )
  195. language.Add( "tool.rb655_lightsaber.take", "Take this lightsaber" )
  196.  
  197. language.Add( "tool.rb655_lightsaber.DarkInner", "Dark inner blade" )
  198. language.Add( "tool.rb655_lightsaber.StartEnabled", "Enabled on spawn" )
  199.  
  200. language.Add( "tool.rb655_lightsaber.HumSound", "Hum Sound" )
  201. language.Add( "tool.rb655_lightsaber.SwingSound", "Swing Sound" )
  202. language.Add( "tool.rb655_lightsaber.IgniteSound", "Ignition Sound" )
  203.  
  204. //language.Add( "tool.rb655_lightsaber.SyncW", "Apply settings to weapon on spawn" )
  205. //language.Add( "tool.rb655_lightsaber.SyncE", "Apply settings to entity on spawn" )
  206. //language.Add( "tool.rb655_lightsaber.SyncE.Help", "If cheked, will apply current tool settings to newly spawned from spawnmenu weapon/entity." )
  207.  
  208. language.Add( "tool.rb655_lightsaber.bladew", "Blade Width" )
  209. language.Add( "tool.rb655_lightsaber.bladel", "Blade Length" )
  210.  
  211. language.Add( "tool.rb655_lightsaber.jedi", "Jedi" )
  212. language.Add( "tool.rb655_lightsaber.jedi_fast", "Jedi - Fast" )
  213. language.Add( "tool.rb655_lightsaber.sith", "Sith" )
  214. language.Add( "tool.rb655_lightsaber.sith_fast", "Sith - Fast" )
  215. language.Add( "tool.rb655_lightsaber.heavy", "Heavy" )
  216. language.Add( "tool.rb655_lightsaber.heavy_fast", "Heavy - Fast" )
  217. language.Add( "tool.rb655_lightsaber.jedi2", "Jedi - Original" )
  218. language.Add( "tool.rb655_lightsaber.jedi2_fast", "Jedi - Original Fast" )
  219. language.Add( "tool.rb655_lightsaber.dark", "Dark Saber" )
  220.  
  221. language.Add( "tool.rb655_lightsaber.hum.1", "Default" )
  222. language.Add( "tool.rb655_lightsaber.hum.2", "Sith Heavy" )
  223. language.Add( "tool.rb655_lightsaber.hum.3", "Medium" )
  224. language.Add( "tool.rb655_lightsaber.hum.4", "Heavish" )
  225. language.Add( "tool.rb655_lightsaber.hum.5", "Sith Assassin Light" )
  226. language.Add( "tool.rb655_lightsaber.hum.6", "Darth Vader" )
  227. language.Add( "tool.rb655_lightsaber.hum.7", "Heavy" )
  228. language.Add( "tool.rb655_lightsaber.hum.8", "Dooku" )
  229.  
  230. language.Add( "Cleanup_ent_lightsabers", "Lightsabers" )
  231. language.Add( "Cleaned_ent_lightsabers", "Cleaned up all Lightsabers" )
  232. language.Add( "SBoxLimit_ent_lightsabers", "You've hit the Lightsaber limit!" )
  233. language.Add( "Undone_ent_lightsaber", "Lightsaber undone" )
  234.  
  235. local ConVarsDefault = TOOL:BuildConVarList()
  236.  
  237. function TOOL.BuildCPanel( panel )
  238. panel:AddControl( "ComboBox", { MenuButton = 1, Folder = "rb655_lightsaber", Options = { [ "#preset.default" ] = ConVarsDefault }, CVars = table.GetKeys( ConVarsDefault ) } )
  239.  
  240. panel:AddControl( "PropSelect", {Label = "#tool.rb655_lightsaber.model", Height = 4, ConVar = "rb655_lightsaber_model", Models = list.Get( "LightsaberModels" )} )
  241. panel:AddControl( "Color", { Label = "#tool.rb655_lightsaber.color", Red = "rb655_lightsaber_red", Green = "rb655_lightsaber_green", Blue = "rb655_lightsaber_blue", ShowAlpha = "0", ShowHSV = "1", ShowRGB = "1" } )
  242.  
  243. panel:AddControl( "Checkbox", { Label = "#tool.rb655_lightsaber.DarkInner", Command = "rb655_lightsaber_dark" } )
  244. panel:AddControl( "Checkbox", { Label = "#tool.rb655_lightsaber.StartEnabled", Command = "rb655_lightsaber_starton" } )
  245.  
  246. panel:AddControl( "Slider", {Label = "#tool.rb655_lightsaber.bladeW", Type = "Float", Min = 2, Max = 4, Command = "rb655_lightsaber_bladew"} )
  247. panel:AddControl( "Slider", {Label = "#tool.rb655_lightsaber.bladeL", Type = "Float", Min = 32, Max = 64, Command = "rb655_lightsaber_bladel"} )
  248.  
  249. panel:AddControl( "ComboBox", { Label = "#tool.rb655_lightsaber.HumSound", MenuButton = "0", Options = list.Get( "rb655_LightsaberHumSounds" ) } )
  250. panel:AddControl( "ComboBox", { Label = "#tool.rb655_lightsaber.SwingSound", MenuButton = "0", Options = list.Get( "rb655_LightsaberSwingSounds" ) } )
  251. panel:AddControl( "ComboBox", { Label = "#tool.rb655_lightsaber.IgniteSound", MenuButton = "0", Options = list.Get( "rb655_LightsaberIgniteSounds" ) } )
  252.  
  253. //panel:AddControl( "Checkbox", { Label = "#tool.rb655_lightsaber.SyncW", Command = "rb655_lightsaber_syncw" } )
  254. //panel:AddControl( "Checkbox", { Label = "#tool.rb655_lightsaber.SyncE", Command = "rb655_lightsaber_synce", Help = true } )
  255. end
  256.  
  257. list.Set( "rb655_LightsaberHumSounds", "#tool.rb655_lightsaber.hum.1", { rb655_lightsaber_humsound = "lightsaber/SaberLoop1.wav" } )
  258. list.Set( "rb655_LightsaberHumSounds", "#tool.rb655_lightsaber.hum.2", { rb655_lightsaber_humsound = "lightsaber/SaberLoop2.wav" } )
  259. list.Set( "rb655_LightsaberHumSounds", "#tool.rb655_lightsaber.hum.3", { rb655_lightsaber_humsound = "lightsaber/SaberLoop3.wav" } )
  260. list.Set( "rb655_LightsaberHumSounds", "#tool.rb655_lightsaber.hum.4", { rb655_lightsaber_humsound = "lightsaber/SaberLoop4.wav" } )
  261. list.Set( "rb655_LightsaberHumSounds", "#tool.rb655_lightsaber.hum.5", { rb655_lightsaber_humsound = "lightsaber/SaberLoop5.wav" } )
  262. list.Set( "rb655_LightsaberHumSounds", "#tool.rb655_lightsaber.hum.6", { rb655_lightsaber_humsound = "lightsaber/SaberLoop6.wav" } )
  263. list.Set( "rb655_LightsaberHumSounds", "#tool.rb655_lightsaber.hum.7", { rb655_lightsaber_humsound = "lightsaber/SaberLoop7.wav" } )
  264. list.Set( "rb655_LightsaberHumSounds", "#tool.rb655_lightsaber.hum.8", { rb655_lightsaber_humsound = "lightsaber/SaberLoop8.wav" } )
  265. list.Set( "rb655_LightsaberHumSounds", "#tool.rb655_lightsaber.dark", { rb655_lightsaber_humsound = "lightsaber/DarkSaberLoop.wav" } )
  266.  
  267. list.Set( "rb655_LightsaberSwingSounds", "#tool.rb655_lightsaber.jedi", { rb655_lightsaber_swingsound = "lightsaber/SaberSwing1.wav" } )
  268. list.Set( "rb655_LightsaberSwingSounds", "#tool.rb655_lightsaber.sith", { rb655_lightsaber_swingsound = "lightsaber/SaberSwing2.wav" } )
  269. list.Set( "rb655_LightsaberSwingSounds", "#tool.rb655_lightsaber.dark", { rb655_lightsaber_swingsound = "lightsaber/DarkSaberSwing.wav" } )
  270.  
  271. list.Set( "rb655_LightsaberIgniteSounds", "#tool.rb655_lightsaber.jedi", { rb655_lightsaber_onsound = "lightsaber/SaberOn1.wav", rb655_lightsaber_offsound = "lightsaber/SaberOff1.wav" } )
  272. list.Set( "rb655_LightsaberIgniteSounds", "#tool.rb655_lightsaber.jedi_fast", { rb655_lightsaber_onsound = "lightsaber/SaberOn1_fast.wav", rb655_lightsaber_offsound = "lightsaber/SaberOff1_fast.wav" } )
  273. list.Set( "rb655_LightsaberIgniteSounds", "#tool.rb655_lightsaber.sith", { rb655_lightsaber_onsound = "lightsaber/SaberOn2.wav", rb655_lightsaber_offsound = "lightsaber/SaberOff2.wav" } )
  274. list.Set( "rb655_LightsaberIgniteSounds", "#tool.rb655_lightsaber.sith_fast", { rb655_lightsaber_onsound = "lightsaber/SaberOn2_fast.wav", rb655_lightsaber_offsound = "lightsaber/SaberOff2_fast.wav" } )
  275. list.Set( "rb655_LightsaberIgniteSounds", "#tool.rb655_lightsaber.heavy", { rb655_lightsaber_onsound = "lightsaber/SaberOn3.wav", rb655_lightsaber_offsound = "lightsaber/SaberOff3.wav" } )
  276. list.Set( "rb655_LightsaberIgniteSounds", "#tool.rb655_lightsaber.heavy_fast", { rb655_lightsaber_onsound = "lightsaber/SaberOn3_fast.wav", rb655_lightsaber_offsound = "lightsaber/SaberOff3_fast.wav" } )
  277. list.Set( "rb655_LightsaberIgniteSounds", "#tool.rb655_lightsaber.jedi2", { rb655_lightsaber_onsound = "lightsaber/SaberOn4.wav", rb655_lightsaber_offsound = "lightsaber/SaberOff4.mp3" } )
  278. list.Set( "rb655_LightsaberIgniteSounds", "#tool.rb655_lightsaber.jedi2_fast", { rb655_lightsaber_onsound = "lightsaber/SaberOn4_fast.wav", rb655_lightsaber_offsound = "lightsaber/SaberOff4_fast.wav" } )
  279. list.Set( "rb655_LightsaberIgniteSounds", "#tool.rb655_lightsaber.dark", { rb655_lightsaber_onsound = "lightsaber/DarkSaberOn.wav", rb655_lightsaber_offsound = "lightsaber/DarkSaberOff.wav" } )
  280.  
  281. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_anakin_ep2_saber_hilt.mdl", {} )
  282. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_anakin_ep3_saber_hilt.mdl", {} )
  283. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_common_jedi_saber_hilt.mdl", {} )
  284. //list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_dooku_saber_hilt.mdl", {} )
  285. list.Set( "LightsaberModels", "models/weapons/starwars/w_dooku_saber_hilt.mdl", {} )
  286. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_luke_ep6_saber_hilt.mdl", {} )
  287. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_mace_windu_saber_hilt.mdl", {} )
  288. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_maul_saber_half_hilt.mdl", {} )
  289. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_maul_saber_staff_hilt.mdl", {} )
  290. //list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_maul_saber_hilt.mdl", {} )
  291. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_obiwan_ep1_saber_hilt.mdl", {} )
  292. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_obiwan_ep3_saber_hilt.mdl", {} )
  293. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_quigon_gin_saber_hilt.mdl", {} )
  294. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_sidious_saber_hilt.mdl", {} )
  295. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_vader_saber_hilt.mdl", {} )
  296. list.Set( "LightsaberModels", "models/sgg/starwars/weapons/w_yoda_saber_hilt.mdl", {} )
RAW Paste Data