First I know I spelled table wrong in the title, sorry.
Hello. I’m trying to make a box to store things in. I got the basic functions working, I just need a way to remove the table after it have been used.
My init.lua (Where the action happens)
[lua]
AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)
include(“shared.lua”)
function ENT:Initialize()
self.Entity:SetModel(“models/props_junk/cardboard_box003a.mdl”)
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
self.CanUse = true
self.Entity.BoxFull = false
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 ent = ents.Create(“ent_box”)
ent:SetPos( tr.HitPos + tr.HitNormal * 16 )
ent:Spawn()
ent:Activate()
return ent
end
StoreBox = { }
function AddItem( entity )
table.insert( StoreBox, { Entity = entity } )
end
function ENT:Touch(ent)
if ent:IsValid() and !ent:IsPlayer() then
if self.Entity.BoxFull == false then
AddItem( ent:GetClass() )
self.Entity.BoxFull = true
ent:Remove()
else
return
end
end
end
function ENT:Use(activator, caller)
if self.Entity.BoxFull == true then
for k, v in pairs( StoreBox ) do
local controller = ents.Create(v.Entity)
controller:SetPos(self.Entity:GetPos() + Vector(0, 0, 3))
controller:Spawn()
controller:Activate()
table.remove( StoreBox, v.Entity )
end
end
self.Entity.BoxFull = false
end
function ENT:OnRemove()
return false
end
[/lua]
The problem is: table.remove( StoreBox, v.Entity )
The error I get:
entities/ent_box/init.lua:53: bad argument #2 to ‘remove’ (number expected, got string)
What I get from that and the wiki is that I need to use like table.remove( StoreBox, 1 ) to remove the first item that got added, but I want in a later version so it can hold more then one item and then I don’t know how to remove it.
So what I need help to is: How to make it so it can have lets say 10 items inside but it will only remove the ent that get spawned? (I’m going to make a derma menu so I can control what ent gets spawned)
Thanks for you time/help
Ps: Sorry if my English sucked