Getowning_ent error.


function ENT:Think()
    local owner = self:Getowning_ent()
    self.owner = (IsValid(owner) and owner:Nick()) or DarkRP.getPhrase("unknown")
end

net.Receive("gui",function()


printer = net.ReadEntity()

 local Frame = vgui.Create( "DFrame" )
Frame:SetSize( 300, 500 )
Frame:Center()
Frame:SetTitle( "" )
Frame:SetVisible( true )
Frame:SetDraggable( true )
Frame:MakePopup()
Frame:ShowCloseButton( true )
Frame.Paint = function (s , w , h)
   
    draw.RoundedBox(0,0,0,w,h,Color(51,51,51))
 
end

local Avatar = vgui.Create( "AvatarImage", Frame )
Avatar:SetSize( 40, 40 )
Avatar:SetPos( 20, 345 )
Avatar:SetPlayer( printer:Getowning_ent(), 64 )

end)


The ERROR :

attempt to call method ‘Getowning_ent’ (a nil value)

What would be the problem here?

In shared.lua i’ve got this


function ENT:SetupDataTables()
	self:NetworkVar("Bool", 1, "Stone")
	self:NetworkVar("Bool", 2, "Muter");
	self:NetworkVar("Bool", 3, "HP");
	self:NetworkVar("Int", 2, "StoneTime");
	self:NetworkVar("Int", 3, "MuterTime");
	self:NetworkVar("Int", 4, "Money");
	self:NetworkVar("Int", 0, "price");
	self:NetworkVar("Entity", 3, "owning_ent")
	self:NetworkVar("Int", 1, "PrinterHealth");
	self:NetworkVar("String", 0, "PrinterName");
	self:NetworkVar("Bool", 0, "CoolerTouching");
end

Any help would be amazing!

Thank you

[editline]23rd August 2017[/editline]

in the shared.lua i’ve tried also setting the self:NetworkVar(“Entity”, 3, “owning_ent”) to self:NetworkVar(“Entity”, 0, “owning_ent”) yet nothing

Put a print in SetupDataTables to make sure it’s running.

Where would i put the print? any chance you could show me?

In SetupDataTables.

yes, but where in there. Like this?



function ENT:SetupDataTables()
	print()
         self:NetworkVar("Bool", 1, "Stone")
	self:NetworkVar("Bool", 2, "Muter");
	self:NetworkVar("Bool", 3, "HP");
	self:NetworkVar("Int", 2, "StoneTime");
	self:NetworkVar("Int", 3, "MuterTime");
	self:NetworkVar("Int", 4, "Money");
	self:NetworkVar("Int", 0, "price");
	self:NetworkVar("Entity", 3, "owning_ent")
	self:NetworkVar("Int", 1, "PrinterHealth");
	self:NetworkVar("String", 0, "PrinterName");
	self:NetworkVar("Bool", 0, "CoolerTouching");

end


Sure, but you have to put a string inside to print.

so basically this?



function ENT:SetupDataTables()
	print("i could put something in here to tell me that its printing.")
         self:NetworkVar("Bool", 1, "Stone")
	self:NetworkVar("Bool", 2, "Muter");
	self:NetworkVar("Bool", 3, "HP");
	self:NetworkVar("Int", 2, "StoneTime");
	self:NetworkVar("Int", 3, "MuterTime");
	self:NetworkVar("Int", 4, "Money");
	self:NetworkVar("Int", 0, "price");
	self:NetworkVar("Entity", 3, "owning_ent")
	self:NetworkVar("Int", 1, "PrinterHealth");
	self:NetworkVar("String", 0, "PrinterName");
	self:NetworkVar("Bool", 0, "CoolerTouching");

end


[editline]23rd August 2017[/editline]

running, not printing lel

[editline]23rd August 2017[/editline]

Yeah, it’s running it. What could be the error?

So is it printing or not?

cl_init.lua



include("shared.lua")

function ENT:Initialize()
end

function ENT:Draw()
	self:DrawModel()
end

surface.CreateFont( "printer_font1", {
	font = "Trebuchet24", 
	size = 16,
	weight = 640,
	blursize = 0,
	scanlines = 10,
	antialias = true,
	shadow = false,
} )

surface.CreateFont( "printer_font2", {
	font = "Trebuchet24", 
	size = 8,
	weight = 640,
	blursize = 0,
	scanlines = 10,
	antialias = true,
	shadow = false,
} )

function ENT:Think()
    local owner = self:Getowning_ent()
    self.owner = (IsValid(owner) and owner:Nick()) or DarkRP.getPhrase("unknown")
end

