Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2021
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.30 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. ENT.Type = "anim"
  4.  
  5. ENT.PrintName = "Private Reserve"
  6. ENT.Instructions = "Use the machine only if you're worthy"
  7. ENT.Author = "Azbr"
  8. ENT.Purpose = "Provide Reserve only to those who deserve it."
  9. ENT.Spawnable = true
  10. ENT.Category = "Azbr's Gizmos"
  11.  
  12.  
  13. ENT.Menuopensound = (Sound("ambient/levels/labs/coinslot1.wav"))
  14. local Menuchoicesound = (Sound("buttons/button1.wav"))
  15.  
  16. local DrinkSelections = {"reservecanhp1", "reservecanhp2", "reservecanar1", "reservecanar2", "reservecanmix", "reservecanmix2"}
  17. local DrinkSelectionTitles = {"Classic Reserve", "Diet Reserve", "Cherry Reserve", "Diet Cherry Reserve", "Reserve Twist!", "Diet Reserve Twist!"}
  18. local drink
  19. local classname = "reservemachine"
  20.  
  21. sound.Add({
  22.     name = "Azbr_Machine_ProductFalling",
  23.     channel = CHAN_STATIC,
  24.     volume = 0.75,
  25.     level = 75,
  26.     pitch = {90,110},
  27.     sound = {"azbr/azbr_reservemachine/productfall.wav"}
  28.           })
  29.  
  30. sound.Add({
  31.     name = "Azbr_Machine_Reserve_Playthisonremove",
  32.     channel = CHAN_AUTO,
  33.     volume = 1,
  34.     level = 80,
  35.     pitch = {90,110},
  36.     sound = {"vo/citadel/br_ohshit.wav", "vo/citadel/br_no.wav", "vo/citadel/br_failing11.wav",
  37.              "vo/citadel/br_youneedme.wav","vo/citadel/br_youfool.wav","vo/citadel/br_mock09.wav",}
  38. })
  39.  
  40. sound.Add({
  41.     name = "Azbr_Machine_Reserve_Playthisonspawn",
  42.     channel = CHAN_AUTO,
  43.     volume = 1,
  44.     level = 80,
  45.     pitch = {90,110},
  46.     sound = {"vo/citadel/br_mock05.wav", "vo/citadel/br_laugh01.wav", "vo/k_lab/br_tele_02.wav",
  47.              "vo/k_lab/br_tele_03.wav","vo/breencast/br_tofreeman06.wav",}
  48. })
  49.  
  50.  
  51.  
  52. if SERVER then
  53.  
  54.     function ENT:Initialize()
  55.         self:SetModel("models/props_interiors/VendingMachineSoda01a.mdl")
  56.  
  57.         self:PhysicsInit(SOLID_VPHYSICS)
  58.         self:SetMoveType(MOVETYPE_VPHYSICS)
  59.         self:SetSolid(SOLID_VPHYSICS)
  60.         self:SetUseType(3)
  61.         self:GetPhysicsObject():SetMass(1600)
  62.        
  63.  
  64.         local phys = self:GetPhysicsObject()
  65.  
  66.         if(phys:IsValid()) then
  67.             phys:Wake()
  68.  
  69.  
  70.         local glow = ents.Create("light_dynamic")
  71.             glow:Spawn()
  72.             glow:Activate()
  73.             glow:SetPos(self:LocalToWorld(Vector(60, 0, 16))) -- FRONT, RIGHT/LEFT, UP/DOWN (Facing the vending machine)
  74.             glow:SetKeyValue("distance", 110)
  75.             glow:SetKeyValue("brightness", 7)
  76.             glow:SetKeyValue("_light", "75 140 143 255")
  77.  
  78.             glow:Fire("TurnOn")
  79.             glow:SetParent(self, 1)
  80.  
  81.         self.ambientsound = CreateSound(self, "ambient/machines/air_conditioner_loop_1.wav")
  82.         self.ambientsound:Play()
  83.         self.ambientsound:ChangeVolume(.25,0)
  84.  
  85.         end
  86.     end
  87.            
  88.            
  89.  
  90.     util.AddNetworkString("Reservemenu")
  91.     util.AddNetworkString("Reservechoice")
  92.        
  93.  
  94.     function ENT:SpawnFunction(ply,tr)
  95.  
  96.         if (!tr.Hit)  then return end
  97.  
  98.             local SpLoc = tr.HitPos + tr.HitNormal * 5 
  99.             local playerlook = ply:EyeAngles():ToTable()
  100.             local ent = ents.Create(classname)
  101.             ent:SetPos(SpLoc)
  102.             ent:SetAngles(Angle(0,playerlook[2] +180,0))
  103.             ent:Spawn()
  104.             ent:Activate()
  105.  
  106.             local effectData = EffectData()
  107.             effectData:SetOrigin(ent:GetPos() + (Vector(0,0,5)))
  108.             effectData:SetMagnitude(0.05)
  109.             effectData:SetScale(0.05)
  110.             util.Effect("Explosion", effectData)
  111.             util.ScreenShake(ent:GetPos(), 15, 5, 1.75, 250)
  112.  
  113.             ent:EmitSound("Azbr_Machine_Reserve_Playthisonspawn")
  114.         return ent
  115.     end
  116.  
  117.     function ENT:Use(acti,call) -- When Entity is Used, open the GUI for the client.
  118.         if call:IsPlayer() then
  119.             if (!timer.Exists("ReserveProductSpawning")) then
  120.                 net.Start("Reservemenu")
  121.                 net.WriteEntity(self)
  122.                 net.Send(call)
  123.  
  124.                 self:EmitSound(self.Menuopensound, 80, 100, .75, CHAN_AUTO)
  125.             end                
  126.         end
  127.     end
  128.  
  129.     local existingcans = {}
  130.  
  131.    
  132.         net.Receive("Reservechoice" , function(len,ply)
  133.             if (IsValid(ply) and ply:IsPlayer()) then
  134.                 local TM = (net.ReadEntity())
  135.                 local choice = (net.ReadString())
  136.                 drink = ents.Create(choice)
  137.  
  138.                 drink:SetPos(TM:LocalToWorld(Vector(18,-3.5,-26)))
  139.                 drink:SetAngles(TM:LocalToWorldAngles(Angle(0,0,90)))  
  140.                 drink:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  141.  
  142.                 if TM:IsValid() then
  143.                     if (!timer.Exists("ReserveProductSpawning")) then  
  144.                         timer.Create("ReserveProductSpawning", 0.8, 1, function()  
  145.                             drink:Spawn()
  146.                             drink:GetPhysicsObject():ApplyForceCenter(TM:GetForward())
  147.                         end)
  148.  
  149.                         TM:EmitSound(Menuchoicesound, 80, 100, .75, CHAN_AUTO)
  150.                         timer.Simple(.35, function()
  151.                             TM:EmitSound("ProductFalling") -- SFX of item tumbling out of machine.
  152.                         end)
  153.                     end
  154.                         table.insert(existingcans, drink)
  155.                 end    
  156.             end
  157.         end)
  158.  
  159.  
  160.     function ENT:OnRemove()                               -- This will remove any cans spawned by *ANY* reserve machine when you delete one.
  161.         for k , v in pairs(existingcans) do               -- This is to assist with spam and lag reduction.
  162.             if IsValid(drink) && IsValid(self) then v:Remove()            -- I would make it to where it only deletes cans spawned by the partiuclar machine if I knew how: sorry.
  163.             end                                           -- Comment out the entire function if you wish to turn this off.
  164.         end
  165.  
  166.         table.Empty(existingcans)
  167.         self:EmitSound("Azbr_Machine_Reserve_Playthisonremove")
  168.         self:StopSound("Azbr_Machine_Reserve_Playthisonspawn")
  169.         if self.ambientsound then self.ambientsound:Stop() end
  170.     end
  171.  
  172.  
  173. end -- End of Server Functions.
  174.  
  175. if CLIENT then
  176.  
  177.  
  178.  
  179.     local ButtonColorTable = {Color(30,145,210),Color(30,120,170),Color(165,30,60),Color(135,30,60), Color(255,0,190), Color(255,45,225)}
  180.     local ButtonMessageTable = {}
  181.  
  182.     surface.CreateFont("ReserveFont", {
  183.     font = "Agency FB",
  184.     extended = false,
  185.     size = 27,
  186.     weight = 610,
  187.     blursize = 0,
  188.     scanlines = 0,
  189.     antialias = true,
  190.     underline = false,
  191.     italic = false,
  192.     strikeout = false,
  193.     symbol = false,
  194.     rotary = false,
  195.     shadow = false,
  196.     additive = false,
  197.     outline = false
  198.     } )
  199.  
  200.  
  201.  
  202.     local textcolor = Color(0,0,0)
  203.  
  204.    
  205.  
  206.  
  207.     net.Receive("Reservemenu", function(len)
  208.  
  209.         local ThisMachine = net.ReadEntity()
  210.            
  211.  
  212.         if(!frame) then
  213.             local frame = vgui.Create("DFrame")
  214.             frame:SetTitle("Make your selection.")
  215.             frame:SetSize(300,600)
  216.             frame:Center()
  217.             frame:SetVisible(true)
  218.             frame:MakePopup()
  219.             frame:SetBackgroundBlur(true)
  220.             frame:SetDeleteOnClose(true)
  221.             frame.Paint = function(self,w,h)
  222.                 draw.RoundedBox(8, 0, 0, w, h, Color(120,120,255,200))
  223.             end
  224.  
  225.             local function CreateButton(text,color,iter)
  226.                 local button = vgui.Create("DButton", frame)
  227.                 button:SetFont("ReserveFont")
  228.                 button:SetText(text)
  229.                 button:SetSize(200, 88)
  230.                 button:SetContentAlignment(5)
  231.                 button:Dock(TOP)
  232.                 button:DockMargin(3,0,3,6)
  233.                 button.Paint = function(self,w,h)
  234.                     if (!button:IsHovered()) then
  235.                     draw.RoundedBox(8,0,0,w,h,ButtonColorTable[iter])
  236.                         button:SetTextColor(Color(55,55,55)) else
  237.  
  238.                     draw.RoundedBox(8,0,0,w,h,Color(25,165,25))
  239.                         button:SetTextColor(Color(175,175,175))
  240.                 end
  241.  
  242.                 if button:IsDown() then draw.RoundedBox(5,0,0,w,h,Color(200,200,200))
  243.                 end
  244.             end -- Of button.Paint 
  245.  
  246.  
  247.                 function button:DoClick()
  248.                     net.Start("Reservechoice")
  249.                     net.WriteEntity(ThisMachine)
  250.                     net.WriteString(DrinkSelections[iter])
  251.                     net.SendToServer()
  252.                     frame:Close()  
  253.                 end
  254.  
  255.             end
  256.  
  257.  
  258.             for i = 1, #DrinkSelectionTitles do        
  259.                 CreateButton(DrinkSelectionTitles[i], ButtonColorTable[i], i)                              
  260.             end
  261.    
  262.             function frame:Think() if (!LocalPlayer():Alive()) then if frame then frame:Remove() end end end  -- If you die or press END [Insert] [Home] [Pageup]  close the menu.
  263.             function frame:OnKeyCodePressed(key)     --                                                                                  [Delete] [*END*] [Pagedown]    
  264.                 if (key == KEY_END) then
  265.                     frame:Remove()
  266.                 end        
  267.             end
  268.         end
  269.     end)
  270.  
  271.  
  272.  
  273.     function ENT:Draw()
  274.         self:DrawModel()
  275.        
  276.         local dist = self:GetPos():Distance(LocalPlayer():GetPos())
  277.         if dist <= 999 then
  278.    
  279.             local coords = self:GetPos()
  280.             local angs1 = self:GetAngles()
  281.             local angs2 = self:GetAngles()
  282.             local angs3 = self:GetAngles()
  283.             local angs4 = self:GetAngles()
  284.  
  285.             local h = 42
  286.             local speed = 80
  287.             local h2 = 65 + (math.sin(CurTime() * 2) * 2)
  288.             local textcolor = Color(255,90,90,255)
  289.             local outlinecolor = Color(0,0,0,90)
  290.  
  291.             angs1:RotateAroundAxis(angs1:Forward(), 90)
  292.             angs1:RotateAroundAxis(angs1:Right(), -89)
  293.  
  294.             angs2:RotateAroundAxis(angs2:Forward(), 90)
  295.             angs2:RotateAroundAxis(angs2:Right(), -80)
  296.  
  297.             angs3:RotateAroundAxis(angs3:Forward(),90)
  298.             angs3:RotateAroundAxis(angs3:Right(),CurTime()*85)
  299.  
  300.             angs4:RotateAroundAxis(angs4:Forward(),90)
  301.             angs4:RotateAroundAxis(angs4:Right(),180 + CurTime()*85)
  302.  
  303.  
  304.                 cam.Start3D2D(self:LocalToWorld(Vector(20.5,-8.45,h)), angs1, 0.15)
  305.                     draw.SimpleTextOutlined(" WAY FROM", "ReserveFont", 0, 0, textcolor, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, outlinecolor)
  306.                 cam.End3D2D()
  307.  
  308.                 cam.Start3D2D(self:LocalToWorld(Vector(19.8,-17.8,h)),angs2, 0.15)
  309.                     draw.SimpleTextOutlined("KEEP A","ReserveFont", 0, 0, textcolor, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, 2, outlinecolor)
  310.                 cam.End3D2D()
  311.  
  312.                 //Spinning Text
  313.                 cam.Start3D2D(self:LocalToWorld(Vector(0,0,h2)),angs3,0.45)
  314.                     draw.SimpleTextOutlined("DR BREEN'S","ReserveFont",0,0,Color(150,150,150),TEXT_ALIGN_CENTER,TEXT_ALIGN_TOP,2,outlinecolor) 
  315.                 cam.End3D2D()
  316.                 cam.Start3D2D(self:LocalToWorld(Vector(0,0,h2)),angs4,0.45)
  317.                     draw.SimpleTextOutlined("PRIVATE RESERVE","ReserveFont",0,0,Color(90,165,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_TOP,2,outlinecolor) 
  318.                 cam.End3D2D()
  319.         end
  320.     end
  321.  
  322. end -- End of Client Functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement