Advertisement
LuaTenshi

(Garrysmod) Quick&Dirty - Prop Kill Gamemode

Jun 6th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.91 KB | None | 0 0
  1. if CLIENT then
  2.     local matMaterial = Material( "pp/texturize" )
  3.     local m = CreateMaterial( 'pk+player2', "VertexLitGeneric", { ["$basetexture"] = "models/debug/debugwhite", ["$model"] = 1, ["$ignorez"] = 1 } );
  4.  
  5.     local function isPlayer(e) return IsValid(e) and e.GetClass and e:GetClass() == "player" end
  6.  
  7.     local PlayerProps = {}
  8.  
  9.     function tex()
  10.         local pMaterial = Material('pp/texturize/plain.png')
  11.  
  12.         render.UpdateScreenEffectTexture()
  13.  
  14.         matMaterial:SetFloat( "$scalex", ( ScrW() / 64 ) * 1 )
  15.         matMaterial:SetFloat( "$scaley", ( ScrH() / 64 / 8 ) * 1 )
  16.         matMaterial:SetTexture( "$basetexture", pMaterial:GetTexture( "$basetexture" ) )
  17.  
  18.         render.SetMaterial( matMaterial )
  19.         render.DrawScreenQuad()
  20.         render.SuppressEngineLighting(false)
  21.     end
  22.  
  23.     hook.Add( "PostDrawOpaqueRenderables", "zed", tex )
  24.  
  25.     local function TableSortByDistance(former, latter) return latter:GetPos():Distance( LocalPlayer():GetPos() ) > former:GetPos():Distance( LocalPlayer():GetPos() ) end
  26.     function GetPlayersByDistance() local players = player.GetAll(); table.sort( players, TableSortByDistance ); return players; end
  27.  
  28.     function pkplayer()
  29.         for _,v in next, ents.FindByClass('prop_physics') do
  30.             if IsValid(v) then
  31.                 cam.Start3D( LocalPlayer():EyePos(), LocalPlayer():EyeAngles() );
  32.                     render.SuppressEngineLighting(false)
  33.                     render.SetColorModulation( 1, 0, 0, 1 );
  34.                     render.SetModelLighting( 4, 1, 0, 0 );
  35.                     render.MaterialOverride( m );
  36.                     v:DrawModel()
  37.                 cam.End3D();
  38.             end
  39.         end
  40.         for _, ply in pairs( GetPlayersByDistance() ) do
  41.             if (ply != LocalPlayer() && IsValid( ply ) && ply:Alive() && ply:Health() > 0 && ply:Team() != TEAM_SPECTATOR && !ply:IsDormant()) then
  42.                 cam.Start3D( LocalPlayer():EyePos(), LocalPlayer():EyeAngles() );
  43.                     render.SuppressEngineLighting(true)
  44.                     render.SetColorModulation( 0.7, 0, 0, 1 );
  45.                     render.SetModelLighting( 4, 1, 0, 0 );
  46.                     render.MaterialOverride( m );
  47.                     render.SetMaterial(m)
  48.                     ply:DrawModel();
  49.                    
  50.                     if (IsValid( ply:GetActiveWeapon() )) then
  51.                         local clr = ply:GetWeaponColor()
  52.                         render.SetColorModulation( math.abs(clr.x), math.abs(clr.y), math.abs(clr.z), 1 );
  53.                         ply:GetActiveWeapon():DrawModel();
  54.                     end
  55.                     render.SuppressEngineLighting(false);
  56.                 cam.End3D();
  57.             end
  58.         end
  59.     end
  60.  
  61.     hook.Add( "RenderScreenspaceEffects", "zed", pkplayer )
  62.  
  63.     hook.Add("PreDrawPlayerHands", "zed", function(vm, ply, wep)
  64.         render.SuppressEngineLighting(true)
  65.         render.SetColorModulation( 0.7, 0, 0, 1 );
  66.         render.MaterialOverride( m )
  67.     end)
  68.  
  69.     hook.Add("PreDrawViewModel", "zed", function(vm, ply, wep)
  70.         if IsValid(ply) then
  71.             local clr = ply:GetWeaponColor()
  72.             render.SuppressEngineLighting(true)
  73.             render.SetColorModulation(
  74.                 math.abs(clr.x) < 0.5 and clr.x or 0.5,
  75.                 math.abs(clr.y) < 0.5 and clr.y or 0.5,
  76.                 math.abs(clr.z) < 0.5 and clr.z or 0.5
  77.             ,1);
  78.             render.MaterialOverride( m )
  79.         end
  80.     end)
  81. elseif SERVER then
  82.     local function FindOwner( ent )
  83.         local owner, _ = ent:CPPIGetOwner()
  84.         return owner or ent.FPPOwner or nil -- Fallback to FPP variable if CPPI fails.
  85.     end
  86.  
  87.     local function isPlayer(e) return IsValid(e) and e.GetClass and e:GetClass() == "player" end
  88.  
  89.     local function DamageFilter( target, d ) -- d for damage info.
  90.         local attacker, inflictor, damage, type = d:GetAttacker(), d:GetInflictor(), d:GetDamage(), d:GetDamageType()
  91.         local dents = {attacker, inflictor}
  92.  
  93.         for _,v in next, dents do
  94.  
  95.             local str = '_pk='..tostring(CurTime())..v:EntIndex()
  96.  
  97.             if isPlayer(target) and damage > 0 then
  98.                 if not isPlayer(v) then
  99.                     local o = FindOwner(v)
  100.                     timer.Create(str, 0.0001, 1, function()
  101.                         if IsValid(target) and IsValid(o) and (target.Alive and not target:Alive()) then
  102.                             if target ~= o then
  103.                                 o:AddFrags(1)
  104.                             else
  105.                                 o:AddFrags(-2)
  106.                             end
  107.                         end
  108.                     end)
  109.                 end
  110.             end
  111.  
  112.         end
  113.     end
  114.     hook.Add( "EntityTakeDamage", "zed", DamageFilter )
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement