Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[-------------------------------------------------------------------
- Modified Lightsaber:
- Runs on the intuitive wOS Lightsaber Base
- Powered by
- _ _ _ ___ ____
- __ _(_) | |_ / _ \/ ___|
- \ \ /\ / / | | __| | | \___ \
- \ V V /| | | |_| |_| |___) |
- \_/\_/ |_|_|\__|\___/|____/
- _____ _ _ _
- |_ _|__ ___| |__ _ __ ___ | | ___ __ _(_) ___ ___
- | |/ _ \/ __| '_ \| '_ \ / _ \| |/ _ \ / _` | |/ _ \/ __|
- | | __/ (__| | | | | | | (_) | | (_) | (_| | | __/\__ \
- |_|\___|\___|_| |_|_| |_|\___/|_|\___/ \__, |_|\___||___/
- |___/
- ----------------------------- Copyright 2017, David "King David" Wiltos ]]--[[
- Lua Developer: King David
- Contact: http://steamcommunity.com/groups/wiltostech
- -- Copyright 2017, David "King David" Wiltos ]]--
- AddCSLuaFile()
- SWEP.Base = "weapon_lightsaber"
- SWEP.WeaponSynched = true
- SWEP.PrintName = "Training Saber"
- SWEP.Author = "Robotboy655 + King David"
- SWEP.Category = "wiltOS Technologies"
- SWEP.Contact = ""
- SWEP.Purpose = "To train in the ways of lightsaber combat."
- SWEP.Instructions = "Harden your drive."
- SWEP.RenderGroup = RENDERGROUP_BOTH
- SWEP.Slot = 0
- SWEP.SlotPos = 4
- SWEP.Spawnable = true
- SWEP.DrawAmmo = false
- SWEP.DrawCrosshair = false
- SWEP.AutoSwitchTo = false
- SWEP.AutoSwitchFrom = false
- SWEP.DrawWeaponInfoBox = false
- SWEP.ViewModel = "models/weapons/v_crowbar.mdl"
- SWEP.WorldModel = "models/sgg/starwars/weapons/w_anakin_ep2_saber_hilt.mdl"
- SWEP.ViewModelFOV = 55
- SWEP.Primary.ClipSize = -1
- SWEP.Primary.DefaultClip = -1
- SWEP.Primary.Automatic = false
- SWEP.Primary.Ammo = "none"
- SWEP.Secondary.ClipSize = -1
- SWEP.Secondary.DefaultClip = -1
- SWEP.Secondary.Automatic = true
- SWEP.Secondary.Ammo = "none"
- SWEP.HoldType = "bs-arrogant-balanced"
- SWEP.IsLightsaber = true
- SWEP.ForceSelectEnabled = false
- function SWEP:PrimaryAttack()
- if ( !IsValid( self.Owner ) ) then return end
- self:SetNextAttack( 1 )
- if ( !self.Owner:IsNPC() && self:GetEnabled() ) then
- self.Owner:AnimResetGestureSlot( GESTURE_SLOT_CUSTOM )
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
- end
- end
- function SWEP:GetTargetHoldType()
- return "bs-arrogant-balanced"
- end
- if SERVER then return end
- local rb655_lightsaber_hud_blur = CreateClientConVar( "rb655_lightsaber_hud_blur", "0" )
- local grad = Material( "gui/gradient_up" )
- local matBlurScreen = Material( "pp/blurscreen" )
- matBlurScreen:SetFloat( "$blur", 3 )
- matBlurScreen:Recompute()
- local function DrawHUDBox( x, y, w, h, b )
- x = math.floor( x )
- y = math.floor( y )
- w = math.floor( w )
- h = math.floor( h )
- surface.SetMaterial( matBlurScreen )
- surface.SetDrawColor( 255, 255, 255, 255 )
- if ( rb655_lightsaber_hud_blur:GetBool() ) then
- render.SetScissorRect( x, y, w + x, h + y, true )
- for i = 0.33, 1, 0.33 do
- matBlurScreen:SetFloat( "$blur", 5 * i )
- matBlurScreen:Recompute()
- render.UpdateScreenEffectTexture()
- surface.DrawTexturedRect( 0, 0, ScrW(), ScrH() )
- end
- render.SetScissorRect( 0, 0, 0, 0, false )
- else
- draw.NoTexture()
- surface.SetDrawColor( Color( 0, 0, 0, 128 ) )
- surface.DrawTexturedRect( x, y, w, h )
- end
- surface.SetDrawColor( Color( 0, 0, 0, 128 ) )
- surface.DrawRect( x, y, w, h )
- if ( b ) then
- surface.SetMaterial( grad )
- surface.SetDrawColor( Color( 0, 128, 255, 4 ) )
- surface.DrawTexturedRect( x, y, w, h )
- end
- end
- local ForceBar = 100
- function SWEP:DrawHUD()
- if ( !IsValid( self.Owner ) or self.Owner:GetViewEntity() != self.Owner or self.Owner:InVehicle() ) then return end
- -----------------------------------
- local icon = 52
- local gap = 5
- local bar = 4
- local bar2 = 16
- if ( self.ForceSelectEnabled ) then
- icon = 128
- bar = 8
- bar2 = 24
- end
- local ForcePowers = self:GetActiveForcePowers()
- if ( #ForcePowers < 1 ) then self:DrawHUDTargetSelection() return end
- ----------------------------------- Force Bar -----------------------------------
- ForceBar = math.min( 100, Lerp( 0.1, ForceBar, math.floor( self:GetForce() ) ) )
- local w = #ForcePowers * icon + ( #ForcePowers - 1 ) * gap
- local h = bar2
- local x = math.floor( ScrW() / 2 - w / 2 )
- local y = ScrH() - gap - bar2
- DrawHUDBox( x, y, w, h )
- local barW = math.ceil( w * ( ForceBar / 100 ) )
- if ( self:GetForce() <= 1 && barW <= 1 ) then barW = 0 end
- draw.RoundedBox( 0, x, y, barW, h, Color( 0, 128, 255, 255 ) )
- draw.SimpleText( math.floor( self:GetForce() ) .. "%", "SelectedForceHUD", x + w / 2, y + h / 2, Color( 255, 255, 255 ), 1, 1 )
- ----------------------------------- Force Icons -----------------------------------
- local y = y - icon - gap
- local h = icon
- for id, t in pairs( ForcePowers ) do
- local x = x + ( id - 1 ) * ( h + gap )
- local x2 = math.floor( x + icon / 2 )
- DrawHUDBox( x, y, h, h, self:GetForceType() == id )
- draw.SimpleText( t.icon or "", "SelectedForceType", x2, math.floor( y + icon / 2 ), Color( 255, 255, 255 ), 1, 1 )
- if ( self.ForceSelectEnabled ) then
- draw.SimpleText( ( input.LookupBinding( "slot" .. id ) or "<NOT BOUND>" ):upper(), "SelectedForceHUD", x + gap, y + gap, Color( 255, 255, 255 ) )
- end
- if ( self:GetForceType() == id ) then
- local y = y + ( icon - bar )
- surface.SetDrawColor( 0, 128, 255, 255 )
- draw.NoTexture()
- surface.DrawPoly( {
- { x = x2 - bar, y = y },
- { x = x2, y = y - bar },
- { x = x2 + bar, y = y }
- } )
- draw.RoundedBox( 0, x, y, h, bar, Color( 0, 128, 255, 255 ) )
- end
- end
- ----------------------------------- Force Description -----------------------------------
- local selectedForcePower = self:GetActiveForcePowerType( self:GetForceType() )
- if ( selectedForcePower && self.ForceSelectEnabled ) then
- surface.SetFont( "SelectedForceHUD" )
- local tW, tH = surface.GetTextSize( selectedForcePower.description or "" )
- --[[local x = x + w + gap
- local y = y]]
- local x = ScrW() / 2 + gap-- - tW / 2
- local y = y - tH - gap * 3
- DrawHUDBox( x, y, tW + gap * 2, tH + gap * 2 )
- for id, txt in pairs( string.Explode( "\n", selectedForcePower.description or "" ) ) do
- draw.SimpleText( txt, "SelectedForceHUD", x + gap, y + ( id - 1 ) * ScreenScale( 6 ) + gap, Color( 255, 255, 255 ) )
- end
- end
- ----------------------------------- Force Label -----------------------------------
- if ( !self.ForceSelectEnabled ) then
- surface.SetFont( "SelectedForceHUD" )
- local txt = "Press " .. ( input.LookupBinding( "impulse 100" ) or "<NOT BOUND>" ):upper() .. " to toggle Force selection"
- local tW, tH = surface.GetTextSize( txt )
- local x = x + w / 2
- local y = y - tH - gap
- DrawHUDBox( x - tW / 2 - 5, y, tW + 10, tH )
- draw.SimpleText( txt, "SelectedForceHUD", x, y, Color( 255, 255, 255 ), 1 )
- if ( self:GetIncorrectPlayerModel() != 0 ) then
- 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()
- local tW, tH = surface.GetTextSize( txt )
- y = y - tH - gap
- DrawHUDBox( x - tW / 2 - 5, y, tW + 10, tH )
- for id, str in pairs( string.Explode( "\n", txt ) ) do
- local _, lineH = surface.GetTextSize( str )
- draw.SimpleText( str, "SelectedForceHUD", x, y + ( id - 1 ) * lineH, Color( 255, 200, 200 ), 1 )
- end
- end
- end
- if ( selectedForcePower && self.ForceSelectEnabled ) then
- surface.SetFont( "SelectedForceType" )
- local txt = selectedForcePower.name or ""
- local tW2, tH2 = surface.GetTextSize( txt )
- local x = x + w / 2 - tW2 - gap * 2 --+ w / 2
- local y = y + gap - tH2 - gap * 2
- DrawHUDBox( x, y, tW2 + 10, tH2 )
- draw.SimpleText( txt, "SelectedForceType", x + gap, y, Color( 255, 255, 255 ) )
- end
- ----------------------------------- Force Target -----------------------------------
- self:DrawHUDTargetSelection()
- end
- function SWEP:PlayWeaponSound( snd )
- if ( CLIENT ) then return end
- if ( IsValid( self:GetOwner() ) && IsValid( self:GetOwner():GetActiveWeapon() ) && self:GetOwner():GetActiveWeapon() != self ) then return end
- if ( !IsValid( self.Owner ) ) then return self:EmitSound( snd ) end
- self.Owner:EmitSound( snd )
- end
- function SWEP:SelectTargets( num )
- local t = {}
- local dist = 512
- --[[local tr = util.TraceLine( {
- start = self.Owner:GetShootPos(),
- endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * dist,
- filter = self.Owner
- } )]]
- local p = {}
- for id, ply in pairs( ents.GetAll() ) do
- if ( !ply:GetModel() or ply:GetModel() == "" or ply == self.Owner or ply:Health() < 1 ) then continue end
- if ( string.StartWith( ply:GetModel() or "", "models/gibs/" ) ) then continue end
- if ( string.find( ply:GetModel() or "", "chunk" ) ) then continue end
- if ( string.find( ply:GetModel() or "", "_shard" ) ) then continue end
- if ( string.find( ply:GetModel() or "", "_splinters" ) ) then continue end
- local tr = util.TraceLine( {
- start = self.Owner:GetShootPos(),
- endpos = ply.GetShootPos && ply:GetShootPos() or ply:GetPos(),
- filter = self.Owner,
- } )
- if ( tr.Entity != ply && IsValid( tr.Entity ) or tr.Entity == game.GetWorld() ) then continue end
- local pos1 = self.Owner:GetPos() + self.Owner:GetAimVector() * dist
- local pos2 = ply:GetPos()
- local dot = self.Owner:GetAimVector():Dot( ( self.Owner:GetPos() - pos2 ):GetNormalized() )
- if ( pos1:Distance( pos2 ) <= dist && ply:EntIndex() > 0 && ply:GetModel() && ply:GetModel() != "" ) then
- table.insert( p, { ply = ply, dist = tr.HitPos:Distance( pos2 ), dot = dot, score = -dot + ( ( dist - pos1:Distance( pos2 ) ) / dist ) * 50 } )
- end
- end
- for id, ply in SortedPairsByMemberValue( p, "dist" ) do
- table.insert( t, ply.ply )
- if ( #t >= num ) then return t end
- end
- return t
- end
- ----------------------------------- Initialize -----------------------------------
- function SWEP:LoadToolValues( ply )
- local maxLen = ply:GetInfoNum( "rb655_lightsaber_bladel", 42 )
- local bldWidth = ply:GetInfoNum( "rb655_lightsaber_bladew", 2 )
- local Vector = ply:GetInfoNum( "rb655_lightsaber_red", 255 ), ply:GetInfoNum( "rb655_lightsaber_green", 0 ), ply:GetInfoNum( "rb655_lightsaber_blue", 0 )
- local WorldModel = ply:GetInfoNum ( "rb655_lightsaber_model", "models/training/training.mdl" )
- self:SetMaxLength( maxLen )
- self:SetBladeWidth( bldWidth )
- self:SetCrystalColor( Vector( ply:GetInfo( "rb655_lightsaber_red" ), ply:GetInfo( "rb655_lightsaber_green" ), ply:GetInfo( "rb655_lightsaber_blue" ) ) )
- self:SetDarkInner( ply:GetInfo( "rb655_lightsaber_dark" ) == "1" )
- self:SetWorldModel( ply:GetInfo( "rb655_lightsaber_model" ) )
- self:SetModel( self:GetWorldModel() )
- self.WorldModel = self:GetWorldModel()
- --self:PhysicsInit( SOLID_VPHYSICS )
- self.LoopSound = ply:GetInfo( "rb655_lightsaber_humsound" )
- self.SwingSound = ply:GetInfo( "rb655_lightsaber_swingsound" )
- self:SetOnSound( ply:GetInfo( "rb655_lightsaber_onsound" ) )
- self:SetOffSound( ply:GetInfo( "rb655_lightsaber_offsound" ) )
- --self:SetEnabled( ply:GetInfo( "rb655_lightsaber_starton" ) )
- self.WeaponSynched = true
- -- Start it if we spawned it using the spawnmenu!
- if ( !IsValid( self.Owner ) || self.Owner:IsPlayer() ) then
- -- Gotta wait a tick so we don't play double sounds!
- timer.Simple( 0, function() if ( !IsValid( self ) ) then return end self:SetEnabled( false ) end )
- end
- end
- hook.Add( "PlayerSpawnedSWEP", "rb655_lightsaber_swep_sync", function( ply, wep )
- if ( !rb655_IsLightsaber( wep ) ) then return end
- wep:LoadToolValues( ply )
- end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement