Hi again, im running an HL2rp and today i was in want of making a coffee machine so i did it but when a player buy the coffee it claim him 20tk (money), and then all the coffee are free for everyone.
This is my code
[CODE] function ENT:SalePrice(activator)
local discounted = math.ceil(20)
-- If they are still a cook, sell them the food at the discounted rate
if self.allowed and type(self.allowed) == "table" and table.HasValue(self.allowed, activator:Team()) then
return discounted
else -- Otherwise, sell it to them at full price
return math.ceil(20)
end
end
function ENT:Use( activator, caller )
self.user = activator
if not activator:canAfford(self:SalePrice(activator)) then
DarkRP.notify(activator, 1, 3, DarkRP.getPhrase("cant_afford", string.lower(DarkRP.getPhrase("food"))))
return ""
end
if activator.maxFoods and activator.maxFoods >= GAMEMODE.Config.maxfoods then
DarkRP.notify(activator, 1, 3, DarkRP.getPhrase("limit", string.lower(DarkRP.getPhrase("food"))))
elseif not self.Once then
self.Once = true
self.sparking = true
local discounted = math.ceil(20)
local cash = self:SalePrice(activator)
activator:addMoney(cash * -1)
DarkRP.notify(activator, 0, 3, DarkRP.getPhrase("you_bought", string.lower(DarkRP.getPhrase("food")), DarkRP.formatMoney(cash))) return
end
if delay_can == false then
local ent = ents.Create( "canette" )
activator:EmitSound( Sound( "ambient/levels/labs/coinslot1.wav" ) )
ent:SetPos( self:GetPos() + ( self:GetForward() * 30 ) + ( self:GetUp() * -30 ) )
ent:SetAngles( self:GetAngles() + Angle( 0, 0, 90 ) )
ent:Spawn()
ent:Activate()
ent:GetPhysicsObject():ApplyForceCenter( self:GetForward() * 150 )
delay_can = true
timer.Simple( 3, function()
delay_can = false
end )
end
end
function ENT:Think()
end
return
end[/CODE]
A little bit long to read.
Thank all for help.
Check your self.Once, you only allow it to be called once because you set it to true.
Thx man !
Sorry, you need to Log In to post a reply to this thread.