• Upgradable Printers
    4 replies, posted
Im trying to create custom money printers that upgrade when you click the button 'upgrade'. So far (with some help), I've been able to successfully code the printers to store a variable (PrintA) that when the user press the button "collect money" it takes the money from that variable. My question is, how can I make these printers upgradable. For ex. Press 'e' on printer, menu pops up and you click the button upgrade. THis brings it to level 2/5, it will now print a larger amount than level 1.. I'm so confused on this. 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, -TextWidth*0.5, -120, "Level 1/10", "HUDNumber5", Color(0, 0, 0, 100), Color(255,255,255,255)) 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( um ) LocalPlayer():ConCommand( "-use" ) RunConsoleCommand( "-use" ) local ent = um:ReadString() local base = vgui.Create( "DFrame" ) local button = vgui.Create( "DButton" ) local upgrade = vgui.Create( "DButton" ) base:SetPos(ScrW()/2 - 150, ScrH()/2 - 100 ) base:SetSize( 300, 200 ) base:SetVisible( true ) base:SetTitle( "Money Printer" ) base:SetDraggable( true ) base:ShowCloseButton( true ) base:MakePopup() button:SetParent( base ) button:SetPos(75,100) button:SetText( "Collect Money" ) button:SetSize( 150, 50 ) button.DoClick = function() RunConsoleCommand( "eject_money", ent ) end upgrade:SetParent( base ) upgrade:SetText( "Upgrade" ) upgrade:SetPos(75, 50) upgrade:SetSize( 150, 50 ) upgrade.DoClick = function() RunConsoleCommand( "upgrade", ent ) end end usermessage.Hook( "userMenu", printopen ) [/CODE] init.lua [CODE] AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") local PrintMore function ENT:Initialize() self:SetModel("models/props_c17/consolebox01a.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetUseType(SIMPLE_USE) 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 = 200 local printtime = 300 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, cmd, args ) -- local ent = nil -- for k, v in ipairs( ents.GetAll() ) do if ( tostring( v ) == table.concat( args ) ) then ent = v end end -- if( activator:IsPlayer() ) then if ( ent:GetNWInt( "PrintA" ) >= 1 ) then activator:AddMoney( ent:GetNWInt( "PrintA" ) ); GAMEMODE:Notify( activator, 1, 4, "You have collected $" .. ent:GetNWInt( "PrintA" ) .. " from the Money Printer." ) ent:SetNWInt( "PrintA", 0 ) end end end ); concommand.Add( "upgrade", function( activator, cmd, args, intCurrentLevel, intUpgradeLevel) -- local ent = nil -- for k, v in ipairs( ents.GetAll() ) do if ( tostring( v ) == table.concat( args ) ) then ent = v end end -- if( activator:IsPlayer() ) then end end function ENT:Use(activator, caller) umsg.Start( "userMenu", activator ) umsg.String( tostring( self ) ) umsg.End() end function ENT:OnRemove() if self.sound then self.sound:Stop() end end[/CODE] Just so you know, im a pretty big noob at lua, and if neccessary I can pay a fee of like 5$ for someone to finish this for me.
I think you might find what you want on [URL="http://coderhire.com/"]Coder Hire[/URL].
I was hoping one of you guys would just save me some time and do it for me...
[QUOTE=JeffDOA;41977634]I think you might find what you want on [URL="http://coderhire.com/"]Coder Hire[/URL].[/QUOTE] If he was to BUY a script of printers and save the time thats one thing. Also it seems he wants to try and fix this up. (I suggest not getting someone to "finish up" something if pretty much the core is working as of now.) Wish i could help but tbh the way i would do it would probablly... suck. haha. But honestlly you should try and do this on your own and not go onto Coderhire. Making printers is not the hardest thing in the world. Including upgradable ones. Its just how good they look and work is where it gets hard. .... Just keep going at it and read tuts :P
Its hard to read tuts though because their code doesnt incorporate with mine.
Sorry, you need to Log In to post a reply to this thread.