thegrump

propkill minimap

Nov 3rd, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.35 KB | None | 0 0
  1. --[[this goes in your server's lua/autorun]]--
  2.  
  3. local MapName = string.lower( game.GetMap() )
  4.  
  5. if( CLIENT ) then
  6.     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
  7. else
  8.     AddCSLuaFile()
  9.     hook.Add( "PlayerSpawnedProp", "setpropowners", function( ply, _, ent )
  10.         if not( IsValid( ply ) and IsValid( ent ) ) then return end
  11.         ent:SetNWEntity( "Owner", ply )
  12.     end )
  13.     return
  14. end
  15.  
  16. local Map = {
  17.     PropHolos = {},
  18.     Active = false,
  19.     LastFrame = 69,
  20.     PlayerHolos = {},
  21.     MinimapScale = 4,
  22.     GeneralSpeed = 500,
  23.     DumbfoundedSpeed = 8,
  24.     MaxBounds = Vector( -2920, -789, 170 ),
  25.     MinBounds = Vector( -5492, -2808, -550 ),
  26.     MinimapOrigin = Vector( -4242.35, -1717.83, -438 ),
  27.     Mat = CreateMaterial( "White9", "UnlitGeneric", { ["$basetexture"] = "models/debug/debugwhite", ["$nocull"] = 1, ["$model"] = 1 } ),
  28. }
  29.  
  30. --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
  31. local MsgN = MsgN
  32. local Color = Color
  33. local pairs = pairs
  34. local Angle = Angle
  35. local Exp = math.exp
  36. local Vector = Vector
  37. local CurTime = CurTime
  38. local IsValid = IsValid
  39. local End3D = cam.End3D
  40. local Clamp = math.Clamp
  41. local Material = Material
  42. local TimedSin = TimedSin
  43. local PGA = player.GetAll
  44. local TableAdd = table.Add
  45. local Start3D = cam.Start3D
  46. local IgnoreZ = cam.IgnoreZ
  47. local TeamCol = team.GetColor
  48. local TableCount = table.Count
  49. local LocalPlayer = LocalPlayer
  50. local DrawBeam = render.DrawBeam
  51. local SetBlend = render.SetBlend
  52. local SetMat = render.SetMaterial
  53. local FindByClass = ents.FindByClass
  54. local ClientProp = ents.CreateClientProp
  55. local ColorMod = render.SetColorModulation
  56. local MatOverride = render.MaterialOverride
  57. local DrawTextOutlined = draw.SimpleTextOutlined
  58. local SuppressLighting = render.SuppressEngineLighting
  59. surface.CreateFont( "MinimapFont", { font = "coolvetica", size = 35, antialias = true } )
  60.  
  61. local function InMapRoom( ply )
  62.     if( !ply ) then ply = LocalPlayer() end
  63.     local pos = ply:GetPos() +Vector( 0, 0, 70 )
  64.     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 )
  65. end
  66.  
  67. local function GetMPos( Vec )
  68.     return( Map.MinimapOrigin +( Vec /Map.MinimapScale ) )
  69. end
  70.  
  71. local function CreateHolo( mdl )
  72.     local Holo = ClientProp( mdl )
  73.     Holo:SetModelScale( 1 / Map.MinimapScale, 0 )
  74.     Holo.NoDraw = true
  75.     Holo:SetNoDraw( true )
  76.     return Holo
  77. end
  78.  
  79. local function CleanTable( Filthy )
  80.     local Clean = {}
  81.  
  82.     for k,v in pairs( Filthy ) do
  83.         if not( IsValid( k ) and !InMapRoom( k ) and IsValid( v ) ) then continue end
  84.         Clean[k] = v
  85.     end
  86.     return Clean
  87. end
  88.  
  89. local function CombinedHoloTable( ReverseKV )
  90.     local tbl = {}
  91.  
  92.     for k,v in pairs( Map.PlayerHolos ) do
  93.         if( ReverseKV ) then
  94.             tbl[v] = true--so i can check if the holo exists as a key instead of using table.HasValue which is slow and gay
  95.         else
  96.             tbl[k] = v
  97.         end
  98.     end
  99.  
  100.     for k,v in pairs( Map.PropHolos ) do
  101.         if( ReverseKV ) then
  102.             tbl[v] = true
  103.         else
  104.             tbl[k] = v
  105.         end
  106.     end
  107.     return tbl
  108. end
  109.  
  110. local function UnfuckStuckHolos()
  111.     local ValidHolos = CombinedHoloTable( true )
  112.     local AllHolos = FindByClass( "class C_PhysPropClientside" )
  113.     TableAdd( AllHolos, FindByClass( "C_BaseFlex" ) )
  114.  
  115.     if( TableCount( ValidHolos ) == #AllHolos ) then return end
  116.  
  117.     for _,v in pairs( AllHolos ) do
  118.         if not( IsValid( v ) and !ValidHolos[v] ) then continue end
  119.         v:Remove()
  120.     end
  121. end
  122. UnfuckStuckHolos()
  123.  
  124. local function ResetMinimap()--reset and disable the map for people outside the map room
  125.     Map.PropHolos = {}
  126.     Map.PlayerHolos = {}
  127.     UnfuckStuckHolos()
  128.     for _,v in pairs( PGA() ) do
  129.         v.HeldProp = nil
  130.     end
  131.     Map.Active = false
  132. end
  133.  
  134.  
  135. local function BeamWidth( Start, End )
  136.     if not( IsValid( LocalPlayer() ) ) then return end
  137.     return util.DistanceToLine( Start, End, LocalPlayer():GetShootPos() ) /90
  138. end
  139.  
  140. hook.Add( "Think", "Minimap_CreateHolos", function()
  141.     if( Map.Active ) then
  142.         if( !InMapRoom() ) then
  143.             ResetMinimap()
  144.             -- LocalPlayer():ChatPrint( "DISABLED MAP" )
  145.             return
  146.         end
  147.     else
  148.         if( InMapRoom() ) then
  149.             Map.Active = true
  150.             -- LocalPlayer():ChatPrint( "ENABLED MAP" )
  151.         end
  152.     end
  153.  
  154.     for _,v in pairs( PGA() ) do
  155.         if not( IsValid( v ) ) then continue end
  156.  
  157.         --player holos
  158.         if( !Map.PlayerHolos[v] ) then
  159.             Map.PlayerHolos[v] = CreateHolo( v:GetModel() )
  160.             --MsgN( "CREATED HOLO PLAYER FOR "..v:Nick()..", "..v:GetModel() )
  161.         end
  162.  
  163.         --physgun holos
  164.         if( IsValid( v:GetActiveWeapon() ) and v:GetActiveWeapon():GetClass() == "weapon_physgun" and v:LookupBone( "ValveBiped.Bip01_R_Hand" ) ) then
  165.             if( !v.Physgun or !IsValid( v.Physgun ) ) then
  166.                 v.Physgun = CreateHolo( "models/weapons/w_physics.mdl" )
  167.             --  MsgN( "CREATED HOLO PHYSGUN FOR "..v:Nick() )
  168.             end
  169.         elseif( IsValid( v.Physgun ) ) then
  170.             v.Physgun:Remove()
  171.             --MsgN( "REMOVED HOLO PHYSGUN FOR "..v:Nick() )
  172.         end
  173.     end
  174.  
  175.     --prop holos
  176.     for _,v in pairs( FindByClass( "prop_physics" ) ) do
  177.         if not( IsValid( v ) and !Map.PropHolos[v] ) then continue end
  178.  
  179.         Map.PropHolos[v] = CreateHolo( v:GetModel() )
  180.         --MsgN( "CREATED HOLO PROP: "..v:GetModel() )
  181.     end
  182.  
  183.     Map.PropHolos = CleanTable( Map.PropHolos )
  184.     UnfuckStuckHolos()
  185. end )
  186.  
  187. hook.Add( "PostDrawHUD", "Minimap_DrawHolos", function()
  188.     if( !Map.Active ) then return end
  189.     local CT = CurTime()
  190.  
  191.     --animate player holos
  192.     Map.PlayerHolos = CleanTable( Map.PlayerHolos )
  193.     for k,v in pairs( Map.PlayerHolos ) do
  194.         local Seq = 2--best death animation, i call it the look-mum-no-hands-maximum-over-smackdown-mcfaceplant-3D
  195.         local EA = k:EyeAngles()
  196.  
  197.         --animate physguns
  198.         if( k.Physgun and IsValid( k.Physgun ) ) then
  199.             if( !k.Pitch ) then k.Pitch = EA.p end
  200.             if( EA.p <45 and EA.p >-15 ) then--math.Clamp made it flicker spastically
  201.                 k.Pitch = EA.p
  202.             end
  203.             k.Physgun:SetPos( GetMPos( k:GetBonePosition( k:LookupBone( "ValveBiped.Bip01_R_Hand" ) ) -EA:Forward() *2 ) )
  204.             k.Physgun:SetAngles( Angle( k.Pitch, EA.y, 0 ) )
  205.         end
  206.  
  207.         EA.p, EA.r = 0
  208.  
  209.         if( k:Health() >0 ) then
  210.             k.FaceplantStart = nil
  211.             v:SetPos( GetMPos( k:GetPos() ) )
  212.             Seq = k:GetSequence()
  213.         else
  214.             if( !k.FaceplantStart ) then
  215.                 k.FaceplantStart = CT
  216.                 k.FaceplantY = EA.y
  217.             end
  218.             EA.p = Clamp( Exp( ( CT -k.FaceplantStart ) ^Map.DumbfoundedSpeed ) *Map.GeneralSpeed, 0, 90 +Map.GeneralSpeed ) -Map.GeneralSpeed
  219.             EA.y = k.FaceplantY--stops player holos breakdancing if the player dies and starts looking around
  220.         end
  221.  
  222.         v:InvalidateBoneCache()
  223.         v:FrameAdvance( CT -Map.LastFrame )
  224.         v:SetSequence( Seq )
  225.         v:SetAngles( EA )
  226.  
  227.         for i=0,k:GetNumPoseParameters() -1 do
  228.             local Pose = k:GetPoseParameterName( i )
  229.             v:SetPoseParameter( Pose, k:GetPoseParameter( Pose ) )
  230.         end
  231.     end
  232.     Map.LastFrame = CT
  233.  
  234.     --animate prop holos
  235.     Map.PropHolos = CleanTable( Map.PropHolos )
  236.     for k,v in pairs( Map.PropHolos ) do
  237.         v:SetPos( GetMPos( k:GetPos() ) )
  238.         v:SetAngles( k:GetAngles() )
  239.     end
  240.  
  241.     --draw holos
  242.     Start3D()
  243.         IgnoreZ( true )
  244.         MatOverride( Map.Mat )
  245.         SuppressLighting( true )
  246.  
  247.         for k,v in pairs( CombinedHoloTable() ) do
  248.             local Col
  249.             local Blend = 1
  250.  
  251.             --players
  252.             if( k:IsPlayer() ) then
  253.                 Col = k:Health() <1 and Color( TimedSin( 2, 170, 340, 1 ), 0, 0 ) or TeamCol( k:Team() )
  254.  
  255.                 --physguns
  256.                 if( k.Physgun and IsValid( k.Physgun ) ) then
  257.                     ColorMod( 1, 1, 1 )
  258.                     k.Physgun:DrawModel()
  259.                 end
  260.  
  261.             --props
  262.             else
  263.                 local Owner = k:GetNWEntity( "Owner" )
  264.                 if( !IsValid( Owner ) ) then continue end
  265.                 Col = Owner:Health() <1 and Color( TimedSin( 2, 170, 340, 1 ), 0, 0 ) or TeamCol( Owner:Team() )
  266.                 Blend = 0.3
  267.             end
  268.  
  269.             ColorMod( Col.r /255, Col.g /255, Col.b /255 )
  270.             SetBlend( Blend )
  271.             v:DrawModel()
  272.         end
  273.  
  274.         --draw physgun/eyetrace beams
  275.         SetMat( Material( "sprites/tp_beam001" ) )--"cable/new_cable_lit"--solid beam
  276.  
  277.         for k,v in pairs( Map.PlayerHolos ) do
  278.             if not( k:Health() >0 and !k:IsBot() ) then continue end
  279.             -- if not( k:Health() >0 ) then continue end
  280.             local BeamStart, BeamEnd
  281.             local Pulse = TimedSin( 0.2, 3, 7, 1 )
  282.  
  283.             if( k:LookupBone( "ValveBiped.Bip01_R_Hand" ) ) then
  284.                 BeamStart = k:GetBonePosition( k:LookupBone( "ValveBiped.Bip01_R_Hand" ) )
  285.  
  286.                 if( IsValid( k:GetActiveWeapon() ) and k:GetActiveWeapon():GetClass() == "weapon_physgun" and k.Pitch ) then
  287.                     BeamStart = BeamStart +Angle( k.Pitch, k:EyeAngles().y, 0 ):Forward() *18--make the beam start from the front of the physgun
  288.                 end
  289.             else
  290.                 BeamStart = k:GetPos() +Vector( 0, 0, 45 )
  291.             end
  292.  
  293.             BeamEnd = ( k.IsHoldingProp and IsValid( k.HeldProp ) ) and k.HeldProp:GetPos() or k:GetEyeTrace().HitPos
  294.             local Start, End = GetMPos( BeamStart ), GetMPos( BeamEnd )
  295.             DrawBeam( Start, End, BeamWidth( Start, End ), 0, 0, TeamCol( k:Team() ) )
  296.         end
  297.  
  298.         SuppressLighting( false )
  299.         MatOverride( nil )
  300.         IgnoreZ( false )
  301.     End3D()
  302.  
  303.  
  304.     --player names
  305.     for k,v in pairs( Map.PlayerHolos ) do
  306.         if not( IsValid( k )  and IsValid( v ) ) then continue end
  307.         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
  308.         Pos.z = Pos.z +40
  309.         Pos = Pos:ToScreen()
  310.         local Col = k:Health() <1 and Color( TimedSin( 2, 170, 340, 1 ), 0, 0 ) or TeamCol( k:Team() )
  311.         DrawTextOutlined( k:Nick(), "MinimapFont", Pos.x, Pos.y, Col, 1, 1, 3, Color( 0, 0, 0 ) )
  312.     end
  313.  
  314. end )
  315.  
  316. hook.Add( "DrawPhysgunBeam", "Minimap_GetHeldProp", function( Ply, _, HoldingTheProp, Prop )
  317.     if not( Map.Active and IsValid( Ply ) ) then return end
  318.  
  319.     Ply.IsHoldingAProp = HoldingTheProp
  320.     if( !IsValid( Prop ) ) then Ply.HeldProp = nil return end
  321.     Ply.HeldProp = Prop
  322. end )
  323.  
  324. hook.Add( "HUDPaint", "BONERIFFIC", function()
  325.     --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
  326.     local Ent = IsValid( LocalPlayer():GetEyeTrace().Entity ) and LocalPlayer():GetEyeTrace().Entity or nil
  327.     if( Ent and Ent:GetClass() == "prop_physics" and IsValid( Ent:GetNWEntity( "Owner" ) ) ) then
  328.         local Owner = Ent:GetNWEntity( "Owner" )
  329.         local X = 10 +string.len( Owner:Nick() ) *8
  330.         DrawTextOutlined( string.upper( Owner:Nick() ), "MinimapFont", X, ScrH() -130, Color( 0, 180, 180 ), 1, 1, 2, Color( 0, 0, 0 ) )
  331.     end
  332. end )
Add Comment
Please, Sign In to add comment