Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.58 KB | None | 0 0
  1.  
  2. --[[
  3.  
  4. Editing the Lightsabers.
  5.  
  6. Once you unpack the lightsaber addon, you are voided of any support as to why it doesn't work.
  7. I can't possibly provide support for all the edits and I can't know what your edits broke or whatever.
  8.  
  9. /////////////////////////////// DO NOT REUPLOAD THIS ADDON IN ANY SHAPE OF FORM. ///////////////////////////////
  10. /////////////////////////////// DO NOT REUPLOAD THIS ADDON IN ANY SHAPE OF FORM. ///////////////////////////////
  11. /////////////////////////////// DO NOT REUPLOAD THIS ADDON IN ANY SHAPE OF FORM. ///////////////////////////////
  12. /////////////////////////////// DO NOT REUPLOAD THIS ADDON IN ANY SHAPE OF FORM. ///////////////////////////////
  13. /////////////////////////////// DO NOT REUPLOAD THIS ADDON IN ANY SHAPE OF FORM. ///////////////////////////////
  14.  
  15. ////////////////////////// DO NOT EDIT ANYTHING DOWN BELOW OR YOU LOSE SUPPORT FROM ME //////////////////////////
  16. ////////////////////////// DO NOT EDIT ANYTHING DOWN BELOW OR YOU LOSE SUPPORT FROM ME //////////////////////////
  17. ////////////////////////// DO NOT EDIT ANYTHING DOWN BELOW OR YOU LOSE SUPPORT FROM ME //////////////////////////
  18. ////////////////////////// DO NOT EDIT ANYTHING DOWN BELOW OR YOU LOSE SUPPORT FROM ME //////////////////////////
  19. ////////////////////////// DO NOT EDIT ANYTHING DOWN BELOW OR YOU LOSE SUPPORT FROM ME //////////////////////////
  20. ////////////////////////// DO NOT EDIT ANYTHING DOWN BELOW OR YOU LOSE SUPPORT FROM ME //////////////////////////
  21.  
  22. ]]
  23.  
  24. AddCSLuaFile()
  25.  
  26. if ( SERVER ) then
  27. util.AddNetworkString( "rb655_holdtype" )
  28. resource.AddWorkshop( "111412589" )
  29. CreateConVar( "rb655_lightsaber_infinite", "0" )
  30. end
  31.  
  32. SWEP.PrintName = "Lightsaber chavalier/guerrier"
  33. SWEP.Author = "Robotboy655"
  34. SWEP.Category = "Robotboy655's Weapons"
  35. SWEP.Contact = "robotboy655@gmail.com"
  36. SWEP.Purpose = "To slice off each others limbs and heads."
  37. SWEP.Instructions = "Use the force, Luke."
  38. SWEP.RenderGroup = RENDERGROUP_BOTH
  39.  
  40. SWEP.Slot = 0
  41. SWEP.SlotPos = 4
  42.  
  43. SWEP.Spawnable = true
  44. SWEP.DrawAmmo = false
  45. SWEP.DrawCrosshair = false
  46. SWEP.AutoSwitchTo = false
  47. SWEP.AutoSwitchFrom = false
  48. SWEP.DrawWeaponInfoBox = false
  49.  
  50. SWEP.ViewModel = "models/weapons/v_crowbar.mdl"
  51. SWEP.WorldModel = "models/sgg/starwars/weapons/w_anakin_ep2_saber_hilt.mdl"
  52. SWEP.ViewModelFOV = 55
  53.  
  54. SWEP.Primary.ClipSize = -1
  55. SWEP.Primary.DefaultClip = -1
  56. SWEP.Primary.Automatic = false
  57. SWEP.Primary.Ammo = "none"
  58.  
  59. SWEP.Secondary.ClipSize = -1
  60. SWEP.Secondary.DefaultClip = -1
  61. SWEP.Secondary.Automatic = true
  62. SWEP.Secondary.Ammo = "none"
  63.  
  64. // We have NPC support, but it SUCKS
  65. list.Add( "NPCUsableWeapons", { class = "weapon_lightsaber", title = SWEP.PrintName } )
  66.  
  67. /* --------------------------------------------------------- Helper functions --------------------------------------------------------- */
  68.  
  69. function SWEP:PlayWeaponSound( snd )
  70. if ( CLIENT ) then return end
  71. self.Owner:EmitSound( snd )
  72. end
  73.  
  74. function SWEP:SelectTargets( num )
  75. local t = {}
  76. local dist = 512
  77.  
  78. local tr = util.TraceLine( {
  79. start = self.Owner:GetShootPos(),
  80. endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * dist,
  81. filter = self.Owner
  82. } )
  83.  
  84. local p = {}
  85. for id, ply in pairs( ents.GetAll() ) do
  86. if ( !ply:GetModel() || ply:GetModel() == "" || ply == self.Owner || ply:Health() < 1 ) then continue end
  87. if ( string.StartWith( ply:GetModel() || "", "models/gibs/" ) ) then continue end
  88. if ( string.find( ply:GetModel() || "", "chunk" ) ) then continue end
  89. if ( string.find( ply:GetModel() || "", "_shard" ) ) then continue end
  90. if ( string.find( ply:GetModel() || "", "_splinters" ) ) then continue end
  91.  
  92. local tr = util.TraceLine( {
  93. start = self.Owner:GetShootPos(),
  94. endpos = (ply.GetShootPos && ply:GetShootPos() || ply:GetPos()),
  95. filter = self.Owner,
  96. } )
  97.  
  98. if ( tr.Entity != ply && IsValid( tr.Entity ) || tr.Entity == game.GetWorld() ) then continue end
  99.  
  100. local pos1 = self.Owner:GetPos() + self.Owner:GetAimVector() * dist
  101. local pos2 = ply:GetPos()
  102. local dot = self.Owner:GetAimVector():Dot( ( self.Owner:GetPos() - pos2 ):GetNormalized() )
  103.  
  104. if ( pos1:Distance( pos2 ) <= dist && ply:EntIndex() > 0 && ply:GetModel() && ply:GetModel() != "" ) then
  105. table.insert( p, { ply = ply, dist = tr.HitPos:Distance( pos2 ), dot = dot, score = -dot + ( ( dist - pos1:Distance( pos2 ) ) / dist ) * 50 } )
  106. end
  107. end
  108.  
  109. local d = {}
  110. for id, ply in SortedPairsByMemberValue( p, "dist" ) do
  111. table.insert( t, ply.ply )
  112. if ( #t >= num ) then return t end
  113. end
  114.  
  115. return t
  116. end
  117.  
  118. /* --------------------------------------------------------- Force Powers --------------------------------------------------------- */
  119.  
  120. if ( SERVER ) then
  121. concommand.Add( "rb655_select_force", function( ply, cmd, args )
  122. if ( !IsValid( ply ) || !IsValid( ply:GetActiveWeapon() ) || ply:GetActiveWeapon():GetClass() != "weapon_lightsaber" || !tonumber( args[ 1 ]) ) then return end
  123.  
  124. local wep = ply:GetActiveWeapon()
  125. local typ = math.Clamp( tonumber( args[ 1 ]), 1, #wep.ForcePowers )
  126. wep:SetForceType( typ )
  127. end )
  128. end
  129.  
  130. hook.Add( "GetFallDamage", "rb655_lightsaber_no_fall_damage", function( ply, speed )
  131. if ( IsValid( ply ) && IsValid( ply:GetActiveWeapon() ) && ply:GetActiveWeapon():GetClass() == "weapon_lightsaber" ) then
  132. local wep = ply:GetActiveWeapon()
  133.  
  134. if ( ply:KeyDown( IN_DUCK ) ) then
  135. ply:SetNWFloat( "SWL_FeatherFall", CurTime() ) -- Hate on me for NWVars!
  136. wep:SetNextAttack( 0.5 )
  137. ply:ViewPunch( Angle( speed / 32, 0, math.random( -speed, speed ) / 128 ) )
  138. return 0
  139. end
  140. end
  141. end )
  142.  
  143. function SWEP:OnRestore()
  144. self.Owner:SetNWFloat( "SWL_FeatherFall", 0 )
  145. end
  146.  
  147. hook.Add( "CreateMove", "rb655_lightsaber_no_fall_damage", function( cmd/* ply, mv, cmd*/ )
  148. if ( CurTime() - LocalPlayer():GetNWFloat( "SWL_FeatherFall", CurTime() - 2 ) < 1 ) then
  149. cmd:ClearButtons() -- No attacking, we are busy
  150. cmd:ClearMovement() -- No moving, we are busy
  151. cmd:SetButtons( IN_DUCK ) -- Force them to crouch
  152. end
  153. end )
  154.  
  155. hook.Add( "EntityTakeDamage", "rb655_sabers_armor", function( victim, dmg )
  156. local ply = victim
  157. if ( !ply.GetActiveWeapon || !ply:IsPlayer() ) then return end
  158. local wep = ply:GetActiveWeapon()
  159. if ( !IsValid( wep ) || wep:GetClass() != "weapon_lightsaber" || wep.ForcePowers[ wep:GetForceType() ].name != "Force Absorb" ) then return end
  160. if ( !ply:KeyDown( IN_ATTACK2 ) /*|| !ply:IsOnGround()*/ ) then return end
  161.  
  162. local damage = dmg:GetDamage() / 5
  163. local force = wep:GetForce()
  164. if ( force < damage ) then
  165. wep:SetForce( 0 )
  166. dmg:SetDamage( ( damage - force ) * 5 )
  167. return
  168. end
  169. wep:SetForce( force - damage )
  170. dmg:SetDamage( 0 )
  171. end )
  172.  
  173. function SWEP:SetNextAttack( delay )
  174. self:SetNextPrimaryFire( CurTime() + delay )
  175. self:SetNextSecondaryFire( CurTime() + delay )
  176. end
  177.  
  178. function SWEP:ForceJumpAnim()
  179. self.Owner.m_bJumping = true
  180.  
  181. self.Owner.m_bFirstJumpFrame = true
  182. self.Owner.m_flJumpStartTime = CurTime()
  183.  
  184. self.Owner:AnimRestartMainSequence()
  185. end
  186.  
  187.  
  188.  
  189. SWEP.ForcePowers = { {
  190. name = "Force Leap",
  191. icon = "L",
  192. description = "Jump longer and higher.\nAim higher to jump higher/further.\nHold CTRL to negate fall damage, but stop moving for 1 sec",
  193. action = function( self )
  194. if ( self:GetForce() < 10 || !self.Owner:IsOnGround() || CLIENT ) then return end
  195. self:SetForce( self:GetForce() - 10 )
  196.  
  197. self:SetNextAttack( 0.5 )
  198.  
  199. self.Owner:SetVelocity( self.Owner:GetAimVector() * 512 + Vector( 0, 0, 512 ) )
  200.  
  201. self:PlayWeaponSound( "lightsaber/force_leap.wav" )
  202.  
  203. // Trigger the jump animation, yay
  204. self:CallOnClient( "ForceJumpAnim", "" )
  205. end
  206. }, {
  207. name = "Force Absorb",
  208. icon = "A",
  209. description = "Hold Mouse 2 to protect yourself from harm",
  210. action = function( self )
  211. if ( self:GetForce() < 1/* || !self.Owner:IsOnGround()*/ || CLIENT ) then return end
  212. self:SetForce( self:GetForce() - 0.1 )
  213.  
  214. self:SetNextAttack( 0.3 )
  215. end
  216. }, {
  217. name = "Force Repulse",
  218. icon = "R",
  219. description = "Hold to charge for greater distance/damage.\nKill everybody close to you.\nPush back everybody who is a bit farther away but still close enough.",
  220. think = function( self )
  221. if ( self:GetNextSecondaryFire() > CurTime() ) then return end
  222. if ( self:GetForce() < 1 || CLIENT ) then return end
  223. if ( !self.Owner:KeyDown( IN_ATTACK2 ) && !self.Owner:KeyReleased( IN_ATTACK2 ) ) then return end
  224. if ( !self._ForceRepulse && self:GetForce() < 16 ) then return end
  225.  
  226. if ( !self.Owner:KeyReleased( IN_ATTACK2 ) ) then
  227. if ( !self._ForceRepulse ) then self:SetForce( self:GetForce() - 16 ) self._ForceRepulse = 1 end
  228.  
  229. if ( !self.NextForceEffect || self.NextForceEffect < CurTime() ) then
  230. local ed = EffectData()
  231. ed:SetOrigin( self.Owner:GetPos() + Vector( 0, 0, 36 ) )
  232. ed:SetRadius( 128 * self._ForceRepulse )
  233. util.Effect( "rb655_force_repulse_in", ed, true, true )
  234.  
  235. self.NextForceEffect = CurTime() + math.Clamp( self._ForceRepulse / 20, 0.1, 0.5 )
  236. end
  237.  
  238. self._ForceRepulse = self._ForceRepulse + 0.025
  239. self:SetForce( self:GetForce() - 0.5 )
  240. if ( self:GetForce() > 0.99 ) then return end
  241. else
  242. if ( !self._ForceRepulse ) then return end
  243. end
  244.  
  245. local maxdist = 128 * self._ForceRepulse
  246.  
  247. for i, e in pairs( ents.FindInSphere( self.Owner:GetPos(), maxdist ) ) do
  248. if ( e == self.Owner ) then continue end
  249.  
  250. local dist = self.Owner:GetPos():Distance( e:GetPos() )
  251. local mul = ( maxdist - dist ) / 256
  252.  
  253. local v = ( self.Owner:GetPos() - e:GetPos() ):GetNormalized()
  254. v.z = 0
  255.  
  256. if ( e:IsNPC() && util.IsValidRagdoll( e:GetModel() || "" ) ) then
  257.  
  258. local dmg = DamageInfo()
  259. dmg:SetDamagePosition( e:GetPos() + e:OBBCenter() )
  260. dmg:SetDamage( 48 * mul )
  261. dmg:SetDamageType( DMG_GENERIC )
  262. if ( ( 1 - dist / maxdist ) > 0.8 ) then
  263. dmg:SetDamageType( DMG_DISSOLVE )
  264. dmg:SetDamage( e:Health() * 3 )
  265. end
  266. dmg:SetDamageForce( -v * math.min( mul * 40000, 80000 ) )
  267. dmg:SetInflictor( self.Owner )
  268. dmg:SetAttacker( self.Owner )
  269. e:TakeDamageInfo( dmg )
  270.  
  271. if ( e:IsOnGround() ) then
  272. e:SetVelocity( v * mul * -2048 + Vector( 0, 0, 64 ) )
  273. elseif ( !e:IsOnGround() ) then
  274. e:SetVelocity( v * mul * -1024 + Vector( 0, 0, 64 ) )
  275. end
  276.  
  277. elseif ( e:IsPlayer() && e:IsOnGround() ) then
  278. e:SetVelocity( v * mul * -2048 + Vector( 0, 0, 64 ) )
  279. elseif ( e:IsPlayer() && !e:IsOnGround() ) then
  280. e:SetVelocity( v * mul * -384 + Vector( 0, 0, 64 ) )
  281. elseif ( e:GetPhysicsObjectCount() > 0 ) then
  282. for i = 0, e:GetPhysicsObjectCount() - 1 do
  283. e:GetPhysicsObjectNum( i ):ApplyForceCenter( v * mul * -512 * math.min( e:GetPhysicsObject():GetMass(), 256 ) + Vector( 0, 0, 64 ) )
  284. end
  285. end
  286. end
  287.  
  288. local ed = EffectData()
  289. ed:SetOrigin( self.Owner:GetPos() + Vector( 0, 0, 36 ) )
  290. ed:SetRadius( maxdist )
  291. util.Effect( "rb655_force_repulse_out", ed, true, true )
  292.  
  293. self._ForceRepulse = nil
  294.  
  295. self:SetNextAttack( 1 )
  296.  
  297. self:PlayWeaponSound( "lightsaber/force_repulse.wav" )
  298. end
  299. }
  300.  
  301. /* --------------------------------------------------------- Initialize --------------------------------------------------------- */
  302.  
  303. function SWEP:SetupDataTables()
  304. self:NetworkVar( "Float", 0, "BladeLength" )
  305. self:NetworkVar( "Float", 1, "MaxLength" )
  306. self:NetworkVar( "Float", 2, "BladeWidth" )
  307. self:NetworkVar( "Float", 3, "Force" )
  308.  
  309. self:NetworkVar( "Bool", 0, "DarkInner" )
  310. self:NetworkVar( "Bool", 1, "Enabled" )
  311. self:NetworkVar( "Bool", 2, "WorksUnderwater" )
  312. self:NetworkVar( "Int", 0, "ForceType" )
  313. self:NetworkVar( "Int", 1, "IncorrectPlayerModel" )
  314.  
  315. self:NetworkVar( "Vector", 0, "CrystalColor" )
  316. self:NetworkVar( "String", 0, "WorldModel" )
  317. self:NetworkVar( "String", 1, "OnSound" )
  318. self:NetworkVar( "String", 2, "OffSound" )
  319.  
  320. if ( SERVER ) then
  321. self:SetBladeLength( 0 )
  322. self:SetBladeWidth( 2 )
  323. self:SetMaxLength( 42 )
  324. self:SetDarkInner( false )
  325. self:SetWorksUnderwater( true )
  326. self:SetEnabled( true )
  327.  
  328. self:SetOnSound( "lightsaber/saber_on" .. math.random( 1, 4 ) .. ".wav" )
  329. self:SetOffSound( "lightsaber/saber_off" .. math.random( 1, 4 ) .. ".wav" )
  330. self:SetWorldModel( "models/sgg/starwars/weapons/w_anakin_ep2_saber_hilt.mdl" )
  331. self:SetCrystalColor( Vector( math.random( 0, 255 ), math.random( 0, 255 ), math.random( 0, 255 ) ) )
  332. self:SetForceType( 1 )
  333. self:SetForce( 100 )
  334.  
  335. self:NetworkVarNotify( "Force", self.OnForceChanged )
  336. end
  337. end
  338.  
  339. function SWEP:Initialize()
  340. self.LoopSound = self.LoopSound || "lightsaber/saber_loop" .. math.random( 1, 8 ) .. ".wav"
  341. self.SwingSound = self.SwingSound || "lightsaber/saber_swing" .. math.random( 1, 2 ) .. ".wav"
  342.  
  343. self:SetWeaponHoldType( self:GetTargetHoldType() )
  344.  
  345. if ( self.Owner && self.Owner:IsNPC() && SERVER ) then // NPC Weapons
  346. self.Owner:Fire( "GagEnable" )
  347.  
  348. if self.Owner:GetClass() == "npc_citizen" then
  349. self.Owner:Fire( "DisableWeaponPickup" )
  350. end
  351.  
  352. self.Owner:SetKeyValue( "spawnflags", "256" )
  353.  
  354. hook.Add( "Think", self, self.NPCThink )
  355.  
  356. timer.Simple( 0.5, function()
  357. if ( !IsValid( self ) || !IsValid( self.Owner ) ) then return end
  358. self.Owner:SetCurrentWeaponProficiency( 4 )
  359. self.Owner:CapabilitiesAdd( CAP_FRIENDLY_DMG_IMMUNE )
  360. self.Owner:CapabilitiesRemove( CAP_WEAPON_MELEE_ATTACK1 )
  361. self.Owner:CapabilitiesRemove( CAP_INNATE_MELEE_ATTACK1 )
  362. end )
  363. end
  364. end
  365.  
  366. /* --------------------------------------------------------- NPC Weapons --------------------------------------------------------- */
  367.  
  368. function SWEP:SetupWeaponHoldTypeForAI( t )
  369. if ( !self.Owner:IsNPC() ) then return end
  370.  
  371. self.ActivityTranslateAI = {}
  372.  
  373. self.ActivityTranslateAI[ ACT_IDLE ] = ACT_IDLE
  374. self.ActivityTranslateAI[ ACT_IDLE_ANGRY ] = ACT_IDLE_ANGRY_MELEE
  375. self.ActivityTranslateAI[ ACT_IDLE_RELAXED ] = ACT_IDLE
  376. self.ActivityTranslateAI[ ACT_IDLE_STIMULATED ] = ACT_IDLE_ANGRY_MELEE
  377. self.ActivityTranslateAI[ ACT_IDLE_AGITATED ] = ACT_IDLE_ANGRY_MELEE
  378. self.ActivityTranslateAI[ ACT_IDLE_AIM_RELAXED ] = ACT_IDLE_ANGRY_MELEE
  379. self.ActivityTranslateAI[ ACT_IDLE_AIM_STIMULATED ] = ACT_IDLE_ANGRY_MELEE
  380. self.ActivityTranslateAI[ ACT_IDLE_AIM_AGITATED ] = ACT_IDLE_ANGRY_MELEE
  381.  
  382. self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ] = ACT_RANGE_ATTACK_THROW
  383. self.ActivityTranslateAI[ ACT_RANGE_ATTACK1_LOW ] = ACT_MELEE_ATTACK_SWING
  384. self.ActivityTranslateAI[ ACT_MELEE_ATTACK1 ] = ACT_MELEE_ATTACK_SWING
  385. self.ActivityTranslateAI[ ACT_MELEE_ATTACK2 ] = ACT_MELEE_ATTACK_SWING
  386. self.ActivityTranslateAI[ ACT_SPECIAL_ATTACK1 ] = ACT_RANGE_ATTACK_THROW
  387.  
  388. self.ActivityTranslateAI[ ACT_RANGE_AIM_LOW ] = ACT_IDLE_ANGRY_MELEE
  389. self.ActivityTranslateAI[ ACT_COVER_LOW ] = ACT_IDLE_ANGRY_MELEE
  390.  
  391. self.ActivityTranslateAI[ ACT_WALK ] = ACT_WALK
  392. self.ActivityTranslateAI[ ACT_WALK_RELAXED ] = ACT_WALK
  393. self.ActivityTranslateAI[ ACT_WALK_STIMULATED ] = ACT_WALK
  394. self.ActivityTranslateAI[ ACT_WALK_AGITATED ] = ACT_WALK
  395.  
  396. self.ActivityTranslateAI[ ACT_RUN_CROUCH ] = ACT_RUN
  397. self.ActivityTranslateAI[ ACT_RUN_CROUCH_AIM ] = ACT_RUN
  398. self.ActivityTranslateAI[ ACT_RUN ] = ACT_RUN
  399. self.ActivityTranslateAI[ ACT_RUN_AIM_RELAXED ] = ACT_RUN
  400. self.ActivityTranslateAI[ ACT_RUN_AIM_STIMULATED ] = ACT_RUN
  401. self.ActivityTranslateAI[ ACT_RUN_AIM_AGITATED ] = ACT_RUN
  402. self.ActivityTranslateAI[ ACT_RUN_AIM ] = ACT_RUN
  403. self.ActivityTranslateAI[ ACT_SMALL_FLINCH ] = ACT_RANGE_ATTACK_PISTOL
  404. self.ActivityTranslateAI[ ACT_BIG_FLINCH ] = ACT_RANGE_ATTACK_PISTOL
  405.  
  406. if ( self.Owner:GetClass() == "npc_metropolice" ) then
  407.  
  408. self.ActivityTranslateAI[ ACT_IDLE ] = ACT_IDLE
  409. self.ActivityTranslateAI[ ACT_IDLE_ANGRY ] = ACT_IDLE_ANGRY_MELEE
  410. self.ActivityTranslateAI[ ACT_IDLE_RELAXED ] = ACT_IDLE
  411. self.ActivityTranslateAI[ ACT_IDLE_STIMULATED ] = ACT_IDLE
  412. self.ActivityTranslateAI[ ACT_IDLE_AGITATED ] = ACT_IDLE_ANGRY_MELEE
  413.  
  414. self.ActivityTranslateAI[ ACT_MP_RUN ] = ACT_HL2MP_RUN_SUITCASE
  415. self.ActivityTranslateAI[ ACT_WALK ] = ACT_WALK_SUITCASE
  416. self.ActivityTranslateAI[ ACT_MELEE_ATTACK1 ] = ACT_MELEE_ATTACK_SWING
  417. self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ] = ACT_MELEE_ATTACK_SWING
  418. self.ActivityTranslateAI[ ACT_SPECIAL_ATTACK1 ] = ACT_RANGE_ATTACK_THROW
  419. self.ActivityTranslateAI[ ACT_SMALL_FLINCH ] = ACT_RANGE_ATTACK_PISTOL
  420. self.ActivityTranslateAI[ ACT_BIG_FLINCH ] = ACT_RANGE_ATTACK_PISTOL
  421.  
  422. return end
  423.  
  424. if ( self.Owner:GetClass() == "npc_combine_s2" ) then
  425.  
  426. self.ActivityTranslateAI[ ACT_IDLE ] = ACT_IDLE
  427. self.ActivityTranslateAI[ ACT_IDLE_ANGRY ] = ACT_IDLE_ANGRY_MELEE
  428. self.ActivityTranslateAI[ ACT_IDLE_RELAXED ] = ACT_IDLE
  429. self.ActivityTranslateAI[ ACT_IDLE_STIMULATED ] = ACT_IDLE_ANGRY_MELEE
  430. self.ActivityTranslateAI[ ACT_IDLE_AGITATED ] = ACT_IDLE_ANGRY_MELEE
  431. self.ActivityTranslateAI[ ACT_IDLE_AIM_RELAXED ] = ACT_IDLE_ANGRY_MELEE
  432. self.ActivityTranslateAI[ ACT_IDLE_AIM_STIMULATED ] = ACT_IDLE_ANGRY_MELEE
  433. self.ActivityTranslateAI[ ACT_IDLE_AIM_AGITATED ] = ACT_IDLE_ANGRY_MELEE
  434.  
  435. self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ] = ACT_RANGE_ATTACK_THROW
  436. self.ActivityTranslateAI[ ACT_RANGE_ATTACK1_LOW ] = ACT_MELEE_ATTACK_SWING
  437. self.ActivityTranslateAI[ ACT_MELEE_ATTACK1 ] = ACT_MELEE_ATTACK_SWING
  438. self.ActivityTranslateAI[ ACT_MELEE_ATTACK2 ] = ACT_MELEE_ATTACK_SWING
  439. self.ActivityTranslateAI[ ACT_SPECIAL_ATTACK1 ] = ACT_RANGE_ATTACK_THROW
  440.  
  441.  
  442. self.ActivityTranslateAI[ ACT_RANGE_AIM_LOW ] = ACT_IDLE_ANGRY_MELEE
  443. self.ActivityTranslateAI[ ACT_COVER_LOW ] = ACT_IDLE_ANGRY_MELEE
  444.  
  445. self.ActivityTranslateAI[ ACT_WALK ] = ACT_WALK
  446. self.ActivityTranslateAI[ ACT_WALK_RELAXED ] = ACT_WALK
  447. self.ActivityTranslateAI[ ACT_WALK_STIMULATED ] = ACT_WALK
  448. self.ActivityTranslateAI[ ACT_WALK_AGITATED ] = ACT_WALK
  449.  
  450. self.ActivityTranslateAI[ ACT_RUN ] = ACT_RUN
  451. self.ActivityTranslateAI[ ACT_RUN_AIM_RELAXED ] = ACT_RUN
  452. self.ActivityTranslateAI[ ACT_RUN_AIM_STIMULATED ] = ACT_RUN
  453. self.ActivityTranslateAI[ ACT_RUN_AIM_AGITATED ] = ACT_RUN
  454. self.ActivityTranslateAI[ ACT_RUN_AIM ] = ACT_RUN
  455. self.ActivityTranslateAI[ ACT_SMALL_FLINCH ] = ACT_RANGE_ATTACK_PISTOL
  456. self.ActivityTranslateAI[ ACT_BIG_FLINCH ] = ACT_RANGE_ATTACK_PISTOL
  457.  
  458. return end
  459.  
  460. if ( self.Owner:GetClass() == "npc_combine_s" ) then
  461.  
  462. self.ActivityTranslateAI[ ACT_IDLE ] = ACT_IDLE_UNARMED
  463. self.ActivityTranslateAI[ ACT_IDLE_ANGRY ] = ACT_IDLE_SHOTGUN
  464. self.ActivityTranslateAI[ ACT_IDLE_RELAXED ] = ACT_IDLE_SHOTGUN
  465. self.ActivityTranslateAI[ ACT_IDLE_STIMULATED ] = ACT_IDLE_SHOTGUN
  466. self.ActivityTranslateAI[ ACT_IDLE_AGITATED ] = ACT_IDLE_SHOTGUN
  467. self.ActivityTranslateAI[ ACT_IDLE_AIM_RELAXED ] = ACT_IDLE_SHOTGUN
  468. self.ActivityTranslateAI[ ACT_IDLE_AIM_STIMULATED ] = ACT_IDLE_SHOTGUN
  469. self.ActivityTranslateAI[ ACT_IDLE_AIM_AGITATED ] = ACT_IDLE_SHOTGUN
  470.  
  471. self.ActivityTranslateAI[ ACT_RANGE_ATTACK1 ] = ACT_MELEE_ATTACK1
  472. self.ActivityTranslateAI[ ACT_RANGE_ATTACK1_LOW ] = ACT_MELEE_ATTACK1
  473. self.ActivityTranslateAI[ ACT_MELEE_ATTACK1 ] = ACT_MELEE_ATTACK1
  474. self.ActivityTranslateAI[ ACT_MELEE_ATTACK2 ] = ACT_MELEE_ATTACK1
  475. self.ActivityTranslateAI[ ACT_SPECIAL_ATTACK1 ] = ACT_MELEE_ATTACK1
  476.  
  477. self.ActivityTranslateAI[ ACT_RANGE_AIM_LOW ] = ACT_IDLE_SHOTGUN
  478. self.ActivityTranslateAI[ ACT_COVER_LOW ] = ACT_IDLE_SHOTGUN
  479.  
  480. self.ActivityTranslateAI[ ACT_WALK ] = ACT_WALK_UNARMED
  481. self.ActivityTranslateAI[ ACT_WALK_RELAXED ] = ACT_WALK_UNARMED
  482. self.ActivityTranslateAI[ ACT_WALK_STIMULATED ] = ACT_WALK_UNARMED
  483. self.ActivityTranslateAI[ ACT_WALK_AGITATED ] = ACT_WALK_UNARMED
  484.  
  485. self.ActivityTranslateAI[ ACT_RUN ] = ACT_RUN_AIM_SHOTGUN
  486. self.ActivityTranslateAI[ ACT_RUN_AIM_RELAXED ] = ACT_RUN_AIM_SHOTGUN
  487. self.ActivityTranslateAI[ ACT_RUN_AIM_STIMULATED ] = ACT_RUN_AIM_SHOTGUN
  488. self.ActivityTranslateAI[ ACT_RUN_AIM_AGITATED ] = ACT_RUN_AIM_SHOTGUN
  489. self.ActivityTranslateAI[ ACT_RUN_AIM ] = ACT_RUN_AIM_SHOTGUN
  490.  
  491. return end
  492. end
  493.  
  494. function SWEP:GetCapabilities()
  495. return bit.bor( CAP_WEAPON_MELEE_ATTACK1 )
  496. end
  497.  
  498. function SWEP:NextFire()
  499. if ( !IsValid( self ) || !IsValid( self.Owner ) ) then return end
  500. if ( self.Owner:IsCurrentSchedule( SCHED_CHASE_ENEMY ) ) then return end
  501. self.NextFireTimer = true
  502. self:Chase_Enemy()
  503.  
  504. timer.Simple( math.Rand( 0.6, 1 ), function()
  505. self.NextFireTimer = false
  506. end )
  507. end
  508.  
  509. function SWEP:Chase_Enemy()
  510. if ( !IsValid( self ) || !IsValid( self.Owner ) ) then return end
  511. if ( self.Owner:GetEnemy():GetPos():Distance( self:GetPos() ) > 70 ) then
  512. self.Owner:SetSchedule( SCHED_CHASE_ENEMY )
  513. end
  514.  
  515. if ( self.Owner:GetEnemy() == self.Owner ) then self.Owner:SetEnemy( NULL ) return end
  516. if ( !self.CooldownTimer && self.Owner:GetEnemy():GetPos():Distance( self:GetPos() ) <= 70 ) then
  517. self.Owner:SetSchedule( SCHED_MELEE_ATTACK1 )
  518. self:NPCShoot_Primary( ShootPos, ShootDir )
  519. end
  520. end
  521.  
  522. function SWEP:NPCThink()
  523. if ( !IsValid( self.Owner ) || !IsValid( self ) || !self.Owner:IsNPC() ) then return end
  524.  
  525. //self.Owner:RemoveAllDecals()
  526. self.Owner:ClearCondition( 13 )
  527. self.Owner:ClearCondition( 17 )
  528. self.Owner:ClearCondition( 18 )
  529. self.Owner:ClearCondition( 20 )
  530. self.Owner:ClearCondition( 48 )
  531. self.Owner:ClearCondition( 42 )
  532. self.Owner:ClearCondition( 45 )
  533.  
  534. if ( !self.NextFireTimer && IsValid( self.Owner:GetEnemy() ) ) then
  535. self:NextFire()
  536. end
  537.  
  538. self:Think()
  539. end
  540.  
  541. function SWEP:NPCShoot_Primary( ShootPos, ShootDir )
  542. if ( !IsValid( self ) || !IsValid( self.Owner ) ) then return end
  543. if ( !self.Owner:GetEnemy() ) then return end
  544.  
  545. self.CooldownTimer = true
  546. local seqtimer = 0.4
  547. if self.Owner:GetClass() == "npc_alyx" then
  548. seqtimer = 0.8
  549. end
  550.  
  551. timer.Simple( seqtimer, function()
  552. if ( !IsValid( self ) || !IsValid( self.Owner ) ) then return end
  553. if ( self.Owner:IsCurrentSchedule( SCHED_MELEE_ATTACK1 ) ) then
  554. //self:PrimaryAttack()
  555. end
  556. self.CooldownTimer = false
  557. end )
  558. end
  559.  
  560. /* --------------------------------------------------------- Attacks --------------------------------------------------------- */
  561.  
  562. function SWEP:PrimaryAttack()
  563. if ( !IsValid( self.Owner ) ) then return end
  564.  
  565. self:SetNextAttack( 0.5 )
  566.  
  567. if ( !self.Owner:IsNPC() && self:GetEnabled() ) then
  568. self.Owner:AnimResetGestureSlot( GESTURE_SLOT_CUSTOM )
  569. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  570. end
  571. end
  572.  
  573. function SWEP:SecondaryAttack()
  574. if ( !IsValid( self.Owner ) || !self.ForcePowers[ self:GetForceType() ] ) then return end
  575. if ( game.SinglePlayer() && SERVER ) then self:CallOnClient( "SecondaryAttack", "" ) end
  576.  
  577. local ret = hook.Run( "CanUseLightsaberForcePower", self.Owner, self.ForcePowers[ self:GetForceType() ].name )
  578. if ( ret == false ) then return end
  579.  
  580. if ( self.ForcePowers[ self:GetForceType() ].action ) then
  581. self.ForcePowers[ self:GetForceType() ].action( self )
  582. if ( GetConVarNumber( "rb655_lightsaber_infinite" ) != 0 ) then self:SetForce( 100 ) end
  583. end
  584. end
  585.  
  586. function SWEP:Reload()
  587. if ( !self.Owner:KeyPressed( IN_RELOAD ) ) then return end
  588. if ( self.Owner:WaterLevel() > 2 && !self:GetWorksUnderwater() ) then return end
  589.  
  590. if ( self:GetEnabled() ) then
  591. self:PlayWeaponSound( self:GetOffSound() )
  592.  
  593. -- Fancy extinguish animations?
  594. if ( self.Owner:WaterLevel() > 1 ) then self:SetHoldType( "knife" ) end
  595. timer.Create( "rb655_ls_ht", 0.4, 1, function() if ( IsValid( self ) ) then self:SetHoldType( "normal" ) end end )
  596.  
  597. if ( CLIENT ) then return end
  598.  
  599. if ( self.SoundLoop ) then self.SoundLoop:Stop() self.SoundLoop = nil end
  600. if ( self.SoundSwing ) then self.SoundSwing:Stop() self.SoundSwing = nil end
  601. if ( self.SoundHit ) then self.SoundHit:Stop() self.SoundHit = nil end
  602. else
  603. self:PlayWeaponSound( self:GetOnSound() )
  604. self:SetHoldType( self:GetTargetHoldType() )
  605. timer.Destroy( "rb655_ls_ht" )
  606.  
  607. if ( CLIENT ) then return end
  608.  
  609. self.SoundLoop = CreateSound( self.Owner, Sound( self.LoopSound ) )
  610. if ( self.SoundLoop ) then self.SoundLoop:Play() end
  611.  
  612. self.SoundSwing = CreateSound( self.Owner, Sound( self.SwingSound ) )
  613. if ( self.SoundSwing ) then self.SoundSwing:Play() self.SoundSwing:ChangeVolume( 0, 0 ) end
  614.  
  615. self.SoundHit = CreateSound( self.Owner, Sound( "lightsaber/saber_hit.wav" ) )
  616. if ( self.SoundHit ) then self.SoundHit:Play() self.SoundHit:ChangeVolume( 0, 0 ) end
  617. end
  618.  
  619. self:SetEnabled( !self:GetEnabled() )
  620. end
  621.  
  622. /* --------------------------------------------------------- Hold Types --------------------------------------------------------- */
  623.  
  624. function SWEP:GetTargetHoldType()
  625. //print( self:LookupAttachment( "blade2" ), self:GetAttachment( 1 ), self:GetModel() )
  626. //PrintTable( self:GetAttachments() )
  627.  
  628. //if ( !self:GetEnabled() ) then return "normal" end
  629. //if ( self:GetWorldModel() == "models/sgg/starwars/weapons/w_maul_saber_hilt.mdl" ) then return "knife" end
  630. if ( self:GetWorldModel() == "models/weapons/starwars/w_maul_saber_staff_hilt.mdl" ) then return "knife" end
  631. if ( self:LookupAttachment( "blade2" ) && self:LookupAttachment( "blade2" ) > 0 ) then return "knife" end
  632.  
  633. return "melee2"
  634. end
  635.  
  636. /* --------------------------------------------------------- Drop / Deploy / Holster --------------------------------------------------------- */
  637.  
  638. function SWEP:OnDrop()
  639. if ( CLIENT ) then rb655_SaberClean( self:EntIndex() ) return end
  640.  
  641. if ( self.SoundLoop ) then self.SoundLoop:Stop() self.SoundLoop = nil end
  642. if ( self.SoundSwing ) then self.SoundSwing:Stop() self.SoundSwing = nil end
  643. if ( self.SoundHit ) then self.SoundHit:Stop() self.SoundHit = nil end
  644. end
  645.  
  646. function SWEP:OnRemove()
  647. if ( CLIENT ) then rb655_SaberClean( self:EntIndex() ) return end
  648.  
  649. if ( self.SoundLoop ) then self.SoundLoop:Stop() self.SoundLoop = nil end
  650. if ( self.SoundSwing ) then self.SoundSwing:Stop() self.SoundSwing = nil end
  651. if ( self.SoundHit ) then self.SoundHit:Stop() self.SoundHit = nil end
  652. end
  653.  
  654. function SWEP:Deploy()
  655.  
  656. local ply = self.Owner
  657.  
  658. if ( ply:IsPlayer() && !ply:IsBot() && !self.WeaponSynched && SERVER && GAMEMODE.IsSandboxDerived ) then
  659. self:SetMaxLength( math.Clamp( ply:GetInfoNum( "rb655_lightsaber_bladel", 42 ), 32, 64 ) )
  660. self:SetCrystalColor( Vector( ply:GetInfo( "rb655_lightsaber_red" ), ply:GetInfo( "rb655_lightsaber_green" ), ply:GetInfo( "rb655_lightsaber_blue" ) ) )
  661. self:SetDarkInner( ply:GetInfo( "rb655_lightsaber_dark" ) == "1" )
  662. self:SetWorldModel( ply:GetInfo( "rb655_lightsaber_model" ) )
  663. self:SetBladeWidth( math.Clamp( ply:GetInfoNum( "rb655_lightsaber_bladew", 2 ), 2, 4 ) )
  664.  
  665. self.LoopSound = ply:GetInfo( "rb655_lightsaber_humsound" )
  666. self.SwingSound = ply:GetInfo( "rb655_lightsaber_swingsound" )
  667. self:SetOnSound( ply:GetInfo( "rb655_lightsaber_onsound" ) )
  668. self:SetOffSound( ply:GetInfo( "rb655_lightsaber_offsound" ) )
  669.  
  670. self.WeaponSynched = true
  671. end
  672.  
  673. if ( self:GetEnabled() ) then self:PlayWeaponSound( self:GetOnSound() ) end
  674.  
  675. if ( CLIENT ) then return end
  676.  
  677. if ( ply:FlashlightIsOn() ) then ply:Flashlight( false ) end
  678.  
  679. self:SetBladeLength( 0 )
  680.  
  681. if ( self:GetEnabled() ) then
  682. self.SoundLoop = CreateSound( ply, Sound( self.LoopSound ) )
  683. if ( self.SoundLoop ) then self.SoundLoop:Play() end
  684.  
  685. self.SoundSwing = CreateSound( ply, Sound( self.SwingSound ) )
  686. if ( self.SoundSwing ) then self.SoundSwing:Play() self.SoundSwing:ChangeVolume( 0, 0 ) end
  687.  
  688. self.SoundHit = CreateSound( ply, Sound( "lightsaber/saber_hit.wav" ) )
  689. if ( self.SoundHit ) then self.SoundHit:Play() self.SoundHit:ChangeVolume( 0, 0 ) end
  690. end
  691.  
  692. if ( !self:GetEnabled() ) then
  693. self:SetHoldType( "normal" )
  694. else
  695. self:SetHoldType( self:GetTargetHoldType() )
  696. end
  697.  
  698. return true
  699. end
  700.  
  701. function SWEP:Holster()
  702. if ( self:GetEnabled() ) then self:PlayWeaponSound( self:GetOffSound() ) end
  703.  
  704. if ( CLIENT ) then rb655_SaberClean( self:EntIndex() ) return true end
  705.  
  706. if ( self.SoundLoop ) then self.SoundLoop:Stop() self.SoundLoop = nil end
  707. if ( self.SoundSwing ) then self.SoundSwing:Stop() self.SoundSwing = nil end
  708. if ( self.SoundHit ) then self.SoundHit:Stop() self.SoundHit = nil end
  709.  
  710. return true
  711. end
  712.  
  713. /* --------------------------------------------------------- Think --------------------------------------------------------- */
  714.  
  715. function SWEP:GetSaberPosAng( num, side )
  716. num = num || 1
  717.  
  718. if ( SERVER ) then self:SetIncorrectPlayerModel( 0 ) end
  719.  
  720. if ( IsValid( self.Owner ) ) then
  721. local bone = self.Owner:LookupBone( "ValveBiped.Bip01_R_Hand" )
  722. local attachment = self:LookupAttachment( "blade" .. num )
  723. if ( side ) then
  724. attachment = self:LookupAttachment( "quillon" .. num )
  725. end
  726.  
  727. if ( !bone && SERVER ) then
  728. self:SetIncorrectPlayerModel( 1 )
  729. end
  730.  
  731. if ( attachment && attachment > 0 ) then
  732. local PosAng = self:GetAttachment( attachment )
  733.  
  734. if ( !bone && SERVER ) then
  735. PosAng.Pos = PosAng.Pos + Vector( 0, 0, 36 )
  736. if ( SERVER && IsValid( self.Owner ) && self.Owner:Crouching() ) then PosAng.Pos = PosAng.Pos - Vector( 0, 0, 18 ) end
  737. PosAng.Ang.p = 0
  738. end
  739.  
  740. return PosAng.Pos, PosAng.Ang:Forward()
  741. end
  742.  
  743. if ( bone ) then
  744. local pos, ang = self.Owner:GetBonePosition( bone )
  745. if ( pos == self.Owner:GetPos() ) then
  746. local matrix = self.Owner:GetBoneMatrix( bone )
  747. if ( matrix ) then
  748. pos = matrix:GetTranslation()
  749. ang = matrix:GetAngles()
  750. else
  751. self:SetIncorrectPlayerModel( 1 )
  752. end
  753. end
  754.  
  755. ang:RotateAroundAxis( ang:Forward(), 180 )
  756. ang:RotateAroundAxis( ang:Up(), 30 )
  757. ang:RotateAroundAxis( ang:Forward(), -5.7 )
  758. ang:RotateAroundAxis( ang:Right(), 92 )
  759.  
  760. pos = pos + ang:Up() * -3.3 + ang:Right() * 0.8 + ang:Forward() * 5.6
  761.  
  762. return pos, ang:Forward()
  763. end
  764.  
  765. self:SetIncorrectPlayerModel( 1 )
  766. else
  767. self:SetIncorrectPlayerModel( 2 )
  768. end
  769.  
  770. if ( self:GetIncorrectPlayerModel() == 0 ) then self:SetIncorrectPlayerModel( 1 ) end
  771.  
  772. local defAng = self:GetAngles()
  773. defAng.p = 0
  774.  
  775. local defPos = self:GetPos() + defAng:Right() * 0.6 - defAng:Up() * 0.2 + defAng:Forward() * 0.8
  776. if ( SERVER ) then defPos = defPos + Vector( 0, 0, 36 ) end
  777. if ( SERVER && IsValid( self.Owner ) && self.Owner:Crouching() ) then defPos = defPos - Vector( 0, 0, 18 ) end
  778.  
  779. return defPos, -defAng:Forward()
  780. end
  781.  
  782. function SWEP:OnForceChanged( name, old, new )
  783. if ( old > new ) then
  784. self.NextForce = CurTime() + 4
  785. end
  786. end
  787.  
  788. function SWEP:Think()
  789. self.WorldModel = self:GetWorldModel()
  790. self:SetModel( self:GetWorldModel() )
  791.  
  792. if ( self.ForcePowers[ self:GetForceType() ] && self.ForcePowers[ self:GetForceType() ].think && !self.Owner:KeyDown( IN_USE ) ) then
  793. local bool = hook.Run( "CanUseLightsaberForcePower", self.Owner, self.ForcePowers[ self:GetForceType() ].name )
  794. if ( ret != false ) then
  795. self.ForcePowers[ self:GetForceType() ].think( self )
  796. end
  797. end
  798.  
  799. if ( CLIENT ) then return true end
  800.  
  801. if ( ( self.NextForce || 0 ) < CurTime() ) then
  802. self:SetForce( math.min( self:GetForce() + 0.5, 100 ) )
  803. end
  804.  
  805. if ( !self:GetEnabled() && self:GetBladeLength() != 0 ) then
  806. self:SetBladeLength( math.Approach( self:GetBladeLength(), 0, 2 ) )
  807. elseif ( self:GetEnabled() && self:GetBladeLength() != self:GetMaxLength() ) then
  808. self:SetBladeLength( math.Approach( self:GetBladeLength(), self:GetMaxLength(), 8 ) )
  809. end
  810.  
  811. if ( self:GetEnabled() && !self:GetWorksUnderwater() && self.Owner:WaterLevel() > 2 ) then
  812. self:SetEnabled( false )
  813. self:EmitSound( self:GetOffSound() )
  814. end
  815.  
  816. if ( self:GetBladeLength() <= 0 ) then return end
  817.  
  818. // ------------------------------------------------- DAMAGE ------------------------------------------------- //
  819.  
  820. -- Up
  821. local isTrace1Hit = false
  822. local pos, ang = self:GetSaberPosAng()
  823. local trace = util.TraceLine( {
  824. start = pos,
  825. endpos = pos + ang * self:GetBladeLength(),
  826. filter = { self, self.Owner },
  827. //mins = Vector( -1, -1, -1 ) * self:GetBladeWidth() / 8,
  828. //maxs = Vector( 1, 1, 1 ) * self:GetBladeWidth() / 8
  829. } )
  830. local traceBack = util.TraceLine( {
  831. start = pos + ang * self:GetBladeLength(),
  832. endpos = pos,
  833. filter = { self, self.Owner },
  834. //mins = Vector( -1, -1, -1 ) * self:GetBladeWidth() / 8,
  835. //maxs = Vector( 1, 1, 1 ) * self:GetBladeWidth() / 8
  836. } )
  837.  
  838. //if ( SERVER ) then debugoverlay.Line( trace.StartPos, trace.HitPos, .1, Color( 255, 0, 0 ), false ) end
  839.  
  840. if ( trace.HitSky || trace.StartSolid ) then trace.Hit = false end
  841. if ( traceBack.HitSky || traceBack.StartSolid ) then traceBack.Hit = false end
  842.  
  843. self:DrawHitEffects( trace, traceBack )
  844. isTrace1Hit = trace.Hit || traceBack.Hit
  845.  
  846. // Don't deal the damage twice to the same entity
  847. if ( traceBack.Entity == trace.Entity && IsValid( trace.Entity ) ) then traceBack.Hit = false end
  848.  
  849. if ( trace.Hit ) then rb655_LS_DoDamage( trace, self ) end
  850. if ( traceBack.Hit ) then rb655_LS_DoDamage( traceBack, self ) end
  851.  
  852. -- Down
  853. local isTrace2Hit = false
  854. if ( self:LookupAttachment( "blade2" ) > 0 ) then -- TEST ME
  855. local pos2, dir2 = self:GetSaberPosAng( 2 )
  856. local trace2 = util.TraceLine( {
  857. start = pos2,
  858. endpos = pos2 + dir2 * self:GetBladeLength(),
  859. filter = { self, self.Owner },
  860. //mins = Vector( -1, -1, -1 ) * self:GetBladeWidth() / 8,
  861. //maxs = Vector( 1, 1, 1 ) * self:GetBladeWidth() / 8
  862. } )
  863. local traceBack2 = util.TraceLine( {
  864. start = pos2 + dir2 * self:GetBladeLength(),
  865. endpos = pos2,
  866. filter = { self, self.Owner },
  867. //mins = Vector( -1, -1, -1 ) * self:GetBladeWidth() / 8,
  868. //maxs = Vector( 1, 1, 1 ) * self:GetBladeWidth() / 8
  869. } )
  870.  
  871. if ( trace2.HitSky || trace2.StartSolid ) then trace2.Hit = false end
  872. if ( traceBack2.HitSky || traceBack2.StartSolid ) then traceBack2.Hit = false end
  873.  
  874. self:DrawHitEffects( trace2, traceBack2 )
  875. isTrace2Hit = trace2.Hit || traceBack2.Hit
  876.  
  877. if ( traceBack2.Entity == trace2.Entity && IsValid( trace2.Entity ) ) then traceBack2.Hit = false end
  878.  
  879. if ( trace2.Hit ) then rb655_LS_DoDamage( trace2, self ) end
  880. if ( traceBack2.Hit ) then rb655_LS_DoDamage( traceBack2, self ) end
  881.  
  882. end
  883.  
  884. if ( ( isTrace1Hit || isTrace2Hit ) && self.SoundHit ) then
  885. self.SoundHit:ChangeVolume( math.Rand( 0.1, 0.5 ), 0 )
  886. elseif ( self.SoundHit ) then
  887. self.SoundHit:ChangeVolume( 0, 0 )
  888. end
  889.  
  890. // ------------------------------------------------- SOUNDS ------------------------------------------------- //
  891.  
  892. if ( self.SoundSwing ) then
  893.  
  894. if ( self.LastAng != ang ) then
  895. self.LastAng = self.LastAng || ang
  896. self.SoundSwing:ChangeVolume( math.Clamp( ang:Distance( self.LastAng ) / 2, 0, 1 ), 0 )
  897. end
  898.  
  899. self.LastAng = ang
  900. end
  901.  
  902. if ( self.SoundLoop ) then
  903. pos = pos + ang * self:GetBladeLength()
  904.  
  905. if ( self.LastPos != pos ) then
  906. self.LastPos = self.LastPos || pos
  907. self.SoundLoop:ChangeVolume( 0.1 + math.Clamp( pos:Distance( self.LastPos ) / 128, 0, 0.2 ), 0 )
  908. end
  909. self.LastPos = pos
  910. end
  911. end
  912.  
  913. function SWEP:DrawHitEffects( trace, traceBack )
  914. if ( self:GetBladeLength() <= 0 ) then return end
  915.  
  916. if ( trace.Hit ) then
  917. rb655_DrawHit( trace.HitPos, trace.HitNormal )
  918. end
  919.  
  920. if ( traceBack && traceBack.Hit ) then
  921. rb655_DrawHit( traceBack.HitPos, traceBack.HitNormal )
  922. end
  923. end
  924.  
  925. /* ------------------------------------------------------------- NPC STUFF ----------------------------------------------------------------- */
  926.  
  927. local index = ACT_HL2MP_IDLE_KNIFE
  928. local KnifeHoldType = {}
  929. KnifeHoldType[ ACT_MP_STAND_IDLE ] = index
  930. KnifeHoldType[ ACT_MP_WALK ] = index + 1
  931. KnifeHoldType[ ACT_MP_RUN ] = index + 2
  932. KnifeHoldType[ ACT_MP_CROUCH_IDLE ] = index + 3
  933. KnifeHoldType[ ACT_MP_CROUCHWALK ] = index + 4
  934. KnifeHoldType[ ACT_MP_ATTACK_STAND_PRIMARYFIRE ] = index + 5
  935. KnifeHoldType[ ACT_MP_ATTACK_CROUCH_PRIMARYFIRE ] = index + 5
  936. KnifeHoldType[ ACT_MP_RELOAD_STAND ] = index + 6
  937. KnifeHoldType[ ACT_MP_RELOAD_CROUCH ] = index + 6
  938. KnifeHoldType[ ACT_MP_JUMP ] = index + 7
  939. KnifeHoldType[ ACT_RANGE_ATTACK1 ] = index + 8
  940. KnifeHoldType[ ACT_MP_SWIM ] = index + 9
  941.  
  942. function SWEP:TranslateActivity( act )
  943.  
  944. if ( self.Owner:IsNPC() ) then
  945. if ( self.ActivityTranslateAI[ act ] ) then return self.ActivityTranslateAI[ act ] end
  946. return -1
  947. end
  948.  
  949. if ( self.Owner:Crouching() ) then
  950. local tr = util.TraceHull( {
  951. start = self.Owner:GetShootPos(),
  952. endpos = self.Owner:GetShootPos() + Vector( 0, 0, 20 ),
  953. mins = self.Owner:OBBMins(),
  954. maxs = self.Owner:OBBMaxs(),
  955. filter = self.Owner
  956. } )
  957.  
  958. if ( self:GetEnabled() && tr.Hit && act == ACT_MP_ATTACK_CROUCH_PRIMARYFIRE ) then return ACT_HL2MP_IDLE_KNIFE + 5 end
  959.  
  960. if ( ( !self:GetEnabled() && self:GetHoldType() == "normal" ) && self.Owner:Crouching() && act == ACT_MP_CROUCH_IDLE ) then return ACT_HL2MP_IDLE_KNIFE + 3 end
  961. if ( ( ( !self:GetEnabled() && self:GetHoldType() == "normal" ) || ( self:GetEnabled() && tr.Hit ) ) && act == ACT_MP_CROUCH_IDLE ) then return ACT_HL2MP_IDLE_KNIFE + 3 end
  962. if ( ( ( !self:GetEnabled() && self:GetHoldType() == "normal" ) || ( self:GetEnabled() && tr.Hit ) ) && act == ACT_MP_CROUCHWALK ) then return ACT_HL2MP_IDLE_KNIFE + 4 end
  963.  
  964. end
  965.  
  966. if ( self.Owner:WaterLevel() > 1 && self:GetEnabled() ) then
  967. return KnifeHoldType[ act ]
  968. end
  969.  
  970. if ( self.ActivityTranslate[ act ] != nil ) then return self.ActivityTranslate[ act ]end
  971. return -1
  972. end
  973.  
  974. /* ------------------------------------------------------------- Clientside stuff ----------------------------------------------------------------- */
  975.  
  976. if ( SERVER ) then return end
  977.  
  978. killicon.Add( "weapon_lightsaber", "lightsaber/lightsaber_killicon", color_white )
  979.  
  980. local WepSelectIcon = Material( "lightsaber/selection.png" )
  981. local Size = 96
  982.  
  983. function SWEP:DrawWeaponSelection( x, y, w, h, a )
  984. surface.SetDrawColor( 255, 255, 255, a )
  985. surface.SetMaterial( WepSelectIcon )
  986.  
  987. render.PushFilterMag( TEXFILTER.ANISOTROPIC )
  988. render.PushFilterMin( TEXFILTER.ANISOTROPIC )
  989.  
  990. surface.DrawTexturedRect( x + ( ( w - Size ) / 2 ), y + ( ( h - Size ) / 2.5 ), Size, Size )
  991.  
  992. render.PopFilterMag()
  993. render.PopFilterMin()
  994. end
  995.  
  996. function SWEP:DrawWorldModel()
  997. self:DrawWorldModelTranslucent()
  998. end
  999.  
  1000. function SWEP:DrawWorldModelTranslucent()
  1001. self.WorldModel = self:GetWorldModel()
  1002. self:SetModel( self:GetWorldModel() )
  1003.  
  1004. self:DrawModel()
  1005. if ( !IsValid( self:GetOwner() ) ) then return end
  1006.  
  1007. local clr = self:GetCrystalColor()
  1008. clr = Color( clr.x, clr.y, clr.z )
  1009.  
  1010. local bladesFound = false -- true if the model is OLD and does not have blade attachments
  1011. local blades = 0
  1012. for id, t in pairs( self:GetAttachments() ) do
  1013. if ( !string.match( t.name, "blade(%d+)" ) && !string.match( t.name, "quillon(%d+)" ) ) then continue end
  1014.  
  1015. local bladeNum = string.match( t.name, "blade(%d+)" )
  1016. local quillonNum = string.match( t.name, "quillon(%d+)" )
  1017.  
  1018. if ( bladeNum && self:LookupAttachment( "blade" .. bladeNum ) > 0 ) then
  1019. blades = blades + 1
  1020. local pos, dir = self:GetSaberPosAng( bladeNum )
  1021. rb655_RenderBlade( pos, dir, self:GetBladeLength(), self:GetMaxLength(), self:GetBladeWidth(), clr, self:GetDarkInner(), self:EntIndex(), self:GetOwner():WaterLevel() > 2, false, blades )
  1022. bladesFound = true
  1023. end
  1024.  
  1025. if ( quillonNum && self:LookupAttachment( "quillon" .. quillonNum ) > 0 ) then
  1026. blades = blades + 1
  1027. local pos, dir = self:GetSaberPosAng( quillonNum, true )
  1028. rb655_RenderBlade( pos, dir, self:GetBladeLength(), self:GetMaxLength(), self:GetBladeWidth(), clr, self:GetDarkInner(), self:EntIndex(), self:GetOwner():WaterLevel() > 2, true, blades )
  1029. end
  1030.  
  1031. end
  1032.  
  1033. if ( !bladesFound ) then
  1034. local pos, dir = self:GetSaberPosAng()
  1035. rb655_RenderBlade( pos, dir, self:GetBladeLength(), self:GetMaxLength(), self:GetBladeWidth(), clr, self:GetDarkInner(), self:EntIndex(), self:GetOwner():WaterLevel() > 2 )
  1036. end
  1037. end
  1038.  
  1039. /* --------------------------------------------------------- 3rd Person Camera --------------------------------------------------------- */
  1040.  
  1041. /*
  1042. hook.Add( "ShouldDrawLocalPlayer", "rb655_lightsaber_weapon_draw", function()
  1043. if ( IsValid( LocalPlayer() ) && LocalPlayer().GetActiveWeapon && IsValid( LocalPlayer():GetActiveWeapon() ) && LocalPlayer():GetActiveWeapon():GetClass() == "weapon_lightsaber" && !LocalPlayer():InVehicle() && LocalPlayer():Alive() && LocalPlayer():GetViewEntity() == LocalPlayer() ) then return true end
  1044. end )
  1045.  
  1046. function SWEP:CalcView( ply, pos, ang, fov )
  1047. if ( !IsValid( ply ) || !ply:Alive() || ply:InVehicle() || ply:GetViewEntity() != ply ) then return end
  1048.  
  1049. local trace = util.TraceHull( {
  1050. start = pos,
  1051. endpos = pos - ang:Forward() * 100,
  1052. filter = { ply:GetActiveWeapon(), ply },
  1053. mins = Vector( -4, -4, -4 ),
  1054. maxs = Vector( 4, 4, 4 ),
  1055. } )
  1056.  
  1057. if ( trace.Hit ) then pos = trace.HitPos else pos = pos - ang:Forward() * 100 end
  1058.  
  1059. return pos, ang, fov
  1060. end*/
  1061.  
  1062. local isCalcViewFuckedUp2 = true
  1063. hook.Add( "CalcView", "!!!111_rb655_lightsaber_3rdperson", function( ply, pos, ang )
  1064. if ( !IsValid( ply ) || !ply:Alive() || ply:InVehicle() || ply:GetViewEntity() != ply ) then return end
  1065. if ( !LocalPlayer().GetActiveWeapon || !IsValid( LocalPlayer():GetActiveWeapon() ) || LocalPlayer():GetActiveWeapon():GetClass() != "weapon_lightsaber" ) then return end
  1066.  
  1067. isCalcViewFuckedUp2 = false
  1068.  
  1069. local trace = util.TraceHull( {
  1070. start = pos,
  1071. endpos = pos - ang:Forward() * 100,
  1072. filter = { ply:GetActiveWeapon(), ply },
  1073. mins = Vector( -4, -4, -4 ),
  1074. maxs = Vector( 4, 4, 4 ),
  1075. } )
  1076.  
  1077. if ( trace.Hit ) then pos = trace.HitPos else pos = pos - ang:Forward() * 100 end
  1078.  
  1079. return {
  1080. origin = pos,
  1081. angles = ang,
  1082. drawviewer = true
  1083. }
  1084. end )
  1085.  
  1086. /* --------------------------------------------------------- HUD --------------------------------------------------------- */
  1087.  
  1088. surface.CreateFont( "SelectedForceType", {
  1089. font = "Roboto Cn",
  1090. size = ScreenScale( 16 ),
  1091. weight = 600
  1092. } )
  1093.  
  1094. surface.CreateFont( "SelectedForceHUD", {
  1095. font = "Roboto Cn",
  1096. size = ScreenScale( 6 )
  1097. } )
  1098.  
  1099. local ForceSelectEnabled = false
  1100. hook.Add( "PlayerBindPress", "rb655_sabers_force", function( ply, bind, pressed )
  1101. if ( LocalPlayer():InVehicle() || ply != LocalPlayer() || !LocalPlayer():Alive() || !IsValid( LocalPlayer():GetActiveWeapon() ) || LocalPlayer():GetActiveWeapon():GetClass() != "weapon_lightsaber" ) then ForceSelectEnabled = false return end
  1102.  
  1103. if ( bind == "impulse 100" && pressed ) then
  1104. ForceSelectEnabled = !ForceSelectEnabled
  1105. return true
  1106. end
  1107.  
  1108. if ( !ForceSelectEnabled ) then return end
  1109.  
  1110. if ( bind:StartWith( "slot" ) ) then
  1111. RunConsoleCommand( "rb655_select_force", bind:sub( 5 ) )
  1112. return true
  1113. end
  1114. end )
  1115.  
  1116. local rb655_lightsaber_hud_blur = CreateClientConVar( "rb655_lightsaber_hud_blur", "0" )
  1117.  
  1118. local grad = Material( "gui/gradient_up" )
  1119. local matBlurScreen = Material( "pp/blurscreen" )
  1120. matBlurScreen:SetFloat( "$blur", 3 )
  1121. matBlurScreen:Recompute()
  1122. local function DrawHUDBox( x, y, w, h, b )
  1123.  
  1124. x = math.floor( x )
  1125. y = math.floor( y )
  1126. w = math.floor( w )
  1127. h = math.floor( h )
  1128.  
  1129. surface.SetMaterial( matBlurScreen )
  1130. surface.SetDrawColor( 255, 255, 255, 255 )
  1131.  
  1132. if ( rb655_lightsaber_hud_blur:GetBool() ) then
  1133. render.SetScissorRect( x, y, w + x, h + y, true )
  1134. for i = 0.33, 1, 0.33 do
  1135. matBlurScreen:SetFloat( "$blur", 5 * i )
  1136. matBlurScreen:Recompute()
  1137. render.UpdateScreenEffectTexture()
  1138. surface.DrawTexturedRect( 0, 0, ScrW(), ScrH() )
  1139. end
  1140. render.SetScissorRect( 0, 0, 0, 0, false )
  1141. else
  1142. draw.NoTexture()
  1143. surface.SetDrawColor( Color( 0, 0, 0, 128 ) )
  1144. surface.DrawTexturedRect( x, y, w, h )
  1145. end
  1146.  
  1147. surface.SetDrawColor( Color( 0, 0, 0, 128 ) )
  1148. surface.DrawRect( x, y, w, h )
  1149.  
  1150. if ( b ) then
  1151. surface.SetMaterial( grad )
  1152. surface.SetDrawColor( Color( 0, 128, 255, 4 ) )
  1153. surface.DrawTexturedRect( x, y, w, h )
  1154. end
  1155.  
  1156. end
  1157.  
  1158. local isCalcViewFuckedUp = true
  1159. function SWEP:ViewModelDrawn()
  1160. isCalcViewFuckedUp = true -- Clever girl!
  1161. end
  1162.  
  1163. local boneInfo = {}
  1164. net.Receive( "hax", function()
  1165. boneInfo = net.ReadTable()
  1166. end )
  1167.  
  1168.  
  1169. local ForceBar = 100
  1170. function SWEP:DrawHUD()
  1171. if ( !IsValid( self.Owner ) || self.Owner:GetViewEntity() != self.Owner || self.Owner:InVehicle() ) then return end
  1172.  
  1173. -----------------------------------
  1174.  
  1175. local icon = 52
  1176. local gap = 5
  1177.  
  1178. local bar = 4
  1179. local bar2 = 16
  1180.  
  1181. if ( ForceSelectEnabled ) then
  1182. icon = 128
  1183. bar = 8
  1184. bar2 = 24
  1185. end
  1186.  
  1187. ----------------------------------- Force Bar -----------------------------------
  1188.  
  1189. ForceBar = math.min( 100, Lerp( 0.1, ForceBar, math.floor( self:GetForce() ) ) )
  1190.  
  1191. local w = #self.ForcePowers * icon + ( #self.ForcePowers - 1 ) * gap
  1192. local h = bar2
  1193. local x = math.floor( ScrW() / 2 - w / 2 )
  1194. local y = ScrH() - gap - bar2
  1195.  
  1196. DrawHUDBox( x, y, w, h )
  1197.  
  1198. local barW = math.ceil( w * ( ForceBar / 100 ) )
  1199. if ( self:GetForce() <= 1 && barW <= 1 ) then barW = 0 end
  1200. draw.RoundedBox( 0, x, y, barW, h, Color( 0, 128, 255, 255 ) )
  1201.  
  1202. draw.SimpleText( math.floor( self:GetForce() ) .. "%", "SelectedForceHUD", x + w / 2, y + h / 2, Color( 255, 255, 255 ), 1, 1 )
  1203.  
  1204. ----------------------------------- Force Icons -----------------------------------
  1205.  
  1206. local y = y - icon - gap
  1207. local h = icon
  1208.  
  1209. for id, t in pairs( self.ForcePowers ) do
  1210. local x = x + ( id - 1 ) * ( h + gap )
  1211. local x2 = math.floor( x + icon / 2 )
  1212.  
  1213. DrawHUDBox( x, y, h, h, self:GetForceType() == id )
  1214. draw.SimpleText( self.ForcePowers[ id ].icon || "", "SelectedForceType", x2, math.floor( y + icon / 2 ), Color( 255, 255, 255 ), 1, 1 )
  1215. if ( ForceSelectEnabled ) then
  1216. draw.SimpleText( ( input.LookupBinding( "slot" .. id ) || "<NOT BOUND>" ):upper(), "SelectedForceHUD", x + gap, y + gap, Color( 255, 255, 255 ) )
  1217. end
  1218. if ( self:GetForceType() == id ) then
  1219. local y = y + ( icon - bar )
  1220. surface.SetDrawColor( 0, 128, 255, 255 )
  1221. draw.NoTexture()
  1222. surface.DrawPoly( {
  1223. { x = x2 - bar, y = y },
  1224. { x = x2, y = y - bar },
  1225. { x = x2 + bar, y = y }
  1226. } )
  1227. draw.RoundedBox( 0, x, y, h, bar, Color( 0, 128, 255, 255 ) )
  1228. end
  1229. end
  1230.  
  1231. ----------------------------------- Force Description -----------------------------------
  1232.  
  1233. if ( ForceSelectEnabled ) then
  1234.  
  1235. surface.SetFont( "SelectedForceHUD" )
  1236. local tW, tH = surface.GetTextSize( self.ForcePowers[ self:GetForceType() ].description || "" )
  1237.  
  1238. /*local x = x + w + gap
  1239. local y = y*/
  1240. local x = ScrW() / 2 + gap// - tW / 2
  1241. local y = y - tH - gap * 3
  1242.  
  1243. DrawHUDBox( x, y, tW + gap * 2, tH + gap * 2 )
  1244.  
  1245. for id, txt in pairs( string.Explode( "\n", self.ForcePowers[ self:GetForceType() ].description || "" ) ) do
  1246. draw.SimpleText( txt, "SelectedForceHUD", x + gap, y + ( id - 1 ) * ScreenScale( 6 ) + gap, Color( 255, 255, 255 ) )
  1247. end
  1248.  
  1249. end
  1250.  
  1251. ----------------------------------- Force Label -----------------------------------
  1252.  
  1253. if ( !ForceSelectEnabled ) then
  1254. surface.SetFont( "SelectedForceHUD" )
  1255. local txt = "Press " .. ( input.LookupBinding( "impulse 100" ) || "<NOT BOUND>" ):upper() .. " to toggle Force selection"
  1256. local tW, tH = surface.GetTextSize( txt )
  1257.  
  1258. local x = x + w / 2
  1259. local y = y - tH - gap
  1260.  
  1261. DrawHUDBox( x - tW / 2 - 5, y, tW + 10, tH )
  1262. draw.SimpleText( txt, "SelectedForceHUD", x, y, Color( 255, 255, 255 ), 1 )
  1263.  
  1264. local isGood = hook.Call( "PlayerBindPress", nil, LocalPlayer(), "this_bind_doesnt_exist", true )
  1265. if ( isGood == true ) then
  1266. local txt = "Some addon is breaking the PlayerBindPress hook. Send a screenshot of this error to the mod page!"
  1267. for name, func in pairs( hook.GetTable()[ "PlayerBindPress" ] ) do txt = txt .. "\n" .. tostring( name ) end
  1268. local tW, tH = surface.GetTextSize( txt )
  1269.  
  1270. y = y - tH - gap
  1271.  
  1272. local id = 1
  1273. DrawHUDBox( x - tW / 2 - 5, y, tW + 10, tH )
  1274. draw.SimpleText( string.Explode( "\n", txt )[ 1 ], "SelectedForceHUD", x, y + 0, Color( 255, 230, 230 ), 1 )
  1275.  
  1276. for str, func in pairs( hook.GetTable()[ "PlayerBindPress" ] ) do
  1277. local clr = Color( 255, 255, 128 )
  1278. if ( ( isstring( str ) && func( LocalPlayer(), "this_bind_doesnt_exist", true ) == true ) || ( !isstring( str ) && func( str, LocalPlayer(), "this_bind_doesnt_exist", true ) == true ) ) then
  1279. clr = Color( 255, 128, 128 )
  1280. end
  1281. if ( !isstring( str ) ) then str = tostring( str ) end
  1282. if ( str == "" ) then str = "<empty string hook>" end
  1283. local _, lineH = surface.GetTextSize( str )
  1284. draw.SimpleText( str, "SelectedForceHUD", x, y + id * lineH, clr, 1 )
  1285. id = id + 1
  1286. end
  1287. end
  1288.  
  1289. if ( isCalcViewFuckedUp || isCalcViewFuckedUp2 ) then
  1290. local txt = "Some addon is breaking the CalcView hook. Send a screenshot of this error to the mod page!"
  1291. for name, func in pairs( hook.GetTable()[ "CalcView" ] ) do txt = txt .. "\n" .. tostring( name ) end
  1292. local tW, tH = surface.GetTextSize( txt )
  1293.  
  1294. y = y - tH - gap
  1295.  
  1296. local id = 1
  1297. DrawHUDBox( x - tW / 2 - 5, y, tW + 10, tH )
  1298. draw.SimpleText( string.Explode( "\n", txt )[ 1 ], "SelectedForceHUD", x, y + 0, Color( 255, 230, 230 ), 1 )
  1299.  
  1300. for str, func in pairs( hook.GetTable()[ "CalcView" ] ) do
  1301. local clr = Color( 255, 255, 128 )
  1302. if ( ( isstring( str ) && func( LocalPlayer(), EyePos(), EyeAngles(), 90, 4, 16000 ) != nil ) || ( !isstring( str ) && func( str, LocalPlayer(), EyePos(), EyeAngles(), 90, 4, 16000 ) != nil ) ) then
  1303. clr = Color( 255, 128, 128 )
  1304. end
  1305. if ( !isstring( str ) ) then str = tostring( str ) end
  1306. if ( str == "" ) then str = "<empty string hook>" end
  1307. local _, lineH = surface.GetTextSize( str )
  1308. draw.SimpleText( str, "SelectedForceHUD", x, y + id * lineH, clr, 1 )
  1309. id = id + 1
  1310. end
  1311.  
  1312. isCalcViewFuckedUp = false
  1313. end
  1314.  
  1315. if ( !isCalcViewFuckedUp2 ) then
  1316. isCalcViewFuckedUp2 = true
  1317. end
  1318.  
  1319. if ( self:GetIncorrectPlayerModel() != 0 ) then
  1320. local txt = "Server is missing the player model or missing owner! Send a screenshot of this error to the mod page!\nPlayer model: " .. self.Owner:GetModel() .. " - Error Code: " .. self:GetIncorrectPlayerModel()
  1321. local tW, tH = surface.GetTextSize( txt )
  1322.  
  1323. y = y - tH - gap
  1324.  
  1325. DrawHUDBox( x - tW / 2 - 5, y, tW + 10, tH )
  1326. for id, str in pairs( string.Explode( "\n", txt ) ) do
  1327. local _, lineH = surface.GetTextSize( str )
  1328. draw.SimpleText( str, "SelectedForceHUD", x, y + ( id - 1 ) * lineH, Color( 255, 200, 200 ), 1 )
  1329. end
  1330. end
  1331. end
  1332.  
  1333. if ( ForceSelectEnabled ) then
  1334. surface.SetFont( "SelectedForceType" )
  1335. local txt = self.ForcePowers[ self:GetForceType() ].name or ""
  1336. local tW2, tH2 = surface.GetTextSize( txt )
  1337.  
  1338. local x = x + w / 2 - tW2 - gap * 2//+ w / 2
  1339. local y = y + gap - tH2 - gap * 2
  1340.  
  1341. DrawHUDBox( x, y, tW2 + 10, tH2 )
  1342. draw.SimpleText( txt, "SelectedForceType", x + gap, y, Color( 255, 255, 255 ) )
  1343. end
  1344.  
  1345. ----------------------------------- Force Target -----------------------------------
  1346.  
  1347. local isTarget = self.ForcePowers[ self:GetForceType() ].target
  1348.  
  1349. if ( isTarget ) then
  1350. for id, ent in pairs( self:SelectTargets( isTarget ) ) do
  1351. if ( !IsValid( ent ) ) then continue end
  1352. local maxs = ent:OBBMaxs()
  1353. local p = ent:GetPos()
  1354. p.z = p.z + maxs.z
  1355.  
  1356. local pos = p:ToScreen()
  1357. local x, y = pos.x, pos.y
  1358. local size = 16
  1359.  
  1360. surface.SetDrawColor( 255, 0, 0, 255 )
  1361. draw.NoTexture()
  1362. surface.DrawPoly( {
  1363. { x = x - size, y = y - size },
  1364. { x = x + size, y = y - size },
  1365. { x = x, y = y }
  1366. } )
  1367. end
  1368. end
  1369.  
  1370. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement