How can I have access to the SWEP structure members in a Weapon object?

It’s possible to have access to a Weapon in game by performing a hull trace and with its object (tr.Entity) I can check if it’s a Weapon and a SWEP, with the Entity:IsWeapon() and Weapon:IsScripted() method. So let’s suppose I have a Weapon object that is a SWEP how can I have access to the SWEP structure members through it?


When you’re creating a SWEP you add the values and functions to a SWEP structure (linked above) for example:

SWEP.Primary.Spread = 0.1
SWEP.Primary.NumberofShots = 1
SWEP.Primary.Automatic = false
SWEP.Primary.Recoil = 10
SWEP.Primary.Delay = 3
SWEP.Primary.Force = 1000

I’d like to have access to the values above through an Weapon object. For example, how can I access the SWEP.Primary.Spread through the object? I tried ent.Primary.Spread, but I had no success.

Well first off you should probably be using Entity:IsWeapon() to check if it’s a weapon, then if you really need to know if the weapon is scripted you can use IsScripted.
And you can access any part of an object’s members by just refrencing them like myEntity.Owner
I assume that’s what you’re asking because you’re not very clear. If I know what you’re trying to accomplish it’s easier to help.

I edited the question and tried to clarify it with an example.

ent.Primary.Spread should work perfectly fine as long as the entity has those values. It seems to me that your problem lies somewhere else.
You can also just try doing this with your entity to see your results:
print(ent, ent.Primary, ent.Primary and ent.Primary.Spread or nil)

Looks like it worked, I have access to the ent.Primary table that is equivalent to SWEP.Primary, thanks man, I think I wrote something wrong, because I tried that before (a bit differently) and an error occured.

Sorry for this stupid post.