How do I limit the amount of money a DarkRP Printer can hold?
6 replies, posted
[B][I]This has already been solved.[/I][/B]
I'm currently modding the DarkRP printer, and I was wondering how I would limit the amount of money a printer can hold? ( I'm a noob at coding :( )
Here is my init.lua code:
[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:SetColor( Color( 36, 114, 224, 255 ) )
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
phys:Wake()
self.sparking = false
self.damage = 100
self.IsMoneyPrinter = true
timer.Simple(0.5, function() PrintMore(self) end)
end
PrintMore = function(ent)
if not IsValid(ent) then return end
ent.sparking = true
timer.Simple(0.5, function()
if not IsValid(ent) then return end
ent:CreateMoneybag()
end)
end
function ENT:CreateMoneybag()
if not IsValid(self) or self:IsOnFire() then return end
local MoneyPos = self:GetPos()
local amount = 1
self:SetMoney( self:GetMoney() + amount )
self.sparking = false
timer.Simple(0.5, function() PrintMore(self) end)
end
function ENT:Use( ply )
if self:GetMoney() > 0 then
ply:addMoney( self:GetMoney() )
DarkRP.notify( ply, 0, 10, "You received $" .. self:GetMoney() .. " from this printer.")
self:SetMoney( 0 )
end
end
function ENT:OnRemove()
if self.sound then
self.sound:Stop()
end
end[/CODE]
If you need more code or information, just let me know.
[url]http://wiki.garrysmod.com/page/math/max[/url]
[editline]25th March 2016[/editline]
wrap
self:GetMoney() + amount
in math.max
[editline]25th March 2016[/editline]
ooops im dumb one second
ment this one not max
[url]http://wiki.garrysmod.com/page/math/Clamp[/url]
[QUOTE=kulcris;50004494][url]http://wiki.garrysmod.com/page/math/max[/url]
[editline]25th March 2016[/editline]
wrap
self:GetMoney() + amount
in math.max
[editline]25th March 2016[/editline]
ooops im dumb one second
ment this one not max
[url]http://wiki.garrysmod.com/page/math/Clamp[/url][/QUOTE]
He meant how much the printer can hold. Not how much maximum it can send out.
Your printer seems to send out money bags infinitely. You might want to design it so it that sends them out a certain amount of times. Or modify already existing printers to your needs.
Alright, I'll try both ways when I'm done cooking :P
[QUOTE=Maravis;50004563]He meant how much the printer can hold. Not how much maximum it can send out.
Your printer seems to send out money bags infinitely. You might want to design it so it that sends them out a certain amount of times. Or modify already existing printers to your needs.[/QUOTE]
no it does not create money bags, it uses the "createmoneybag" function but it is storing the money in itself (hense "self") by adding a clamp to self:SetMoney( self:GetMoney() + amount ) you are effectively making it so that all "money bags" that are created can not go over whatever you set the amount to.
[editline]25th March 2016[/editline]
math.max is not what you want, dont use that
[editline]25th March 2016[/editline]
or of course you can wrap ent:CreateMoneybag() (inside the printmore function) in an
[lua]
if ent:GetMoney() <= yourmax then
ent:CreateMoneybag()
end
[/lua]
Thank you kulcris! That math.clamp worked :D
np, please mark thread as solved :)
Sorry, you need to Log In to post a reply to this thread.