CapsAdmin

Untitled

Jun 8th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.01 KB | None | 0 0
  1. hook.Add("PlayerFootstep", "snow", function(ply, pos, foot, sound, volume, rf)
  2.     if sound:find("grass") then
  3.         ply:EmitSound(Format("player/footsteps/snow%s.wav", math.random(6)), 60, math.random(95,105))
  4.         return true
  5.     end
  6. end)
  7.  
  8. if SERVER then return end
  9. module  ( "ms" , package.seeall )
  10.  
  11. --snow_data = nil
  12. snow_data = snow_data or {}
  13.  
  14.  
  15. local LP
  16.  
  17.  
  18. local replace = {
  19.     ["METASTRUCT_2/GRASS"] = true,
  20.     ["GM_CONSTRUCT/GRASS"] = true,
  21. --[[    ["maps/metastruct_2/metastruct_2/road_6120_8680_-12944"] = true,
  22.     ["maps/metastruct_2/metastruct_2/road_-3656_12928_-13216"] = true,
  23.     ["maps/metastruct_2/metastruct_2/road_-6332_11456_-13184"] = true,
  24.     ["CONCRETE/CONCRETEFLOOR001A"] = true,
  25.     ["maps/metastruct_2/tile/tileroof004b_-13744_12784_-13200"] = true,
  26.     ["maps/metastruct_2/tile/tileroof004a_-14224_11856_-13216"] = true,
  27.     ["maps/metastruct_2/tile/tileroof004a_-14192_12176_-12784"] = true,
  28.     ["maps/metastruct_2/metastruct_2/road_-13008_12656_-13104"] = true,
  29.    
  30.    
  31.    
  32.    
  33.     ["maps/metastruct_2/tile/tileroof004a_6120_8680_-12944"] = true,
  34.     ["maps/metastruct_2/tile/tileroof004b_-14192_12176_-12784"] = true,
  35.     ["maps/metastruct_2/tile/tileroof004b_-9035_13056_-13188"] = true, 
  36.     ["maps/metastruct_2/metastruct_2/road_-9035_13056_-13188"] = true, 
  37.     ["maps/metastruct_2/tile/tileroof004a_-6332_11456_-13184"] = true, 
  38.     ["maps/metastruct_2/tile/tileroof004b_6120_8680_-12944"] = true,     ]]
  39.    
  40.      
  41. }
  42. local rt = { "roof", "grass", "ceiling" }
  43.  
  44. if table.Count(snow_data) == 0 then
  45.  
  46.     local max = 16000
  47.     local grid_size = 768
  48.     local range = max/grid_size
  49.  
  50.     local pos
  51.  
  52.     for x = -range, range do
  53.         x = x * grid_size
  54.         for y = -range, range do
  55.             y = y * grid_size
  56.             for z = -range, range do
  57.                 z = z * grid_size
  58.                
  59.                 pos = Vector(x,y,z)
  60.                 local conents = util.PointContents( pos )
  61.                
  62.                 if conents == CONTENTS_EMPTY or conents == CONTENTS_TESTFOGVOLUME then
  63.                     local up = util.QuickTrace(pos, vector_up*max*2)
  64.                     if up.HitTexture == "TOOLS/TOOLSSKYBOX" or up.HitTexture == "**empty**" then
  65.                         table.insert(snow_data, pos)
  66. --[[                        local down = util.QuickTrace(pos, (vector_up*-1)*max*2)
  67.                         if down.Hit then
  68.                             local t = down.HitTexture:lower()
  69.                             for k,v in pairs(rt) do
  70.                                 if string.find(t, v) ~= nil then
  71.                                     replace[t] = true
  72.                                 end
  73.                             end
  74.                         end ]]
  75.                     end
  76.                 end
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. local function FastLength(point)
  83.     return point.x*point.x+point.y*point.y+point.z*point.z
  84. end
  85.  
  86. draw_these = {}
  87.  
  88. local emitter = ParticleEmitter(EyePos(), false)
  89.  
  90. local snow_explode = CreateClientConVar("snow_explode", "0", true, false)
  91.  
  92. local function SnowCallback(p, hitpos)
  93.     if snow_explode:GetBool() then
  94.         local efdata = EffectData() --Grab base EffectData table
  95.         efdata:SetOrigin(hitpos) --Sets the origin of it to the hitpos of the particle
  96.         efdata:SetStart(hitpos)
  97.         efdata:SetScale(0.2)
  98.         util.Effect("Explosion", efdata) --Create the effect
  99.     end
  100.     p:SetDieTime(0)
  101. end
  102.  
  103. hook.Add("Think", "snow", function()
  104.     for _, point in pairs(draw_these) do
  105.         if math.random() < 0.95 then continue end
  106.         local particle = emitter:Add("particle/snow", point)
  107.         if (particle) then
  108.             particle:SetVelocity(VectorRand()*100*Vector(1,1,0))
  109.             particle:SetAngles(Angle(math.random(360), math.random(360), math.random(360)))
  110.             particle:SetLifeTime(0)
  111.             particle:SetDieTime(10)
  112.             particle:SetStartAlpha(255)
  113.             particle:SetEndAlpha(0)
  114.             particle:SetStartSize(0)
  115.             particle:SetEndSize(5)
  116.             particle:SetGravity(Vector(0,0,math.Rand(-30, -200)))
  117.             particle:SetCollide(true)
  118.             particle:SetCollideCallback(SnowCallback)
  119.         end
  120.     end
  121. end)
  122.  
  123. local function CreateSnowLoop(t)
  124.     local iterations = math.min(math.ceil(#snow_data/(1/t)), #snow_data)
  125.     local lastkey = 1
  126.     local lastpos = nil
  127.     local len = 3000^2
  128.     local movelen = 100^2
  129.     local LastLoop = -1
  130.     timer.Create("hide_points", t, 0, function()
  131.         if not IsValid(LP) then
  132.             LP = LocalPlayer()
  133.             if not IsValid(LP) then return end
  134.         end
  135.         local EP = LP:EyePos()+LP:GetVelocity()
  136.         --[[local d = SysTime()-LastLoop
  137.         if LastLoop ~= -1 and d > t+0.1 then
  138.             local nt = t+0.05
  139.             CreateSnowLoop(nt)
  140.             return
  141.         elseif t >= 0.1 and d <= t+0.01 then
  142.             local nt = t-0.05
  143.             CreateSnowLoop(nt)
  144.             return
  145.         end]]
  146.         if lastpos == nil or FastLength(lastpos-EP) > movelen then
  147.             local c = #snow_data
  148.             local r = math.min(iterations, c)
  149.             local completed = false
  150.             for i=1,r do
  151.                 local key = lastkey+1
  152.                 if key > c then
  153.                     completed = true
  154.                     lastkey = 1
  155.                     break
  156.                 end
  157.                 local point = snow_data[key]
  158.                 local dc = FastLength(point - EP) < len
  159.                 if dc and draw_these[key] == nil then
  160.                     draw_these[key] = point
  161.                 elseif not dc and draw_these[key] ~= nil then
  162.                     draw_these[key] = nil
  163.                 end
  164.                 lastkey = key
  165.             end
  166.             if completed then lastpos = EP end
  167.         end
  168.     end)
  169. end
  170. CreateSnowLoop(0.1)
  171.  
  172. do
  173. materials = materials or {} local self = materials
  174.  
  175.  
  176. materials.Replaced = {}
  177.  
  178. function materials.ReplaceTexture(path, to)
  179.     check(path, "string")
  180.     check(to, "string", "ITexture", "Material")
  181.  
  182.     path = path:lower()
  183.  
  184.     local mat = Material(path)
  185.  
  186.     if not mat:IsError() then
  187.  
  188.         local typ = type(to)
  189.         local tex
  190.  
  191.         if typ == "string" then
  192.             tex = Material(to):GetMaterialTexture("$basetexture")
  193.         elseif typ == "ITexture" then
  194.             tex = to
  195.         elseif typ == "Material" then
  196.             tex = to:GetMaterialTexture("$basetexture")
  197.         else return false end
  198.  
  199.         self.Replaced[path] = self.Replaced[path] or {}
  200.  
  201.         self.Replaced[path].OldTexture = self.Replaced[path].OldTexture or mat:GetMaterialTexture("$basetexture")
  202.         self.Replaced[path].NewTexture = tex
  203.  
  204.         mat:SetMaterialTexture("$basetexture",tex)
  205.  
  206.         return true
  207.     end
  208.  
  209.     return false
  210. end
  211.  
  212.  
  213. function materials.SetColor(path, color)
  214.     check(path, "string")
  215.     check(color, "Vector")
  216.  
  217.     path = path:lower()
  218.  
  219.     local mat = Material(path)
  220.  
  221.     if not mat:IsError() then
  222.         self.Replaced[path] = self.Replaced[path] or {}
  223.         self.Replaced[path].OldColor = self.Replaced[path].OldColor or mat:GetMaterialVector("$color")
  224.         self.Replaced[path].NewColor = color
  225.  
  226.         mat:SetMaterialVector("$color", color)
  227.  
  228.         return true
  229.     end
  230.  
  231.     return false
  232. end
  233.  
  234.  
  235. function materials.RestoreAll()
  236.     for name, tbl in pairs(self.Replaced) do
  237.         if
  238.             !pcall(function()
  239.                 if tbl.OldTexture then
  240.                     materials.ReplaceTexture(name, tbl.OldTexture)
  241.                 end
  242.  
  243.                 if tbl.OldColor then
  244.                     materials.SetColor(name, tbl.OldColor)
  245.                 end
  246.             end)
  247.         then
  248.             print("Failed to restore: " .. tostring(name))
  249.         end
  250.     end
  251. end
  252. hook.Add('ShutDown','MatRestorer',materials.RestoreAll)
  253.  
  254. -- Material Extensions / SkyBox modder
  255. local sky =
  256. {
  257.     ["up"]=true,
  258.     ["dn"]=true,
  259.     ["lf"]=true,
  260.     ["rt"]=true,
  261.     ["ft"]=true,
  262.     ["bk"]=true,
  263. }
  264.  
  265. local sky_name = GetConVarString("sv_skyname")
  266.  
  267. for side, path in pairs(sky) do
  268.     path = "skybox/" .. sky_name .. side
  269.     materials.ReplaceTexture(path, "Decals/decal_paintsplatterpink001")
  270.     --materials.SetColor(path, Vector(1.4, 1, 1)*3)
  271. end
  272.  
  273. end
  274.  
  275. for k,v in pairs(replace) do
  276.     materials.ReplaceTexture(k, "NATURE/SNOWFLOOR001A")
  277. end
Advertisement
Add Comment
Please, Sign In to add comment