Making a Custom Entity

UPDATE START

I changed
ent.Create(“i_item”) to ent.Create(“prop_physics”)

and it spawned the item but i still need to move it to a custom entity

UPDATE END

sv_init.lua



print()
print()
print("###########################################")
print("###########################################")
print("###########################################")
print()
print("Inventory Initialized")
print()
print("###########################################")
print("###########################################")
print("###########################################")
print()
print()

include("sh_items.lua")
AddCSLuaFile("sh_items.lua")

include("sh_shared.lua")
AddCSLuaFile("sh_shared.lua")

local meta = FindMetaTable("Player")

function meta:SpawnItem( item )
	if(Inventory.Items.Stored[item])then
		local tr = self:EyeTrace(100)
    local entItem = ents.Create("i_item")
		if(!entItem:IsValid()) then
			print("[Inventory Error] - [meta:SpawnItem(item)] - Unknown Entity")
			print("Possibly ent.Create('i_item')?")
			return
		end
    entItem:SetPos(tr.HitPos)
    entItem.uid = item
    entItem:Spawn()
	else
		print("No item registered as: "..item)
	end
end

-- test func should be removed before open beta
concommand.Add("svitems",function(ply, cmd, args)
	if(game.SinglePlayer() or table.HasValue(Inventory.CanSpawn,ply:SteamID())) then
		for item, _ in pairs( Inventory.Items.Stored ) do
            ply:PrintMessage(2, item)
    end
	else
		ply:PrintMessage("You do have have the privileges to access this command!")
	end
end)



sh_items.lua



print()
print()
print("###########################################")
print("###########################################")
print("###########################################")
print()
print("Inventory Items Initialized")
print()
print("###########################################")
print("###########################################")
print("###########################################")
print()
print()

Inventory.Items = {}
Inventory.Items.Stored = {"Filler"}

if(Inventory.Items == nil)then Inventory.Items = {} end

function Inventory.Items:Register(uid, table)

	if (not self.Stored[uid]) then self.Stored[uid] = {} end
	print(self.Stored[1])

	self.Stored[uid].Name = table.Name or ""
	self.Stored[uid].Info = table.Info or ""
	self.Stored[uid].Model = table.Model or ""
	self.Stored[uid].CanUse = table.CanUse or 1
	self.Stored[uid].CanDrop = table.CanDrop or 1
	self.Stored[uid].Weight = table.Weight or 1
	self.Stored[uid].Limit = table.Limit or 200
	self.Stored[uid].Dist = table.Dist or 1.2
	self.Stored[uid].ID = table.ID or 0

	if SERVER then
		print("[Inventory] - Registered item: "..table.Name.." ID: "..table.ID)
	end

end

function Inventory.Items:Get(item)
	if(self.Stored[item] != nil) then
		print("I have that item!")
		return self.Stored[item]
	end
end

local fol = "NocturnalInventory/libraries/core/items/"
local files, folders = file.Find(fol.."*","LUA")
print("[Inventory] Items: ",files,#files)
print("[Inventory] Folders: ",folders,#folders)
print("[Inventory] Path: ",fol)
for k, v in pairs( files ) do

	include(fol .. v)
	print("FILE ",v)


	if (SERVER) then

		AddCSLuaFile(fol .. v)

	end

end

if(SERVER)then
	concommand.Add("item_use",function(ply, cmd, args)

		local item = args[1]

		if(table.HasValue(Inventory.Items.Stored, item)) then
			ply:ChatPrint("You used item "..item)
		end
	end)
end

concommand.Add("item_spawn", function(ply, cmd, args)
	if(game.SinglePlayer() or table.HasValue(Inventory.CanSpawn, ply:SteamID())) then
		if(args[1] != nil) then
			ply:SpawnItem(args[1])
		else
			print("item_spawn <item name>")
		end
	else
		print("You dont have access to this command!, if this is a mistake talk to the owner.")
	end
end)



concommand.Add("items",function(ply, cmd, args)
	if(table.HasValue(Inventory.CanSpawn,ply:SteamID())) then
		for item, _ in pairs( Inventory.Items.Stored ) do
            ply:PrintMessage(2, item)
        end
    else
    	ply:PrintMessage("You do have have the privileges to access this command!")
	end
end)



sh_shared.lua



Inventory = {}
Inventory.Config = {}
Inventory.CanSpawn = {
	"STEAM_0:1:24445839", -- ProfessorSpace
	"STEAM_0:1:24971849", -- Scriptis Account#1
	"STEAM_0:0:68616382",  -- Scriptis Account#2
	"STEAM_0:1:12438880"
}

Inventory.Config["Bind Key_I"] = true -- Not being used yet


local meta = FindMetaTable( "Player" )



function meta:EyeTrace( dis )

	local tr = {}

	tr.start = self:GetShootPos()

	tr.endpos = tr.start + (self:GetAimVector() * dis)

	tr.filter = self

	tr = util.TraceLine(tr)

	return tr

end



function ItemExists( item )

    local itbool = false

	if (table.HasValue(Inventory.Items, item)) then

	    itbool = true

	end

	return itbool

end;



function meta:InventorySize()

    local size=20

	for k, v in pairs(self.i_Inventory)do

		local item = Inventory.Items:GetItem(k)



		if(item.Weight<0)then

			size = size - (math.Clamp(v,0,item.max)*item.Weight)

		end

	end

	return size

end



function meta:InventoryWeight()

    local num = 0

	for k, v in pairs(self.i_Inventory) do

		num = num + math.Clamp(Inventory.Items:GetItem(k).Weight*v,0,90000)

	end

	return num

end



I got lazy so cl_init, shared and init of i_item is below



-- CL_INIT START
include( "shared.lua" )



function ENT:Draw()

	self.Entity:DrawModel()

end
-- CL_INIT END

--INIT START
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")

function ENT:Initialize()
        self.table = Inventory.Items:Get(self.uid)

        self:SetModel(self.table.Model)
        self:PhysicsInit(SOLID_VPHYSICS)
        self:SetMoveType( MOVETYPE_VPHYSICS)
        self:SetSolid(SOLID_VPHYSICS)
        self:SetUseType(SIMPLE_USE)


        local pObject = self:GetPhysicsObject()
		pObject:Wake()


        self:SetNetworkedString("i_Name", self.table.Name)
end

function ENT:Use( activator, caller )
        if (!activator:IsPlayer()) then return false; end

        
        activator:EmitSound("items/ammocrate_open.wav")
        self:Remove()
        activator:ChatPrint("Picked up " .. self.table.Name .. ".")
end
-- INIT END

--SHARED START
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.Author = "ProfessorSpace"
ENT.Spawnable = false
-SHARED END


the entities folder has to be inside the Lua folder.

[editline]29th September 2015[/editline]

like addons/youraddon/lua/entities/i_item

:open_mouth: thanks its fixed :smiley: