CapsAdmin

Untitled

Jun 26th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.93 KB | None | 0 0
  1. -- "defines"
  2. local function HOOK(name) hook.Add(name, "permaprops", permaprops[name]) end
  3.  
  4. permaprops = {}
  5. permaprops.ClientsideModels = {}
  6. permaprops.FadeDist = 10000
  7. permaprops.DefaultClass = "prop_dynamic"
  8. permaprops.ConvertClass =
  9. {
  10.     prop_physics = "prop_dynamic",
  11.     prop_effect = function(ent)
  12.         return ent.AttachedEntity
  13.     end,
  14. }
  15.  
  16. permaprops.SpecialProps =
  17. {
  18.     ["models/props/de_tides/tides_streetlight.mdl"] = function(ent)
  19.  
  20.     end,
  21.  
  22.     ["models/props/de_inferno/light_streetlight.mdl"] = function(ent)
  23.         if SERVER then
  24.             local light = ents.Create("gmod_light")
  25.             light:Spawn()
  26.             light:Activate()
  27.             light:SetParent(ent)
  28.             light:SetPos(Vector(0,0,152))
  29.  
  30.             light:SetLightColor(255, 180, 50)
  31.             light:SetBrightness(2)
  32.             light:SetLightSize(550)
  33.             if permaprops.FadeDist > 0 then
  34.                 light:SetKeyValue("fademaxdist", permaprops.FadeDist)
  35.             end
  36.         end
  37.     end,
  38. }
  39.  
  40. function permaprops.InitPostEntity()
  41.     if aowl then
  42.         aowl.AddCommand("loadmap", function(player, line)
  43.                 aowl.CountDown(line, "LOADING PERMAPROPS", function()
  44.                     permaprops.LoadMap(nil, true)
  45.                 end)
  46.         end, "moderators")
  47.     end
  48. end
  49.  
  50. HOOK("InitPostEntity")
  51.  
  52. do -- orientation
  53.  
  54.     local position
  55.     local parent = NULL
  56.  
  57.     function permaprops.SetParent(ent)
  58.         ent = ent or NULL
  59.         if ent:IsValid() then
  60.             for k, v in ipairs(ents.GetAll()) do
  61.                 if v:IsPermaProp() then
  62.                     v:SetParent(ent)
  63.                 end
  64.             end
  65.             parent = ent
  66.         end
  67.     end
  68.  
  69.     function permaprops.GetParent()
  70.         return parent
  71.     end
  72.  
  73. end
  74.  
  75. do -- save/load
  76.     function permaprops.CalcCRC(ent)
  77.         local pos = ent:GetPos()
  78.         local ang = ent:GetAngles()
  79.         local mdl = ent:GetModel():lower():Replace("\\", "/")
  80.         local hpos = Vector(math.Round(pos.x/10), math.Round(pos.y/10), math.Round(pos.z/10))
  81.         local hang = Angle(math.Round(ang.p/10), math.Round(ang.y/10), math.Round(ang.r/10))
  82.  
  83.         local crc = hpos.x .. hpos.y .. hpos.z .. hang.p .. hang.y .. hang.r .. mdl
  84.  
  85.         return util.CRC(crc)
  86.     end
  87.  
  88.     function permaprops.ConvertEntity(ent, _spawn)
  89.         local mdl = ent:GetModel()
  90.         if not mdl then return end
  91.         mdl = mdl:lower():Replace("\\", "/")
  92.         local special = permaprops.SpecialProps[mdl:lower()]
  93.  
  94.         if special then
  95.             special(ent)
  96.         end
  97.  
  98.         if SERVER then
  99.             ent:SetHealth(99999999999999999)
  100.  
  101.             ent:SetKeyValue("solid", 6)
  102.             ent:SetKeyValue("disableshadows", 1)
  103.             --ent:SetKeyValue("spawnflags", 64)
  104.             if permaprops.FadeDist > 0 then
  105.                 ent:SetKeyValue("fademaxdist", permaprops.FadeDist)
  106.             end
  107.  
  108.             if _spawn then ent:Spawn() end
  109.  
  110.             ent:SetMoveType(MOVETYPE_NONE)
  111.             ent:SetSolid(SOLID_VPHYSICS)
  112.  
  113.             if ent.CollisionRulesChanged then
  114.                 ent:CollisionRulesChanged()
  115.             end
  116.  
  117.             local phys = ent:GetPhysicsObject()
  118.  
  119.             if phys:IsValid() then
  120.                 phys:Sleep()
  121.                 phys:EnableMotion(false)
  122.  
  123.                 local a = ent.permaprop_data and ent.permaprop_data.ang or Angle(0)
  124.                 phys:SetAngle(Angle(math.Round(a.p, 1), math.Round(a.y, 1), math.Round(a.r, 1)))
  125.  
  126.             else
  127.                 ErrorNoHalt(Format("invalid physics for permaprop Entity(%i) with the model %q", ent:EntIndex(), ent:GetModel()))
  128.             end
  129.         end
  130.     end
  131.  
  132.     function permaprops.CreateEntity(class)
  133.         if CLIENT then
  134.             local ent = ClientsideModel("error.mdl")
  135.             table.Merge(ent:GetTable(), permaprops.ClientMeta)
  136.  
  137.             return ent
  138.         end
  139.         if SERVER then
  140.             return ents.Create(class or permaprops.DefaultClass)
  141.         end
  142.     end
  143.  
  144.     function permaprops.SpawnPermaProp(data)
  145.  
  146.         -- this isn't working
  147.         if CLIENT then return end
  148.  
  149.         local ent = permaprops.CreateEntity(data.class ~= "" and data.class)
  150.  
  151.         ent:SetModel(data.mdl)
  152.         ent:SetMaterial(data.mat or "")
  153.         ent:SetPos(data.pos)
  154.         ent:SetAngles(data.ang or Angle(0))
  155.         ent.permaprop_data = data
  156.  
  157.         if data.col.r and data.a then
  158.             ent:SetColor(data.col)
  159.         end
  160.  
  161.         permaprops.ConvertEntity(ent, true)
  162.  
  163.         ent:SetPermaProp(true, true)
  164.  
  165.         if CLIENT then
  166.             table.insert(permaprops.ClientsideModels, ent)
  167.         end
  168.  
  169.         return ent
  170.     end
  171.  
  172.     function permaprops.CanSaveEntity(ent, udata)
  173.         if ent:IsPermaProp() then return false end
  174.         if ent:IsWorld() then return false end
  175.         if ent:IsWeapon() then return false end
  176.         if ent:IsPlayer() then return false end
  177.         if ent:IsVehicle() then return false end
  178.  
  179.         local custom = hook.Call("PermaPropsCanSaveEntity", GAMEMODE, ent, udata)
  180.         if custom == false then return false end
  181.  
  182.         if not ent:GetModel() then return false end
  183.         if not ent:GetModel():find("%.mdl") then return false end
  184.  
  185.         return true
  186.     end
  187.  
  188.     function permaprops.SaveEntity(ent, udata)
  189.         local class = permaprops.ConvertClass[ent:GetClass():lower()]
  190.         if type(class) == "function" then
  191.             ent = class(ent)
  192.  
  193.         end
  194.         if class == nil then
  195.             class = ent:GetClass()
  196.         end
  197.  
  198.         if permaprops.CanSaveEntity(ent, udata) == false then return end
  199.         if hook.Call("PermaPropsSaveEntity", GAMEMODE, ent, udata) ~= false then
  200.             local pos = ent:GetPos()
  201.             local ang = ent:GetAngles()
  202.             local mdl = ent:GetModel():lower():Replace("\\", "/")
  203.  
  204.             local hpos = Vector(math.Round(pos.x/10), math.Round(pos.y/10), math.Round(pos.z/10))
  205.             local hang = Angle(math.Round(ang.p/10), math.Round(ang.y/10), math.Round(ang.r/10))
  206.  
  207.             local hash = permaprops.CalcCRC(ent)
  208.  
  209.             -- so it's easier to find stuff you need want to delete something
  210.             hash = (mdl:match(".+/(.+)%.mdl") or mdl:gsub("%p", "_")) .. "_" .. hash
  211.             local path = Format("permaprops/%s/%s.txt", game.GetMap(), hash)
  212.  
  213.             luadata.WriteFile(path,
  214.                 {
  215.                     class = class ~= permaprops.DefaultClass and class or "",
  216.                     mdl = mdl,
  217.                     pos = pos,
  218.                     ang = ang,
  219.                     mat = ent:GetMaterial() or "",
  220.                     col = {ent:GetColor()},
  221.                 }
  222.             )
  223.  
  224.             ent.permaprops_file = path
  225.         end
  226.     end
  227.  
  228.     function permaprops.SaveMap()
  229.         for key, ent in pairs(ents.GetAll()) do
  230.             permaprops.SaveEntity(ent)
  231.         end
  232.     end
  233.  
  234.     function permaprops.LoadMap(map, default)
  235.         map = map or game.GetMap():lower()
  236.         permaprops.CleanUp()
  237.         local path = "permaprops/" .. map .. "/"
  238.  
  239.         if default or hook.Call("PermaPropsLoadMap", GAMEMODE, map) ~= false then
  240.             local files, i = file.Find(path .. "*.txt", "DATA"), 1
  241.             timer.Create("permaprops_fileiterator", 0.02, #files, function()
  242.                 local name = files[i]
  243.  
  244.                 if not name then timer.Destroy("permaprops_fileiterator") return end
  245.  
  246.                 local data = luadata.ReadFile(path .. name)
  247.                 local ent = permaprops.SpawnPermaProp(data)
  248.  
  249.                 ent.permaprops_file = path .. name
  250.  
  251.                 i = i + 1
  252.             end)
  253.         end
  254.     end
  255.  
  256.     function permaprops.CleanUp()
  257.         if CLIENT then
  258.             for key, ent in pairs(permaprops.ClientsideModels) do
  259.                 SafeRemoveEntity(ent)
  260.             end
  261.  
  262.             permaprops.ClientsideModels = {}
  263.         end
  264.         if SERVER then
  265.             for k, v in ipairs(ents.GetAll()) do
  266.                 if v:IsPermaProp() then
  267.                     v:Remove()
  268.                 end
  269.             end
  270.         end
  271.     end
  272. end
  273.  
  274. do -- meta
  275.     do -- parachute meta (CLEAN IT UP)
  276.  
  277.         local ENT = {}
  278.  
  279.         ENT.ClassName = "parachute"
  280.         ENT.Type = "anim"
  281.         ENT.Base = "base_anim"
  282.  
  283.         ENT.Model = "models/props_interiors/radiator01a.mdl"
  284.  
  285.         ENT.PartFence =
  286.         {
  287.             mdl = "models/props_citizen_tech/windmill_blade004b.mdl",
  288.             pos = Vector(-35, -4.2, 6),
  289.             ang = Angle(0, -90, 0),
  290.         }
  291.  
  292.         ENT.PartPropeller =
  293.         {
  294.             mdl = "models/props_citizen_tech/windmill_blade004a.mdl",
  295.             pos = Vector(-5, 0, 2.55),
  296.             ang = Angle(-90, 0, 0),
  297.         }
  298.         ENT.PartPropellerBase =
  299.         {
  300.             mdl = "models/props_junk/PopCan01a.mdl",
  301.             pos = Vector(-70, 0, 25),
  302.             ang = Angle(-90, 0, 0),
  303.         }
  304.  
  305.         ENT.Parts = {}
  306.         ENT.Owner = NULL
  307.  
  308.         function ENT:AttachPart(data)
  309.             local ent = ents.CreateClientProp()
  310.             local pos, ang = LocalToWorld(data.pos, data.ang, self:GetPos(), self:GetAngles())
  311.  
  312.             ent:SetPos(pos)
  313.             ent:SetAngles(ang)
  314.  
  315.             ent:SetModel(data.mdl)
  316.  
  317.             if SERVER then
  318.                 ent:PhysicsInit(SOLID_VPHYSICS)
  319.                 ent:SetSolid(SOLID_VPHYSICS)
  320.             end
  321.  
  322.             if CLIENT then
  323.                 ent:SetParent(self)
  324.             else
  325.                 constraint.Weld(ent, self)
  326.             end
  327.  
  328.             return ent
  329.         end
  330.  
  331.         if CLIENT then
  332.             function ENT:Initialize()
  333.                 self:OnRemove()
  334.  
  335.                 self.Fence = self:AttachPart(self.PartFence)
  336.  
  337.                 self.Propeller = self:AttachPart(self.PartPropellerBase)
  338.                 self.RealPropeller = self.AttachPart(self.Propeller, self.PartPropeller)
  339.             end
  340.  
  341.             function ENT:OnRemove()
  342.                 SafeRemoveEntity(self.Fence)
  343.                 SafeRemoveEntity(self.Propeller)
  344.                 SafeRemoveEntity(self.RealPropeller)
  345.             end
  346.  
  347.             ENT.Rotation = 0
  348.  
  349.             function ENT:Think()
  350.                 local prp = self.Propeller
  351.                 if prp:IsValid() then
  352.                     local vel = WorldToLocal(self:GetVelocity(), Angle(0,0,90), Vector(0), prp:GetAngles())
  353.                     local ang = prp:LocalToWorldAngles(Angle(0, (vel.z * FrameTime() * 5), 0))
  354.                     prp:SetAngles(ang)
  355.                 end
  356.                 self:NextThink()
  357.                 return true
  358.             end
  359.         end
  360.  
  361.         if SERVER then
  362.             ENT.Seat = NULL
  363.             ENT.Driver = NULL
  364.  
  365.             function ENT:Initialize()
  366.                 self:SetModel(self.Model)
  367.  
  368.                 self:PhysicsInit(SOLID_VPHYSICS)
  369.                 self:SetSolid(SOLID_VPHYSICS)
  370.                 self:GetPhysicsObject():SetMass(1000)
  371.                 self:SetColor(Color(60,55,55,255))
  372.  
  373.                 self:StartMotionController()
  374.  
  375.                 local seat = ents.Create("vehicle_weapon_seat")
  376.                 seat:SetModel("models/Nova/airboat_seat.mdl")
  377.                 seat:SetPos(self:GetPos())
  378.                 seat:SetAngles(self:GetAngles() + Angle(180,-90,90))
  379.                 seat:Spawn()
  380.                 seat:SetParent(self)
  381.                 seat:SetColor(Color(0,0,0,0))
  382.                 self.Seat = seat
  383.  
  384.                 local base = self:AttachPart(self.PartPropellerBase)
  385.                     base:GetPhysicsObject():SetMass(100)
  386.                     base:SetNoDraw(true)
  387.                 self.Propeller = base
  388.             end
  389.  
  390.             function ENT:OnRemove()
  391.                 SafeRemoveEntity(self.Seat)
  392.                 SafeRemoveEntity(self.Propeller)
  393.             end
  394.  
  395.             function ENT:SetDriver(ply)
  396.                 if IsValid(ply.Parachute) then
  397.                     ply.Parachute:DropDriver()
  398.                 end
  399.                 self:SetOwner(ply)
  400.                 self.Driver = ply
  401.                 ply.Parachute = self
  402.                 self.Seat:Enter(ply)
  403.             end
  404.  
  405.             function ENT:GetDriver()
  406.                 return self.Seat:IsValid() and self.Seat:GetDriver() or NULL
  407.             end
  408.  
  409.             function ENT:DropDriver()
  410.                 if self.Seat:IsValid() then
  411.                     self.Seat:Drop()
  412.                 end
  413.             end
  414.  
  415.             function ENT:GetBase()
  416.                 return self.Propeller or NULL
  417.             end
  418.  
  419.             function ENT:PhysicsSimulate(phys)
  420.                 if self:WaterLevel() == 3 then
  421.                     self:Remove()
  422.                 end
  423.  
  424.                 -- base er en popcan som sitter i midten på toppen
  425.                 local base = self:GetBase()
  426.                 if base:IsValid() then
  427.                     local basephys = base:GetPhysicsObject()
  428.  
  429.                     if basephys:IsValid() then
  430.                         local ply = self:GetDriver()
  431.                         if ply:IsPlayer() then
  432.                             basephys:AddVelocity(basephys:GetVelocity() * -0.5)
  433.  
  434.                             phys:AddVelocity(self:GetForward() * -phys:GetVelocity():Dot(self:GetForward()) * 0.1)
  435.  
  436.                             local ang = ply:EyeAngles()
  437.                             phys:AddAngleVelocity(Vector((-ang.y+90) * 0.4, 0, 0))
  438.                             ang.p = math.Clamp(ang.p, -30, 30)
  439.                             basephys:AddVelocity(self:LocalToWorldAngles(ang):Up() * -100)
  440.  
  441.                             phys:AddAngleVelocity(phys:GetAngleVelocity() * -0.5)
  442.  
  443.                         else
  444.                             self:Remove()
  445.                         end
  446.                     end
  447.                 end
  448.  
  449.                 self:NextThink(CurTime())
  450.                 return true
  451.             end
  452.         end
  453.  
  454.         scripted_ents.Register(ENT, ENT.ClassName, true)
  455.     end
  456.     -- weapon
  457.     do
  458.         local SWEP = {Primary = {}, Secondary = {}}
  459.  
  460.         SWEP.Base = "weapon_base"
  461.  
  462.         SWEP.ClassName = "permaprop_tool"
  463.         SWEP.PrintName = "PermaProp Maker"
  464.         SWEP.Instructions = "primary attack to make and secondary to unmake"
  465.  
  466.         SWEP.HoldType = "pistol"
  467.  
  468.         SWEP.Primary.Automatic = false
  469.         SWEP.Secondary.Automatic = false
  470.  
  471.         SWEP.Primary.TakeAmmo  = 0
  472.         SWEP.Secondary.TakeAmmo  = 0
  473.  
  474.         if CLIENT then
  475.             function SWEP.CommandEffect(ent, bool, udata)
  476.                 if IsEntity(udata) and udata:IsPlayer() then
  477.                     if bool then
  478.                         notification.AddLegacy(udata:Nick() .. " permapropped " .. ent:GetModel():match(".+/(.+)%.mdl"), NOTIFY_GENERIC, 2)
  479.                     else
  480.                         notification.AddLegacy(udata:Nick() .. " unpermapropped " .. ent:GetModel():match(".+/(.+)%.mdl"),1, 2)
  481.                     end
  482.                 end
  483.             end
  484.             hook.Add("OnPermaPropSet", "permaprop_command", SWEP.CommandEffect)
  485.  
  486.             local mat = Material("models/shiny")
  487.  
  488.             function SWEP:DrawOverlay()
  489.                 local tr = self.Owner:GetEyeTrace()
  490.                 local ent = tr.Entity
  491.  
  492.                 if ent:IsValid() and not ent:IsWorld() then
  493.                     local m = (self.Owner == LocalPlayer() and 1 or 0.4)
  494.  
  495.                     render.SetBlend(0.6 * m)
  496.                         render.MaterialOverride(mat)
  497.                             if ent:IsPermaProp() then
  498.                                 render.SetColorModulation(0.4 * m, 0.4 * m, 6 * m)
  499.                             else
  500.                                 render.SetColorModulation(6 * m, 0.4 * m, 0.4 * m)
  501.                             end
  502.  
  503.                                 ent:DrawModel()
  504.  
  505.                             render.SetColorModulation(1, 1, 1)
  506.                         render.MaterialOverride()
  507.                     render.SetBlend(1)
  508.                 end
  509.             end
  510.  
  511.             hook.Add("PostDrawTranslucentRenderables", "FindPermaprops", function()
  512.                 for key, ply in pairs(player.GetAll()) do
  513.                     local wep = ply:GetActiveWeapon()
  514.                     if wep:IsWeapon() and wep:GetClass() == SWEP.ClassName then
  515.                         wep:DrawOverlay()
  516.                     end
  517.                 end
  518.             end)
  519.  
  520.             SWEP.PrimaryAttack = function() end
  521.             SWEP.SecondaryAttack = function() end
  522.         end
  523.  
  524.         if SERVER then
  525.  
  526.             function SWEP:Initialize()
  527.             end
  528.  
  529.             function SWEP:SetPerma(bool)
  530.                 local trace = self.Owner:GetEyeTrace()
  531.                 local ent = trace.Entity
  532.  
  533.                 if ent:IsValid() and (not ent.CPPIGetOwner or ((ent:CPPIGetOwner() == self.Owner) or self.Owner:CheckUserGroupLevel("moderators"))) then
  534.                     if bool then
  535.                         if permaprops.CanSaveEntity(ent) then
  536.                             ent:SetPermaProp(true, nil, self.Owner)
  537.                             ent:EmitSound("buttons/button9.wav", 70, bool and 100 or 80 )
  538.                         else
  539.                             ent:EmitSound("buttons/button10.wav", 70, 70)
  540.                         end
  541.                     else
  542.                         if ent:IsPermaProp() then
  543.                             ent:SetPermaProp(false, nil, self.Owner)
  544.                             ent:EmitSound("buttons/button10.wav", 70)
  545.                         end
  546.                     end
  547.                 end
  548.             end
  549.  
  550.             function SWEP:PrimaryAttack()
  551.                 self:SetPerma(true)
  552.             end
  553.  
  554.             function SWEP:SecondaryAttack()
  555.                 self:SetPerma(false)
  556.             end
  557.         end
  558.  
  559.         weapons.Register(SWEP, SWEP.ClassName, true)
  560.     end
  561.  
  562.     do -- server
  563.         local META = FindMetaTable("Entity")
  564.  
  565.         function META:IsPermaProp()
  566.             return self:GetNWBool("permaprops")
  567.         end
  568.  
  569.         function META:SetPermaProp(bool, skip_save, udata)
  570.             if self.CollisionRulesChanged then
  571.                 self:CollisionRulesChanged()
  572.             end
  573.  
  574.             if SERVER then
  575.                 if bool then
  576.                     permaprops.ConvertEntity(self)
  577.                 end
  578.  
  579.                 if not skip_save then
  580.                     if bool then
  581.                         permaprops.SaveEntity(self, udata)
  582.                     else
  583.                         if hook.Call("PermaPropsDeleteEntity", GAMEMODE, self, udata) ~= false then
  584.                             if self.permaprops_file then
  585.                                 file.Delete(self.permaprops_file)
  586.                             end
  587.                         end
  588.                     end
  589.                 end
  590.  
  591.                 udata = udata or NULL
  592.                 udata = glon.encode(udata)
  593.  
  594.                 umsg.Start("permaprops")
  595.                     umsg.Entity(self)
  596.                     umsg.Bool(bool)
  597.                     umsg.String(udata)
  598.                 umsg.End()
  599.  
  600.                 self:SetNWBool("permaprops", bool)
  601.             end
  602.  
  603.             if CLIENT and udata and #udata ~= 0 then
  604.                 udata = glon.decode(udata)
  605.             end
  606.  
  607.             hook.Call("OnPermaPropSet", GAMEMODE, self, bool, udata)
  608.         end
  609.  
  610.         if CLIENT then
  611.             function permaprops.PermaPropMessage(umr)
  612.                 local ent = umr:ReadEntity()
  613.                 local bool = umr:ReadBool()
  614.                 local udata = umr:ReadString()
  615.  
  616.                 if ent:IsValid() and not ent:IsPlayer() then
  617.                     ent:SetPermaProp(bool, nil, udata)
  618.                 end
  619.             end
  620.  
  621.             usermessage.Hook("permaprops", permaprops.PermaPropMessage)
  622.         end
  623.     end
  624. end
  625.  
  626. do -- hook
  627.     if CLIENT then
  628.         local tab =
  629.         {
  630.             ["$pp_colour_mulr"] = 0,
  631.             ["$pp_colour_mulg"] = 0,
  632.             ["$pp_colour_addr"] = 0,
  633.             ["$pp_colour_addg"] = 0,
  634.             ["$pp_colour_addb"] = 0,
  635.             ["$pp_colour_colour"] = 1,
  636.             ["$pp_colour_contrast"] = 1,
  637.             ["$pp_colour_brightness"] = 0,
  638.         }
  639.  
  640.         local mult = 0
  641.         usermessage.Hook("permaprops_parachutespawn", function()
  642.             hook.Add( "RenderScreenspaceEffects", "EEK",  function()
  643.                 mult = mult + (FrameTime() * 0.1)
  644.  
  645.                 if mult > 1 then
  646.                     hook.Remove( "RenderScreenspaceEffects", "EEK" )
  647.                     mult = 0
  648.                 else
  649.  
  650.                     tab["$pp_colour_contrast"] = mult,
  651.                     DrawColorModify(tab)
  652.                 end
  653.             end)
  654.         end)
  655.     end
  656.  
  657.     if SERVER and game.GetMap():lower():find("endlessocean") then
  658.         function permaprops.AttachPropellerInitialize(ply)
  659.             ply:SetPos(Vector()*16000)
  660.             ply:Kill()
  661.             ply:GetRagdollEntity():Remove()
  662.         end
  663.        
  664.         function permaprops.AttachPropeller(ply)
  665.             if false then
  666.             if IsValid(ply.Parachute) then
  667.                 ply.Parachute:Remove()
  668.             end
  669.  
  670.             local self = ents.Create("parachute")
  671.  
  672.             self:Spawn()
  673.  
  674.             self:SetPos(Vector(math.Rand(-1,1) * 300, math.Rand(-1, 1) * 300, 3900))
  675.             self:SetAngles(Angle(0,0,0))
  676.             ply:SetPos(self:GetPos())
  677.  
  678.             self:GetPhysicsObject():SetVelocity(vector_origin)
  679.  
  680.             self.Seat.up_offset = 43.5
  681.             self.Seat.right_offset = 1.75
  682.             self.Seat.forward_offset = 0
  683.  
  684.             self:SetDriver(ply)
  685.  
  686.             SendUserMessage("permaprops_parachutespawn", ply)
  687.             end
  688.             ply:Give("permaprop_tool")
  689.         end
  690.  
  691.         hook.Add("PlayerSpawn", "permaprops_parachute", permaprops.AttachPropeller)
  692.         hook.Add("PlayerInitialSpawn", "permaprops_parachute", permaprops.AttachPropellerInitialize)
  693.     end
  694.  
  695.     local not_allowed =
  696.     {
  697.         colour = 1,
  698.         material = 1,
  699.         ballsocket_ez = 1,
  700.         ballsocket_adv = 1,
  701.         ballsocket = 1,
  702.         motor = 1,
  703.         axis = 1,
  704.         remover = 1,
  705.         weld_ez = 1,
  706.     }
  707.  
  708.     function permaprops.CanTool(ply, trace, toolmode)
  709.         local ent = trace.Entity
  710.  
  711.         if ent:IsPermaProp() and not_allowed[toolmode] then
  712.             return false
  713.         end
  714.     end
  715.  
  716.     function permaprops.PhysgunPickup(ply, ent)
  717.         if ent:IsPermaProp() then
  718.             return false
  719.         else
  720.             ply.permaprop_pickup = ent
  721.         end
  722.     end
  723.  
  724.     function permaprops.PhysgunDrop(ply, ent)
  725.         ply.permaprop_pickup = NULL
  726.     end
  727.  
  728.     function permaprops.OnPhysgunFreeze(_,_, ent, ply)
  729.         ply.permaprop_pickup = NULL
  730.     end
  731.  
  732.     function permaprops.ShouldCollide(a, b)
  733.         if a:IsPermaProp() and b:IsPermaProp() then
  734.             return false
  735.         end
  736.     end
  737.  
  738.     function permaprops.CanPlayerUnfreeze(_, ent)
  739.         if ent:IsPermaProp() then
  740.             return false
  741.         end
  742.     end
  743.  
  744.     HOOK("CanTool")
  745.     HOOK("PhysgunPickup")
  746.     HOOK("PhysgunDrop")
  747.     HOOK("OnPhysgunFreeze")
  748.     HOOK("ShouldCollide")
  749.     HOOK("CanPlayerUnfreeze")
  750.  
  751.     if SERVER then
  752.  
  753.         function permaprops.HidePropsThink()
  754.             if permaprops.FadeDist > 0 then
  755.                 for key, ent in pairs(ents.GetAll()) do
  756.                     if ent:IsPermaProp() then
  757.                         local not_visible = true
  758.                         for key, ply in pairs(player.GetAll()) do
  759.                             if ent:GetPos():Distance(ply:EyePos()) < permaprops.FadeDist then
  760.                                 not_visible = false
  761.                             end
  762.                         end
  763.                         ent:SetNoDraw(not_visible)
  764.                     end
  765.                 end
  766.             end
  767.         end
  768.         timer.Create("optimize_permaprops", 0.2, 0, permaprops.HidePropsThink)
  769.     end
  770.  
  771.     HOOK("PostInitEntity")
  772. end
  773.  
  774. if CLIENT then
  775.     SetSkyColor(Vector(0.5,0.75,1)*0.0025)
  776.     local emitter = ParticleEmitter(EyePos())
  777.  
  778.     hook.Add("RenderScreenspaceEffects", "hm", function()
  779.       --  DrawToyTown( 20, 1000)
  780.  
  781.         local tbl = {}
  782.             tbl[ "$pp_colour_addr" ] = 0.08
  783.             tbl[ "$pp_colour_addg" ] = 0.03
  784.             tbl[ "$pp_colour_addb" ] = 0.02
  785.             tbl[ "$pp_colour_brightness" ] = -0.04
  786.             tbl[ "$pp_colour_contrast" ] = 1.4
  787.             tbl[ "$pp_colour_colour" ] = 0.7
  788.             tbl[ "$pp_colour_mulr" ] = 0
  789.             tbl[ "$pp_colour_mulg" ] = 0
  790.             tbl[ "$pp_colour_mulb" ] = 0
  791.         DrawColorModify( tbl )
  792.        
  793.         for i=1, 5 do
  794.             local particle = emitter:Add("particle/Particle_Glow_05", LocalPlayer():EyePos() + VectorRand() * 500)
  795.             if particle then
  796.                 local col = HSVToColor(math.random()*30, 0.1, 1)
  797.                 particle:SetColor(col.r, col.g, col.b, 266)
  798.  
  799.                 particle:SetVelocity(VectorRand() )
  800.  
  801.                 particle:SetDieTime((math.random()+4)*3)
  802.                 particle:SetLifeTime(0)
  803.  
  804.                 local size = 1
  805.  
  806.                 particle:SetAngles(AngleRand())
  807.                 particle:SetStartSize((math.random()+1)*2)
  808.                 particle:SetEndSize(0)
  809.  
  810.                 particle:SetStartAlpha(0)
  811.                 particle:SetEndAlpha(255)
  812.  
  813.                 --particle:SetRollDelta(math.Rand(-1,1)*20)
  814.                 particle:SetAirResistance(500)
  815.                 particle:SetGravity(VectorRand() * 10)
  816.             end
  817.         end
  818.  
  819.     end)
  820. end
  821.  
  822. if SERVER then
  823.     all:StripWeapons()
  824.     for k,v in pairs(player.GetAll()) do
  825.         local ang = v:EyeAngles()
  826.         local pos = v:GetPos()
  827.         v:StripWeapons()
  828.         v:Kill()
  829.         v:Spawn()
  830.         v:SetPos(pos)
  831.         v:SetEyeAngles(ang)
  832.         hook.Run("PlayerLoadout", v)
  833.         hook.Run("PlayerSpawn", v)
  834.     end
  835.    
  836.     hook.Remove("PlayerSpawnProp", "UpplCheckModel")
  837. end
Advertisement
Add Comment
Please, Sign In to add comment