Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[this goes in your server's lua/autorun]]--
- local MapName = string.lower( game.GetMap() )
- if( CLIENT ) then
- if not( ( string.find( MapName, "downtown" ) or string.find( MapName, "propkillcity" ) ) ) then MsgC( Color( 0, 255, 20 ), "\n\n_____________________________\n\nWRONG MAP, PK MINIMAP DISABLED\n_____________________________\n\n\n" ) return end
- else
- AddCSLuaFile()
- hook.Add( "PlayerSpawnedProp", "setpropowners", function( ply, _, ent )
- if not( IsValid( ply ) and IsValid( ent ) ) then return end
- ent:SetNWEntity( "Owner", ply )
- end )
- return
- end
- local Map = {
- PropHolos = {},
- Active = false,
- LastFrame = 69,
- PlayerHolos = {},
- MinimapScale = 4,
- GeneralSpeed = 500,
- DumbfoundedSpeed = 8,
- MaxBounds = Vector( -2920, -789, 170 ),
- MinBounds = Vector( -5492, -2808, -550 ),
- MinimapOrigin = Vector( -4242.35, -1717.83, -438 ),
- Mat = CreateMaterial( "White9", "UnlitGeneric", { ["$basetexture"] = "models/debug/debugwhite", ["$nocull"] = 1, ["$model"] = 1 } ),
- }
- --i have no idea how to test if this actually makes anything faster or not but the thought process behind it makes sense so it's happening
- local MsgN = MsgN
- local Color = Color
- local pairs = pairs
- local Angle = Angle
- local Exp = math.exp
- local Vector = Vector
- local CurTime = CurTime
- local IsValid = IsValid
- local End3D = cam.End3D
- local Clamp = math.Clamp
- local Material = Material
- local TimedSin = TimedSin
- local PGA = player.GetAll
- local TableAdd = table.Add
- local Start3D = cam.Start3D
- local IgnoreZ = cam.IgnoreZ
- local TeamCol = team.GetColor
- local TableCount = table.Count
- local LocalPlayer = LocalPlayer
- local DrawBeam = render.DrawBeam
- local SetBlend = render.SetBlend
- local SetMat = render.SetMaterial
- local FindByClass = ents.FindByClass
- local ClientProp = ents.CreateClientProp
- local ColorMod = render.SetColorModulation
- local MatOverride = render.MaterialOverride
- local DrawTextOutlined = draw.SimpleTextOutlined
- local SuppressLighting = render.SuppressEngineLighting
- surface.CreateFont( "MinimapFont", { font = "coolvetica", size = 35, antialias = true } )
- local function InMapRoom( ply )
- if( !ply ) then ply = LocalPlayer() end
- local pos = ply:GetPos() +Vector( 0, 0, 70 )
- return( pos.x >Map.MinBounds.x and pos.x <Map.MaxBounds.x and pos.y >Map.MinBounds.y and pos.y <Map.MaxBounds.y and pos.z >Map.MinBounds.z and pos.z <Map.MaxBounds.z )
- end
- local function GetMPos( Vec )
- return( Map.MinimapOrigin +( Vec /Map.MinimapScale ) )
- end
- local function CreateHolo( mdl )
- local Holo = ClientProp( mdl )
- Holo:SetModelScale( 1 / Map.MinimapScale, 0 )
- Holo.NoDraw = true
- Holo:SetNoDraw( true )
- return Holo
- end
- local function CleanTable( Filthy )
- local Clean = {}
- for k,v in pairs( Filthy ) do
- if not( IsValid( k ) and !InMapRoom( k ) and IsValid( v ) ) then continue end
- Clean[k] = v
- end
- return Clean
- end
- local function CombinedHoloTable( ReverseKV )
- local tbl = {}
- for k,v in pairs( Map.PlayerHolos ) do
- if( ReverseKV ) then
- tbl[v] = true--so i can check if the holo exists as a key instead of using table.HasValue which is slow and gay
- else
- tbl[k] = v
- end
- end
- for k,v in pairs( Map.PropHolos ) do
- if( ReverseKV ) then
- tbl[v] = true
- else
- tbl[k] = v
- end
- end
- return tbl
- end
- local function UnfuckStuckHolos()
- local ValidHolos = CombinedHoloTable( true )
- local AllHolos = FindByClass( "class C_PhysPropClientside" )
- TableAdd( AllHolos, FindByClass( "C_BaseFlex" ) )
- if( TableCount( ValidHolos ) == #AllHolos ) then return end
- for _,v in pairs( AllHolos ) do
- if not( IsValid( v ) and !ValidHolos[v] ) then continue end
- v:Remove()
- end
- end
- UnfuckStuckHolos()
- local function ResetMinimap()--reset and disable the map for people outside the map room
- Map.PropHolos = {}
- Map.PlayerHolos = {}
- UnfuckStuckHolos()
- for _,v in pairs( PGA() ) do
- v.HeldProp = nil
- end
- Map.Active = false
- end
- local function BeamWidth( Start, End )
- if not( IsValid( LocalPlayer() ) ) then return end
- return util.DistanceToLine( Start, End, LocalPlayer():GetShootPos() ) /90
- end
- hook.Add( "Think", "Minimap_CreateHolos", function()
- if( Map.Active ) then
- if( !InMapRoom() ) then
- ResetMinimap()
- -- LocalPlayer():ChatPrint( "DISABLED MAP" )
- return
- end
- else
- if( InMapRoom() ) then
- Map.Active = true
- -- LocalPlayer():ChatPrint( "ENABLED MAP" )
- end
- end
- for _,v in pairs( PGA() ) do
- if not( IsValid( v ) ) then continue end
- --player holos
- if( !Map.PlayerHolos[v] ) then
- Map.PlayerHolos[v] = CreateHolo( v:GetModel() )
- --MsgN( "CREATED HOLO PLAYER FOR "..v:Nick()..", "..v:GetModel() )
- end
- --physgun holos
- if( IsValid( v:GetActiveWeapon() ) and v:GetActiveWeapon():GetClass() == "weapon_physgun" and v:LookupBone( "ValveBiped.Bip01_R_Hand" ) ) then
- if( !v.Physgun or !IsValid( v.Physgun ) ) then
- v.Physgun = CreateHolo( "models/weapons/w_physics.mdl" )
- -- MsgN( "CREATED HOLO PHYSGUN FOR "..v:Nick() )
- end
- elseif( IsValid( v.Physgun ) ) then
- v.Physgun:Remove()
- --MsgN( "REMOVED HOLO PHYSGUN FOR "..v:Nick() )
- end
- end
- --prop holos
- for _,v in pairs( FindByClass( "prop_physics" ) ) do
- if not( IsValid( v ) and !Map.PropHolos[v] ) then continue end
- Map.PropHolos[v] = CreateHolo( v:GetModel() )
- --MsgN( "CREATED HOLO PROP: "..v:GetModel() )
- end
- Map.PropHolos = CleanTable( Map.PropHolos )
- UnfuckStuckHolos()
- end )
- hook.Add( "PostDrawHUD", "Minimap_DrawHolos", function()
- if( !Map.Active ) then return end
- local CT = CurTime()
- --animate player holos
- Map.PlayerHolos = CleanTable( Map.PlayerHolos )
- for k,v in pairs( Map.PlayerHolos ) do
- local Seq = 2--best death animation, i call it the look-mum-no-hands-maximum-over-smackdown-mcfaceplant-3D
- local EA = k:EyeAngles()
- --animate physguns
- if( k.Physgun and IsValid( k.Physgun ) ) then
- if( !k.Pitch ) then k.Pitch = EA.p end
- if( EA.p <45 and EA.p >-15 ) then--math.Clamp made it flicker spastically
- k.Pitch = EA.p
- end
- k.Physgun:SetPos( GetMPos( k:GetBonePosition( k:LookupBone( "ValveBiped.Bip01_R_Hand" ) ) -EA:Forward() *2 ) )
- k.Physgun:SetAngles( Angle( k.Pitch, EA.y, 0 ) )
- end
- EA.p, EA.r = 0
- if( k:Health() >0 ) then
- k.FaceplantStart = nil
- v:SetPos( GetMPos( k:GetPos() ) )
- Seq = k:GetSequence()
- else
- if( !k.FaceplantStart ) then
- k.FaceplantStart = CT
- k.FaceplantY = EA.y
- end
- EA.p = Clamp( Exp( ( CT -k.FaceplantStart ) ^Map.DumbfoundedSpeed ) *Map.GeneralSpeed, 0, 90 +Map.GeneralSpeed ) -Map.GeneralSpeed
- EA.y = k.FaceplantY--stops player holos breakdancing if the player dies and starts looking around
- end
- v:InvalidateBoneCache()
- v:FrameAdvance( CT -Map.LastFrame )
- v:SetSequence( Seq )
- v:SetAngles( EA )
- for i=0,k:GetNumPoseParameters() -1 do
- local Pose = k:GetPoseParameterName( i )
- v:SetPoseParameter( Pose, k:GetPoseParameter( Pose ) )
- end
- end
- Map.LastFrame = CT
- --animate prop holos
- Map.PropHolos = CleanTable( Map.PropHolos )
- for k,v in pairs( Map.PropHolos ) do
- v:SetPos( GetMPos( k:GetPos() ) )
- v:SetAngles( k:GetAngles() )
- end
- --draw holos
- Start3D()
- IgnoreZ( true )
- MatOverride( Map.Mat )
- SuppressLighting( true )
- for k,v in pairs( CombinedHoloTable() ) do
- local Col
- local Blend = 1
- --players
- if( k:IsPlayer() ) then
- Col = k:Health() <1 and Color( TimedSin( 2, 170, 340, 1 ), 0, 0 ) or TeamCol( k:Team() )
- --physguns
- if( k.Physgun and IsValid( k.Physgun ) ) then
- ColorMod( 1, 1, 1 )
- k.Physgun:DrawModel()
- end
- --props
- else
- local Owner = k:GetNWEntity( "Owner" )
- if( !IsValid( Owner ) ) then continue end
- Col = Owner:Health() <1 and Color( TimedSin( 2, 170, 340, 1 ), 0, 0 ) or TeamCol( Owner:Team() )
- Blend = 0.3
- end
- ColorMod( Col.r /255, Col.g /255, Col.b /255 )
- SetBlend( Blend )
- v:DrawModel()
- end
- --draw physgun/eyetrace beams
- SetMat( Material( "sprites/tp_beam001" ) )--"cable/new_cable_lit"--solid beam
- for k,v in pairs( Map.PlayerHolos ) do
- if not( k:Health() >0 and !k:IsBot() ) then continue end
- -- if not( k:Health() >0 ) then continue end
- local BeamStart, BeamEnd
- local Pulse = TimedSin( 0.2, 3, 7, 1 )
- if( k:LookupBone( "ValveBiped.Bip01_R_Hand" ) ) then
- BeamStart = k:GetBonePosition( k:LookupBone( "ValveBiped.Bip01_R_Hand" ) )
- if( IsValid( k:GetActiveWeapon() ) and k:GetActiveWeapon():GetClass() == "weapon_physgun" and k.Pitch ) then
- BeamStart = BeamStart +Angle( k.Pitch, k:EyeAngles().y, 0 ):Forward() *18--make the beam start from the front of the physgun
- end
- else
- BeamStart = k:GetPos() +Vector( 0, 0, 45 )
- end
- BeamEnd = ( k.IsHoldingProp and IsValid( k.HeldProp ) ) and k.HeldProp:GetPos() or k:GetEyeTrace().HitPos
- local Start, End = GetMPos( BeamStart ), GetMPos( BeamEnd )
- DrawBeam( Start, End, BeamWidth( Start, End ), 0, 0, TeamCol( k:Team() ) )
- end
- SuppressLighting( false )
- MatOverride( nil )
- IgnoreZ( false )
- End3D()
- --player names
- for k,v in pairs( Map.PlayerHolos ) do
- if not( IsValid( k ) and IsValid( v ) ) then continue end
- local Pos = v:GetPos()--put the name above the holo(v) instead of the GetMPos of the player(k) so it stays with the holo during faceplant
- Pos.z = Pos.z +40
- Pos = Pos:ToScreen()
- local Col = k:Health() <1 and Color( TimedSin( 2, 170, 340, 1 ), 0, 0 ) or TeamCol( k:Team() )
- DrawTextOutlined( k:Nick(), "MinimapFont", Pos.x, Pos.y, Col, 1, 1, 3, Color( 0, 0, 0 ) )
- end
- end )
- hook.Add( "DrawPhysgunBeam", "Minimap_GetHeldProp", function( Ply, _, HoldingTheProp, Prop )
- if not( Map.Active and IsValid( Ply ) ) then return end
- Ply.IsHoldingAProp = HoldingTheProp
- if( !IsValid( Prop ) ) then Ply.HeldProp = nil return end
- Ply.HeldProp = Prop
- end )
- hook.Add( "HUDPaint", "BONERIFFIC", function()
- --this shows whose prop you're aiming at, not sure why it's here but there's not much point giving it its own file
- local Ent = IsValid( LocalPlayer():GetEyeTrace().Entity ) and LocalPlayer():GetEyeTrace().Entity or nil
- if( Ent and Ent:GetClass() == "prop_physics" and IsValid( Ent:GetNWEntity( "Owner" ) ) ) then
- local Owner = Ent:GetNWEntity( "Owner" )
- local X = 10 +string.len( Owner:Nick() ) *8
- DrawTextOutlined( string.upper( Owner:Nick() ), "MinimapFont", X, ScrH() -130, Color( 0, 180, 180 ), 1, 1, 2, Color( 0, 0, 0 ) )
- end
- end )
Add Comment
Please, Sign In to add comment