• Custom Printer Help
    0 replies, posted
I was coding a money printer where when you pressed e, it would pop up a menu where you could upgrade and collect from it... I've got the VGUI popping up, the collect button does not work though, any idea why? The error I get: cl_init.lua [CODE]include("shared.lua") function ENT:Initialize() end function ENT:Draw() self:DrawModel() local Pos = self:GetPos() local Ang = self:GetAngles() local owner = self:Getowning_ent() owner = (IsValid(owner) and owner:Nick()) or "unknown" local txt1 = "Money Printer" txt2 = "$" ..self:GetNWInt("PrintA") surface.SetFont("HUDNumber5") local TextWidth = surface.GetTextSize(txt1) local TextWidth2 = surface.GetTextSize(txt2) local TextWidth3 = surface.GetTextSize(owner) Ang:RotateAroundAxis(Ang:Up(), 90) cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11) draw.WordBox(2, -TextWidth3*0.5, -78, owner, "HUDNumber5", Color(0, 0, 0, 100), Color(255,255,255,255)) draw.WordBox(2, -TextWidth*0.5, -30, txt1, "HUDNumber5", Color(0, 0, 0, 100), Color(255,255,255,255)) draw.WordBox(2, -TextWidth2*0.5, 18, txt2, "HUDNumber5", Color(0, 0, 0, 100), Color(255,255,255,255)) cam.End3D2D() end function printopen() local base = vgui.Create( "DFrame" ) local button = vgui.Create( "DButton" ) base:SetPos(ScrW()/2 - 150, ScrH()/2 - 100 ) base:SetSize( 300, 200 ) base:SetVisible( true ) base:SetTitle( "Money Printer" ) base:SetDraggable( false ) base:ShowCloseButton( true ) base:MakePopup() button:SetParent( base ) button:SetText( "Collect Money" ) button:Center() button:SetSize( 150, 50 ) button.DoClick = function() LocalPlayer():ConCommand( "eject_money" ) end end usermessage.Hook( "userMenu", printopen )[/CODE] init.lua [CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") ENT.SeizeReward = 950 local PrintMore function ENT:Initialize() self:SetModel("models/props_c17/consolebox01a.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.damage = 100 self.IsMoneyPrinter = true timer.Simple(1.0, function() PrintMore(self) end) self:SetNWInt("PrintA",0) end function ENT:OnTakeDamage(dmg) if self.burningup then return end self.damage = (self.damage or 100) - dmg:GetDamage() if self.damage <= 0 then local rnd = math.random(1, 10) if rnd < 6 then self:BurstIntoFlames() else self:Destruct() self:Remove() end end end function ENT:Destruct() local vPoint = self:GetPos() local effectdata = EffectData() effectdata:SetStart(vPoint) effectdata:SetOrigin(vPoint) effectdata:SetScale(1) util.Effect("Explosion", effectdata) GAMEMODE:Notify(self:Getowning_ent(), 1, 4, "Your money printer has exploded!") end function ENT:BurstIntoFlames() GAMEMODE:Notify(self:Getowning_ent(), 1, 4, "Your money printer is overheating!") self.burningup = true local burntime = math.random(8, 18) self:Ignite(burntime, 0) timer.Simple(burntime, function() self:Fireball() end) end function ENT:Fireball() if not self:IsOnFire() then self.burningup = false return end local dist = math.random(5, 50) -- Explosion radius self:Destruct() for k, v in pairs(ents.FindInSphere(self:GetPos(), dist)) do if not v:IsPlayer() and not v.IsMoneyPrinter then v:Ignite(math.random(5, 22), 0) end end self:Remove() end PrintMore = function(ent) if IsValid(ent) then ent.sparking = true timer.Simple(1.0, function() ent:CreateMoneybag() end) end end function ENT:CreateMoneybag() if not IsValid(self) then return end if self:IsOnFire() then return end local MoneyPos = self:GetPos() local printamount = 15 local printtime = 10 if math.random(1, 1000) == 3 then self:BurstIntoFlames() end local amount = self:GetNWInt("PrintA") + printamount self:SetNWInt("PrintA",amount) self.sparking = false timer.Simple(math.random(10, 15), function() PrintMore(self) end) end concommand.Add( "eject_money", function(activator) if(activator:IsPlayer()) and Entity:GetNWInt("PrintA") >= 1 then activator:AddMoney(Entity:GetNWInt("PrintA")); GAMEMODE:Notify(activator, 1, 4, "You have collected $"..Entity:GetNWInt("PrintA").." from the Money Printer.") Entity:SetNWInt("PrintA",0) end end ); function ENT:Use(activator, caller) umsg.Start( "userMenu", activator ) umsg.Entity( self, activator ); umsg.End() end function ENT:OnRemove() if self.sound then self.sound:Stop() end end[/CODE] shared.lua [CODE]ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName = "Money Printer" ENT.Author = "Render Case and philxyz" ENT.Spawnable = false ENT.AdminSpawnable = false function ENT:SetupDataTables() self:NetworkVar("Int",0,"price") self:NetworkVar("Entity",1,"owning_ent") end[/CODE]
Sorry, you need to Log In to post a reply to this thread.