CapsAdmin

Untitled

Nov 4th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. easylua.StartEntity("sent_juice")
  2. ENT.Type = "anim"
  3. ENT.Base = "base_gmodentity"
  4. ENT.Model = Model("models/props_junk/glassjug01.mdl")
  5. ENT.ClassName = "sent_juice"
  6.  
  7. function ENT:Initialize()
  8.     self.CreateTime = CurTime()
  9.     if(SERVER) then
  10.         self:SetJColor(HSVToColor(math.random(360),1,1))
  11.         self:SetNWInt("Height",200)
  12.         self:SetModel(ENT.Model)
  13.         self:PhysicsInit(SOLID_VPHYSICS)
  14.         self:SetMoveType(MOVETYPE_VPHYSICS)
  15.         self:SetSolid(SOLID_VPHYSICS)
  16.         self:StartMotionController()
  17.         local phys = self:GetPhysicsObject()
  18.         if(phys:IsValid()) then
  19.             phys:SetMass(100)
  20.             phys:Wake()
  21.             --phys:EnableGravity(false)
  22.             phys:EnableMotion(true)
  23.         end
  24.         self:PhysWake()
  25.         self:SetUseType(SIMPLE_USE)
  26.     else
  27.         --self:SetRenderGroup(
  28.         self.Juice = ClientsideModel("models/holograms/hq_cylinder.mdl",RENDERGROUP_BOTH)
  29.         self.Juice:SetNoDraw(true)
  30.     end
  31. end
  32.  
  33. function ENT:Draw()
  34.    
  35.     render.SuppressEngineLighting(true)
  36.     local scale = Vector(0.45,0.45,0.25 * (self:GetNWInt("Height")/100))
  37.     local color = Color(self:GetNWInt("R"),self:GetNWInt("G"),self:GetNWInt("B"))
  38.     self.Juice:SetRenderOrigin(self:LocalToWorld(scale*Vector(0,0,6)+Vector(0,0,0.48)))
  39.     self.Juice:SetModelScale(scale)
  40.     self.Juice:SetRenderAngles(self:GetAngles())
  41.     render.SetColorModulation(color.r / 255, color.g /255, color.b /255)
  42.     self.Juice:SetupBones()
  43.     self.Juice:DrawModel()
  44.     self.Juice:SetModelScale(scale*-1)
  45.     self.Juice:SetupBones()
  46.     self.Juice:DrawModel()
  47.     render.SetColorModulation(1,1,1)
  48.     render.SuppressEngineLighting(false)
  49.     self:DrawModel()
  50. end
  51.  
  52. function ENT:IsTranslucent()
  53.     return true
  54. end
  55. local emitter = nil
  56. function ENT:GetJuice()
  57.     return self:GetNWInt("Height")
  58. end
  59. function ENT:GetJColor()
  60.     return Color(self:GetNWInt("R"),self:GetNWInt("G"),self:GetNWInt("B"))
  61. end
  62.  
  63. local mat = Material("particle/rain")
  64. local callback
  65. callback = function(part, pos, norm)
  66.     part:SetVelocity(part:GetVelocity() + Vector(math.random(-3,3),math.random(-3,3),math.random(0,2))*30)
  67.     util.DecalEx(mat, LocalPlayer(), pos, norm, 100, 100, 1)
  68. end
  69.  
  70. function ENT:Think()
  71.     if(self:GetUp().z < 0) then
  72.         if(CLIENT) then
  73.             emitter = emitter or ParticleEmitter(self:GetPos())
  74.             emitter:SetPos(self:GetPos())
  75.             for I=1,2 do
  76.                 local part = emitter:Add("particle/rain",self:GetPos()+self:GetUp()*12)
  77.                 if part then
  78.                     part:SetDieTime(10)
  79.                     part:SetLifeTime(0)
  80.                     local col = self:GetJColor()
  81.                     part:SetColor(col.r,col.g,col.b,255)
  82.                     part:SetStartSize(0)
  83.                     part:SetEndSize(50)
  84.                     part:SetStartLength(8)
  85.                     part:SetEndLength(8)
  86.                     part:SetGravity(physenv.GetGravity())
  87.                     part:SetVelocity(Vector(math.random(-0.5,0.5),math.random(-0.5,0.5),math.random(0,-1))*2)
  88.                     part:SetCollide(true)
  89.                     part:SetBounce(0.2)
  90.                     part:SetCollideCallback(callback)
  91.                 end
  92.                
  93.             end
  94.         else
  95.             --self:SetJuice(self:GetJuice()-1)
  96.         end
  97.     end
  98.     self:NextThink(RealTime()+1)
  99. end
  100.  
  101. if(SERVER) then
  102.     function ENT:SetJColor(color)
  103.         if(color.r and color.g and color.b) then
  104.             self:SetNWInt("R",color.r)
  105.             self:SetNWInt("G",color.g)
  106.             self:SetNWInt("B",color.b)
  107.         end
  108.     end
  109.    
  110.  
  111.    
  112.    
  113.     function ENT:SetJuice(num)
  114.         if(type(num)=="number") then
  115.             self:SetNWInt("Height",math.Clamp(num,0,200))
  116.             if(num<=0) then self:Remove() end
  117.         end
  118.     end
  119.        
  120.     function ENT:Use(act,cal)
  121.         if(act:GetEyeTrace().Entity==self) then
  122.             WorldSound("vo/sandwicheat09.wav",act:GetShootPos(),75,100)
  123.             --self:EmitSound("vo/sandwicheat09.wav")
  124.             act:SetHealth(act:Health()+5)
  125.             self:SetJuice(self:GetJuice()-50)
  126.         end
  127.        
  128.     end
  129. end
  130. easylua.EndEntity(true, true)
Advertisement
Add Comment
Please, Sign In to add comment