• DarkRP Printer / Upgradeable HELP please.
    2 replies, posted
So I want to create a printer for darkrp that is upgradeable, I am starting at the basic before I satart making interfaces and buttons etc. so here is my code: init.lua: [LUA]-- RRPX Money Printer reworked for DarkRP by philxyz AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") ENT.SeizeReward = 950 local PrintMore local UpgradeDelay = 3 local PrinterLevel = 1 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() phys:Wake() self.sparking = false self.damage = 100 self.IsMoneyPrinter = true timer.Simple(math.random(100, 350), function() PrintMore(self) end) self.PrinterLevel = 1 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) GAMEMODE:Notify(self:Getowning_ent(), 1, 4, "Your money printer has exploded!") end function ENT:BurstIntoFlames() GAMEMODE:Notify(self:Getowning_ent(), 0, 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(20, 280) -- Explosion radius self:Destruct() for k, v in pairs(ents.FindInSphere(self:GetPos(), dist)) do if not v:IsPlayer() and not v:IsWeapon() and v:GetClass() ~= "predicted_viewmodel" and not v.IsMoneyPrinter then v:Ignite(math.random(5, 22), 0) elseif v:IsPlayer() then local distance = v:GetPos():Distance(self:GetPos()) v:TakeDamage(distance / dist * 100, self, self) end end self:Remove() end PrintMore = function(ent) if not IsValid(ent) then return end ent.sparking = true timer.Simple(3, 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() if math.random(1, 22) == 3 then self:BurstIntoFlames() end local amount = GAMEMODE.Config.mprintamount if amount == 0 then amount = 250 end DarkRPCreateMoneyBag(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15), amount) self.sparking = false timer.Simple(math.random(100, 350), function() PrintMore(self) end) end local UpgradeCost = 5000 * self.PrinterLevel function ENT:Use( activator, caller ) if !IsValid( activator ) then return; end --if not CurTime() > (activator.NextUpgradeTime or 0) then -- return --end if not activator:CanAfford(UpgradeCost) then GAMEMODE:Notify(self:Getowning_ent(), 0, 4, "You cannot afford this.") return end activator:AddMoney(-UpgradeCost) activator.NextUpgradeTime = CurTime() + UpgradeDelay end function ENT:Think() if self:WaterLevel() > 0 then self:Destruct() self:Remove() return end 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] Now my error is: [ERROR] lua/entities/upgrade_money_printer/init.lua:100: attempt to index global 'self' (a nil value) 1. unknown - lua/entities/upgrade_money_printer/init.lua:100 Now this is occurring above the function "function ENT:Use( activator, caller )" at "local UpgradeCost = 5000 * self.PrinterLevel" (Line 100)
That's because you are calling self and self is refering to entity. If you are using it outside the function, it doesn't really know what self is. Call it inside ENT:Initialize() function.
[QUOTE=Netheous;40312409]That's because you are calling self and self is refering to entity. If you are using it outside the function, it doesn't really know what self is. Call it inside ENT:Initialize() function.[/QUOTE] Man I just figured that DOOIII! Thanks for your reply man I really appreciate it anyways.
Sorry, you need to Log In to post a reply to this thread.