Dark RP Moneyprinter

Hey Guys

I started Lua coding and wanted to make an MoneyPrinter that can be Updated when you Press E on it. ( Just for a test )
But the MoneyPrinter dosent spawn please help me.

Here is the init.lua Code.



AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

MPLevel=1

local PrintMore
local Entity;
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.sparking = false
	self.damage = 100
	self.IsMoneyPrinter = true
	timer.Simple(27, PrintMore, self)
	MPLevel = 1
  if MPLevel == 1 then
	Entity = ents.Create("prop_physics");
	Entity = ents.Create("prop_dynamic_override");
	Entity:SetPos(self:GetPos() + Vector(0, 0, 14))
	Entity:SetAngles(self:GetAngles() - Angle(0, 0, 0));
	Entity:SetModel("models/props_lab/reciever01b.mdl");
	Entity:SetParent(self);
	Entity:Spawn();
	end
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 < 3 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)
	Notify(self.dt.owning_ent, 1, 4, "Your money printer has exploded!")
end

function ENT:BurstIntoFlames()
	Notify(self.dt.owning_ent, 0, 4, "Your money printer is overheating!")
	self.burningup = true
	local burntime = math.random(8, 18)
	self:Ignite(burntime, 0)
	timer.Simple(burntime, self.Fireball, self)
end

function ENT:Fireball()
	if not self:IsOnFire() then self.burningup = false return end
	local dist = math.random(20, 280) -- 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 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
	local MoneyPos = self:GetPos()

	if math.random(10, 22) == 3 then self:BurstIntoFlames() end
	
	if MPLevel == 1 then
		amount = math.random(150,200)
		self:EmitSound("items/spawn_item.wav", 85, 100)
    elseif MPLevel == 2 then
	    amount = math.random(200,400)
		self:EmitSound("items/spawn_item.wav", 85, 100)
	end


	DarkRPCreateMoneyBag(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15), amount)
	self.sparking = false
	timer.Simple(math.random(10, 330), PrintMore, self)
end

function UpdateMP(ply, key)
	local trace = ply:GetEyeTrace()
	local e = trace.Entity
	if ValidEntity(e) and trace.HitPos:Distance(ply:GetShootPos()) <= 100 then
	  if e = "vip_printer" then
        if key == "USE" and MPLevel == 1 then
           MPLevel = MPLevel + 1
		   print("Your Money Printer is now Level 2")
         end
      end
   end
end
hook.Add( "KeyPress", "KeyPressedHook", UpdateMP )

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



For a start, you might wish to take a look at this: **[ENT.Use

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=ENT.Use)**

[editline]3rd August 2011[/editline]

Also,


	  if e = "vip_printer" then

Should be:


 	  if e == "vip_printer" then

However that’s still wrong, e is an entity, “vip_printer” is just a string, you can’t compare them.

Also, **[G.print

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.print)** will simply print "Your Money Printer is now Level 2 in the servers console, I think you’d be better off using Notify( ply, 1, 4, “Your Money Printer is now Level 2” )

Does it show up in the Q menu? Also, you seem to be missing a spawn function. See here.

Okay Thanks ill try Ent:Use when i have any problems i will post it :slight_smile:

@thefreeman193
Its for a DarkRP Mp

And,


	Entity = ents.Create("prop_physics");
	Entity = ents.Create("prop_dynamic_override");

Are you sure that’s correct?

[editline]3rd August 2011[/editline]

This is for DarkRP, which uses it’s own thing for entities, not the spawnmenu.

Ah yeah, completely forgot about that, haven’t coded for DarkRP in too long :v:

Okay i did it and i cant spawn it.



function ENT:Use( activator, caller )
 
 if activator != ent.Owner then
    Notify( caller, 1, 4, "You're not the Owner of the MoneyPrinter." ) 
    return
	MPLevel = 2
	Notify( caller, 1, 4, "Your Money Printer is now Level 2" ) 
