Help editting a money printer by adding a variable
2 replies, posted
What I'm trying to do is combine the money printer extra code for a money collector to making the printer itself collect the money without spawning the money itself. Whatever I try it just doesn't seem to work.
It's fairly choppy at the moment, I plan on cleaning it up later, but I need it working first.
Problem I am having is the display works, money still spawns and drops on the printer.
Please no complete rewrites, just a good nudge in the right direction, I wanna learn how to do this for future reference.
Here's my code: (and by "my", I mean a lot of copy pasted code, credit to their respected authors.)
init.lua
[code]
-- RRPX Money Printer reworked for DarkRP by philxyz
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
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()
phys:SetMass(50)
end
self.sparking = false
self.damage = 100
self.IsMoneyPrinter = true
self.money = 0
timer.Simple(30, self.CreateMoneybag, self)
end
function ENT:OnTakeDamage(dmg)
if self.burningup then return end
self.damage = self.damage - dmg:GetDamage()
if self.damage <= 0 then
local rnd = math.random(1, 10)
if rnd < 3 then
self:BurstIntoFlames()
else
self:Destruct()
self:RemoveThis()
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)
Notify(self:GetNWEntity("owning_ent"), 1, 4, "Your money printer has exploded!")
end
function ENT:BurstIntoFlames()
if self.Cooler and self.Cooler:GetNWInt("charges") > 0 then
Notify(self:GetNWEntity("owning_ent"), 1, 4, "Your money printer's cooler has used up a charge.\nRemaining charges: "..self.Cooler:GetNWInt("charges"))
self.Cooler:SetNWInt("charges", self.Cooler:GetNWInt("charges") - 1)
else
Notify(self:GetNWEntity("owning_ent"), 1, 4, "Your money printer is overheating!")
self.burningup = true
local burntime = 20
self:Ignite(burntime, 0)
timer.Simple(burntime, self.Fireball, self)
end
end
function ENT:Fireball()
local dist = math.random(20, 280)
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:RemoveThis()
end
local function PrintMore(ent)
if ValidEntity(ent) then
ent.sparking = true
timer.Simple(3, ent.CreateMoneybag, ent)
end
end
function ENT:CreateMoneybag()
if not ValidEntity(self) then return end
if self:IsOnFire() then return end
self:BurstIntoFlames()
local amount = 100
self.money = (self.money + amount)
self.sparking = false
timer.Simple(math.random(100, 350), PrintMore, self)
end
function ENT:Think()
if not self.sparking then return end
local effectdata = EffectData()
effectdata:SetOrigin(self:GetPos())
effectdata:SetMagnitude(1)
effectdata:SetScale(1)
effectdata:SetRadius(2)
util.Effect("Sparks", effectdata)
end
function ENT:Touch( hitEnt )
if hitEnt.IsCooler and not self.Cooler then
self.Cooler = hitEnt
self.OldAngles = self.Entity:GetAngles()
self.Entity:SetAngles(Vector(0, 0, 0))
hitEnt:SetPos(self.Entity:GetPos() + Vector(1.9534912109375, 9.9049682617188, 6.304988861084))
hitEnt:SetAngles(self.Entity:GetAngles() + Vector(0, 90, 0))
constraint.Weld(hitEnt, self.Entity, 0, 0, 0, true)
self.Entity:SetAngles(self.OldAngles)
local phys = hitEnt:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
phys:SetMass(1)
end
end
end
--This function is to remove the printer and any extras attached, creates room for more extras planned to be added
function ENT:RemoveThis()
self:Destruct()
self:Remove()
if self.Cooler then self.Cooler:Remove() end
end
--Allow collection of money by players
function ENT:Use( activator, caller )
activator:AddMoney( self.money )
self.money = 0
end
[/code]
cl_init.lua
[code]
include("shared.lua")
function ENT:Draw()
self:DrawModel()
end
function DrawInfoPrinter()
local tr = LocalPlayer():GetEyeTrace()
if ValidEntity(tr.Entity) and tr.Entity:GetPos():Distance(LocalPlayer():GetPos()) < 400 then
if tr.Entity:GetClass() == "money_printer" then
local ent = tr.Entity
local pos = ent:GetPos()
pos.z = pos.z + 8
pos = pos:ToScreen()
local owner = "N/A!"
if ValidEntity(ent:GetNWEntity("owning_ent")) then
owner = ent:GetNWEntity("owning_ent"):Nick()
end
local text = owner .. "'s\nMoney Printer Printer\nMoney stored: " .. ent:GetNWInt("money")
draw.DrawText(text, "TargetID", pos.x + 1, pos.y + 1, Color(0, 0, 0, 200), 1)
draw.DrawText(text, "TargetID", pos.x, pos.y, Color(255, 255, 255, 200), 1)
end
end
end
hook.Add( "HUDPaint", "DrawInfoPrinter", DrawInfoPrinter )
[/code]
shared.lua
[code]
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Money Printer"
ENT.Author = ""
ENT.Spawnable = false
ENT.AdminSpawnable = false
[/code]
Bump!
Can you show us the original code?
Sorry, you need to Log In to post a reply to this thread.