I need help with a table value being recognised by Ent:StartTouch.

So I am making a weapons storage chest however just as I am about to start I come across an issue.

My issue is that the function ENT:StartTouch(entity) defines the M9K weapons I am testing with as just “spawned_weapon”.

Is there anyway I can get it to recognize the entity name of the weapon? here is my code.

init.lua[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include(‘shared.lua’)

function ENT:Initialize()

self:SetModel("models/props/CS_militia/footlocker01_closed.mdl") 
self:PhysicsInit(SOLID_VPHYSICS)
self:SetSolid(SOLID_BBOX)
self:SetUseType(SIMPLE_USE) 
self:DropToFloor()

end

function ENT:AcceptInput(activator,caller)
if IsValid( caller ) and caller:IsPlayer() then
–networkingforlater…
end
end

function ENT:StartTouch(entity)
print(entity:GetClass()) – it just prints “spawned_weapon”
if table.HasValue(GunChestItems, “spawnedweapon”) then
entity:Remove()
end
end
[/lua]

cl_init[lua]
include(‘shared.lua’)

function ENT:Draw()

self:DrawModel()

end
[/lua]

shared.lua[lua]
ENT.Base = “base_gmodentity”
ENT.Type = “anim”
ENT.Spawnable = true
ENT.PrintName = “Gun Chest”
ENT.Purpose = “A chest to store weaponry.”
ENT.Category = “Berkark”

function ENT:SetupDataTables()

--for later

end

GunChestItems = {}

GunChestItems[“Raging Bull”] = {
Ent = “m9k_ragingbull”,
Mdl = “models/weapons/w_taurus_raging_bull.mdl”,
}

GunChestItems[“Colt Python”] = {
Ent = “m9k_coltpython”,
Mdl = “models/weapons/w_colt_python.mdl”,
}
[/lua]

It does what its supposed to do.

It’s an entity in DarkRP.

Look at its source code to figure out how to extract the real SWEP class.

Thanks, from that I have sorted it out :smiley:

Usually helps to print out the whole table of the entity. Works with all entites.
That way you can see the whole table path.

Ex. table.subtablepart = whatever

Which I guess for what you are doing I would do a for k,v and just print the value. Then work from that.

Did this when I was messing around with the pockets. It was like v.DV.class which had the value of the weapon name.

TLDR; Print out the whole table to find the path of what you want from that entity.