net.Receive("gui",function()


printer = net.ReadEntity()

 local Frame = vgui.Create( "DFrame" )
Frame:SetSize( 300, 500 )
Frame:Center()
Frame:SetTitle( "" )
Frame:SetVisible( true )
Frame:SetDraggable( true )
Frame:MakePopup()
Frame:ShowCloseButton( true )
Frame.Paint = function (s , w , h)
   
    draw.RoundedBox(0,0,0,w,h,Color(51,51,51))
 
end

local Avatar = vgui.Create( "AvatarImage", Frame )
Avatar:SetSize( 40, 40 )
Avatar:SetPos( 20, 345 )
Avatar:SetPlayer( printer:Getowning_ent(), 64 )

end)


Can you post your shared and init?

the init is really long but sure.

Also, make printer a local variable, and do a class verification before calling the function. You should probably also use a more unique name than “gui”

init.lua




AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
 
function ENT:Initialize()
 
    self:SetModel( self.printerModel );
   
    self:PhysicsInit(SOLID_VPHYSICS);
    self:SetMoveType(MOVETYPE_VPHYSICS);
    self:SetSolid(SOLID_VPHYSICS);
    self:GetPhysicsObject():Wake();
   
    self.sparking = false; 
    self:SetPrinterHealth ( self.startingHP );
    self:SetPrinterName( self.printerName );
   
    self:SetMaterial( self.PrinterMaterial )
    self:SetColor( self.PrinterColor );
   
    self:SetUseType( SIMPLE_USE );
   
    self.IsMoneyPrinter = true;
   
    self.sound = CreateSound( self, Sound( self.soundFile ) );
    self.sound:SetSoundLevel( self.soundLevel );
    self.sound:PlayEx(1, 100); 
   
    self.BeenTouchedBy = {};
   
    self:SetStone( false );
	self:SetMuter( false );

    self:Print();
    self:HealthReduction();
    self:UpgradeTimers();
   
end
 
function ENT:UpgradeTimers()
 
 
    if ( !timer.Exists("batteryUpgrade"..self:EntIndex()) ) then
   
        timer.Create("batteryUpgrade"..self:EntIndex(), 1, 0, function()
       
            if ( self:GetStoneTime() >= 1 ) then
       
                self:SetStoneTime( self:GetStoneTime() - 1 );
       
            else
       
                self:SetStone(false);
           
            end
       
        end)
   
    end
   
    if ( !timer.Exists("silencerUpgrade"..self:EntIndex()) ) then
   
        timer.Create("silencerUpgrade"..self:EntIndex(), 1, 0, function()
       
            if ( self:GetMuterTime() >= 1 ) then
       
                self:SetMuterTime( self:GetMuterTime() - 1 );
       
            else
       
                self:SetMuter(false);
               
                self.sound:Play();
           
            end
       
        end)
   
    end
   
   
end

function ENT:OnTakeDamage( dmg )
 
    if ( self.burningup ) then return; end
 
    self:SetPrinterHealth( ( self:GetPrinterHealth() or 100 ) - dmg:GetDamage() );
   
        if ( self:GetPrinterHealth() <= 30 ) then
       
            self:SetColor( self.PrinterLowHealthColor );
           
        end
       
        if ( self:GetPrinterHealth() <= 0 ) then
           
            local RNG = self.printerExplodeRNG;
           
            if ( RNG == self.printerExplodeRNGEquals ) 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)
    DarkRP.notify(self:Getowning_ent(), 1, 4, DarkRP.getPhrase("money_printer_exploded"))
   
end
 

 
function ENT:Print()
 
    if ( !timer.Exists("timePrinting"..self:EntIndex()) ) then
   
        timer.Create("timePrinting"..self:EntIndex(), self.printTime, 0, function()
       
			if ( !self:GetStone() ) then
			
            self:SetMoney( self:GetMoney() + self.printMoney );
			
			elseif ( self:GetStone() ) then
			
			self:SetMoney( self:GetMoney() + self.printMoneyBoosted );
			
			end
       
        end)
       
    end
 
end

function ENT:BurstIntoFlames()
 
    DarkRP.notify(self:Getowning_ent(), 0, 4, DarkRP.getPhrase("money_printer_overheating"));
    self.burningup = true
    local timeburn = math.random(8, 18)
    self:Ignite(timebrun, 0);
    timer.Simple(timeburn, function() self:Fireball() end)
   
end
 
function ENT:HealthReduction()
 
    self.rngAttempts = 0;
   
    if ( !timer.Exists("healthLossTime"..self:EntIndex()) ) then
   
        timer.Create("healthLossTime"..self:EntIndex(), 1, 0, function()
       
            local rng = self.printerExplodeRNG;
           
            if ( rng == self.printerExplodeRNGEqual ) then
           
                if ( !self:GetStone() ) then
               
                self.rngAttempts = 0;
                self:SetPrinterHealth( self:GetPrinterHealth() - math.random(1,3) );
               
                end
           
            else
           
                if ( !self:GetStone() ) then

                self.rngAttempts = self.rngAttempts + 1;
               
                end
               
            end
               
       
        end)
       
    end
 
end

function ENT:Fireball() -- This is just a standard function for the explosion to take place
    if not self:IsOnFire() then self.burningup = false return end
   
    local dist = math.random(20, 280) -- This is the explosion radius, don't make this any more higher than it is.
    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
 
function ENT:Touch( ent )
 
    if ( !self.BeenTouchedBy[ent] ) then
   
        timer.Simple(0.01, function()
       
            if ( ent:IsPlayer() ) then return; end
       
				if ( ent:GetClass() == "tomz_production" ) then
				
					if ( !self:GetStone() ) then
								
						self:SetStone(true);
						self:SetStoneTime(self.stoneTime);
						ent:Remove();
					
					else
					
						ent:SetText("Already Being Used");
						
						timer.Simple(3.5, function()
						
							if ( IsValid(ent) ) then
							
							ent:SetText("Cash Upgrade");
							
							end
							
						end)
						
					end
					
				end	
			
				if ( ent:GetClass() == "tomz_silencer" ) then
				
					if ( !self:GetMuter() ) then
					
						self:SetMuter(true);
						self:SetMuterTime(self.muterTime);
						ent:Remove();
						
						self.sound:Stop();
						
					else
					
						ent:SetText("Already inserted");
						
						timer.Simple(3.5, function()
						
							if ( IsValid(ent) ) then
							
							ent:SetText("Silencer Upgrade");
							
							end
							
						end)
						
					end
					
				end
				
		
				if ( ent:GetClass() == "tomz_battery" ) then
					self:SetHP(true);
					self:SetPrinterHealth( self:GetPrinterHealth() + self.addHealth );
					ent:Remove();
				end			
           
            self.BeenTouchedBy[ent] = true;
       
            timer.Simple(2, function()
           
                self.BeenTouchedBy[ent] = false;
               
            end)
 
        end)
       
    end
 
end
 
util.AddNetworkString("gui")
util.AddNetworkString("take")
util.AddNetworkString("bat")
util.AddNetworkString("cash")
util.AddNetworkString("mute")

function ENT:Use( ply )

net.Start("gui")
net.Send(ply)



net.Receive("take",function()

	if ( self:GetMoney() > 0 && ply:IsPlayer() ) then
	money = self:GetMoney();
	ply:addMoney(self:GetMoney());
	self:SetMoney(0);
	DarkRP.notify( ply, 1, 5, "You just took $"..money..  " from your printer." );
	end
end)

net.Receive("bat",function(len, ply)
	local battery = ents.Create("tomz_battery")
	battery:SetModel("models/freeman/printerupgrades_battery.mdl")
	battery:SetPos( ply:GetEyeTrace().HitPos )
	battery:Spawn()
end)

net.Receive("cash",function(len, ply)
	local cash = ents.Create("tomz_production")
	cash:SetModel("models/freeman/printerupgrades_money.mdl")
	cash:SetPos( ply:GetEyeTrace().HitPos )
	cash:Spawn()
end)

net.Receive("mute",function(len, ply)
	local mute = ents.Create("tomz_silencer")
	mute:SetModel("models/freeman/printerupgrades_mute.mdl")
	mute:SetPos( ply:GetEyeTrace().HitPos )
	mute:Spawn()
end)
	

end
 
function ENT:Think()
   
	if self:WaterLevel() > 0 then
		self:Destruct()
		self:Remove()
		return
	end
	self:StartSound()
	if not self.sparking then return end


    if ( self:GetPrinterHealth() <= 0 ) then
       
        self:Fireball();
   
    end
   
end
 
function ENT:OnRemove()
 
    if self.sound then
        self.sound:Stop()
    end
   
    timer.Remove("batteryUpgrade"..self:EntIndex() );
    timer.Remove("silencerUpgrade"..self:EntIndex() );
    timer.Remove( "timePrinting"..self:EntIndex() );
    timer.Remove( "healthLossTime"..self:EntIndex() );
   
end



shared.lua




ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Money Printers"
ENT.Author = "Tomz"
ENT.Spawnable = false
ENT.AdminSpawnable = false

function ENT:SetupDataTables()
	self:NetworkVar("Bool", 1, "Stone")
	self:NetworkVar("Bool", 2, "Muter");
	self:NetworkVar("Bool", 3, "HP");
	self:NetworkVar("Int", 2, "StoneTime");
	self:NetworkVar("Int", 3, "MuterTime");
	self:NetworkVar("Int", 4, "Money");
	self:NetworkVar("Int", 0, "price");
	self:NetworkVar("Entity", 3, "owning_ent")
	self:NetworkVar("Int", 1, "PrinterHealth");
	self:NetworkVar("String", 0, "PrinterName");
	self:NetworkVar("Bool", 0, "CoolerTouching");
end



You aren’t writing an entity when you network send to “gui”

oh. is that the issue?

[editline]23rd August 2017[/editline]

Also could you please give an example of writing the entity.

net.WriteEntity(what goes inside?) and if that is the correct net?

net.WriteEntity(self)

thank you! Ill contact you if its not working.