end
 if MPLevel == 1 then
  if not caller:CanAfford(1000)
  	Notify(caller, 1, 10, "You can't afford it!")
    return
    caller:AddMoney(-1000)
    self:SetPos(self:GetPos() + Vector(0,0,10))
	self:SetModel("models/props_lab/reciever_cart.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
 
   end
end
end



function ENT:Use( activator, caller )

	if activator != ent.Owner then
		Notify( caller, 1, 4, "You're not the Owner of the MoneyPrinter." ) 
		return
	end
	
	if MPLevel == 1 then
		if not caller:CanAfford(1000) then
			Notify(caller, 1, 10, "You can't afford it!")
			return
		end
		caller:AddMoney(-1000)
		self:SetPos(self:GetPos() + Vector(0,0,10))
		self:SetModel("models/props_lab/reciever_cart.mdl")
		self:PhysicsInit(SOLID_VPHYSICS)
		self:SetMoveType(MOVETYPE_VPHYSICS)
		self:SetSolid(SOLID_VPHYSICS)
		MPLevel = 2
		Notify( caller, 1, 4, "Your Money Printer is now Level 2" ) 
	end
end

There is another thing you should note, MPLevel needs to be part of each individual money printer created, not the same for every money printer.
Try changing MPLevel to self.MPlevel, wherever you see it.



self.MPLevel = 2


Right?
Or just to create the variable.
And is everything right?

The same everywhere else.

MoneyPrinter still dosent Work -.-’



-- RRPX Money Printer reworked for DarkRP by philxyz
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

local self.MPLevel=1
local PrintMore
local Entity;
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.sparking = false
	self.damage = 100
	self.IsMoneyPrinter = true
	timer.Simple(27, PrintMore, self)
	self.MPLevel = 1
  if self.MPLevel == 1 then
	Entity = ents.Create("prop_physics");
	Entity = ents.Create("prop_dynamic_override");
	Entity:SetPos(self:GetPos() + Vector(0, 0, 14))
	Entity:SetAngles(self:GetAngles() - Angle(0, 0, 0));
	Entity:SetModel("models/props_lab/reciever01b.mdl");
	Entity:SetParent(self);
	Entity:Spawn();
	end
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 < 3 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)
	Notify(self.dt.owning_ent, 1, 4, "Your money printer has exploded!")
end

function ENT:BurstIntoFlames()
	Notify(self.dt.owning_ent, 0, 4, "Your money printer is overheating!")
	self.burningup = true
	local burntime = math.random(8, 18)
	self:Ignite(burntime, 0)
	timer.Simple(burntime, self.Fireball, self)
end

function ENT:Fireball()
	if not self:IsOnFire() then self.burningup = false return end
	local dist = math.random(20, 280) -- 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 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
	local MoneyPos = self:GetPos()

	if math.random(10, 22) == 3 then self:BurstIntoFlames() end
	
	if self.MPLevel == 1 then
		amount = math.random(150,200)
		self:EmitSound("items/spawn_item.wav", 85, 100)
    elseif self.MPLevel == 2 then
	    amount = math.random(200,400)
		self:EmitSound("items/spawn_item.wav", 85, 100)
	end


	DarkRPCreateMoneyBag(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15), amount)
	self.sparking = false
	timer.Simple(math.random(10, 15), PrintMore, self)
end

--function UpdateMP(ply, key)
--	local trace = ply:GetEyeTrace()
--	local e = trace.Entity
--	if ValidEntity(e) and trace.HitPos:Distance(ply:GetShootPos()) <= 100 then
	--  if e = "vip_printer" then
   --     if key == "USE" and MPLevel == 1 then
    --       MPLevel = MPLevel + 1
	--	   print("Your Money Printer is now Level 2")
      --   end
     -- end
  -- end
--end


