ENT:Draw() "ENT" is a nil value?

I’m fairly new to Lua, but when I looked at both old and new wikis, it states that there is a “draw” hook that is called to draw entities. When I tried to use it in cl_init.lua I got:


[ERROR] gamemodes/test/gamemode/cl_init.lua:8: attempt to index global 'ENT' (a nil value)
 

My full code in cl_init.lua:


include("shared.lua")
include("database/cl_database.lua")

function GM:DrawDeathNotice(x, y)
	return
end

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

Help would be appreciated :smile:

It’s a draw hook that’s meant to be inside the SENT file itself, not in your gamemode file.

Thanks, I’m really new to Lua and wasn’t sure why the hook wasn’t working. I appreciate your help.

Here bud this should get you going, this code spawns a black colored box and it kills you when you step on it.

save it as: shared.lua



ENT.Base = "base_hns_blocks"
ENT.PrintName = "Death"
ENT.Color =  Color( 0, 0, 0, 255)

if (SERVER) then

AddCSLuaFile( "shared.lua" )

	function ENT:Initialize()
		self.Entity:SetModel("models/hunter/blocks/cube1x1x025.mdl")
		self.Entity:SetSkin(0)
		self.Entity:SetSolid(SOLID_VPHYSICS)
		local phys = self.Entity:GetPhysicsObject()
		if phys and phys:IsValid() then phys:Wake() end
	end

	function ENT:StartTouch( ent )
		if ( IsValid(ent) and ent:IsPlayer() ) then
			ent:Kill()
		end
	end
 
end


Sorry I completely forgot that I made a base for my ents. Here is the base:



ENT.Type = "anim"
ENT.PrintName = "blocktype"
ENT.Author = "Swifty"
ENT.Information = [[Put shit here]]
ENT.Spawnable = false
ENT.AdminSpawnable = true
ENT.Category = "hns_blocks"
ENT.Color =  Color( 255, 0, 0, 255)
ENT.RenderGroup = RENDERGROUP_BOTH

if (SERVER) then

AddCSLuaFile( "shared.lua" )

	function ENT:Initialize()
		self.Entity:SetModel("models/hunter/blocks/cube1x1x025.mdl")
		self.Entity:SetSkin(0)
		self.Entity:SetSolid(SOLID_VPHYSICS)
		local phys = self.Entity:GetPhysicsObject()
		if phys and phys:IsValid() then phys:Wake() end

	end

	function ENT:SpawnFunction( ply, tr ) 
	   
		if ( !tr.Hit ) then return end 
		 
		local SpawnPos = tr.HitPos + tr.HitNormal * 16 
		 
		local ent = ents.Create( self.Classname ) 
		ent:SetPos( SpawnPos ) 
		ent:Spawn() 
		ent:Activate() 

		return ent 
		 
	 end 
 
end

if ( CLIENT ) then

	function ENT:Initialize()
		self:SetRenderMode( RENDERMODE_TRANSALPHA )
		self:SetColor(self.Color)
	end
	
	function ENT:Draw()
		self.Entity:DrawModel()
	end

	function ENT:OnRemove()
	end

	function ENT:Think()
	end 


end