function ENT:Use( activator, caller )

	if activator != ent.Owner then
		Notify( caller, 1, 4, "You're not the Owner of the MoneyPrinter." ) 
		return
	end
	
	if self.MPLevel == 1 then
		if not caller:CanAfford(1000) then
			Notify(caller, 1, 10, "You can't afford it!")
			return
		end
		caller:AddMoney(-1000)
		self:SetPos(self:GetPos() + Vector(0,0,10))
		self:SetModel("models/props_lab/reciever_cart.mdl")
		self:PhysicsInit(SOLID_VPHYSICS)
		self:SetMoveType(MOVETYPE_VPHYSICS)
		self:SetSolid(SOLID_VPHYSICS)
		self.MPLevel = 2
		Notify( caller, 1, 4, "Your Money Printer is now Level 2" ) 
	end
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


Try this:

[lua]
– RRPX Money Printer reworked for DarkRP by philxyz
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)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
self.sparking = false
self.damage = 100
self.IsMoneyPrinter = true
timer.Simple(27, PrintMore, self)
self.MPLevel = 1
if self.MPLevel == 1 then
Entity = ents.Create(“prop_physics”); --this line is totally redundant, which is it, prop_physics or prop_dynamic_override?!
Entity = ents.Create(“prop_dynamic_override”);
Entity:SetPos(self:GetPos() + Vector(0, 0, 14))
Entity:SetAngles(self:GetAngles() - Angle(0, 0, 0));
Entity:SetModel(“models/props_lab/reciever01b.mdl”);
Entity:SetParent(self);
Entity:Spawn();
end
end

function ENT:OnTakeDamage(dmg)
if self.burningup then return end

self.damage = (self.damage or 100) - dmg:GetDamage()
if self.damage &lt;= 0 then
	local rnd = math.random(1, 10)
	if rnd &lt; 3 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)
Notify(self.dt.owning_ent, 1, 4, “Your money printer has exploded!”)
end

function ENT:BurstIntoFlames()
Notify(self.dt.owning_ent, 0, 4, “Your money printer is overheating!”)
self.burningup = true
local burntime = math.random(8, 18)
self:Ignite(burntime, 0)
timer.Simple(burntime, self.Fireball, self)
end

function ENT:Fireball()
if not self:IsOnFire() then self.burningup = false return end
local dist = math.random(20, 280) – 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 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
local MoneyPos = self:GetPos()

if math.random(10, 22) == 3 then self:BurstIntoFlames() end

local amount
if self.MPLevel == 1 then
	amount = math.random(150,200)
	self:EmitSound("items/spawn_item.wav", 85, 100)
elseif self.MPLevel == 2 then
    amount = math.random(200,400)
	self:EmitSound("items/spawn_item.wav", 85, 100)
end


DarkRPCreateMoneyBag(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15), amount)
self.sparking = false
timer.Simple(math.random(10, 15), PrintMore, self)

end

–function UpdateMP(ply, key)
– local trace = ply:GetEyeTrace()
– local e = trace.Entity
– if ValidEntity(e) and trace.HitPos:Distance(ply:GetShootPos()) <= 100 then
– if e = “vip_printer” then
– if key == “USE” and MPLevel == 1 then
– MPLevel = MPLevel + 1
– print(“Your Money Printer is now Level 2”)
– end
– end
– end
–end

function ENT:Use( activator, caller )

if activator != self.dt.owning_ent then
	Notify( activator, 1, 4, "You're not the Owner of the MoneyPrinter." ) 
	return
end

if self.MPLevel == 1 then
	if not activator:CanAfford(1000) then
		Notify(activator, 1, 10, "You can't afford it!")
		return
	end
	activator:AddMoney(-1000)
	self:SetPos(self:GetPos() + Vector(0,0,10))
	self:SetModel("models/props_lab/reciever_cart.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
	self.MPLevel = 2
	Notify( activator, 1, 4, "Your Money Printer is now Level 2" ) 
end

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[/lua]

Okay got the Error but thanks for Helping me.
It Works now :smiley: