Need a good way to do unique weapon data

I have an item system in a gamemode I’m working on. I want to pass variables from the weapon item’s (variables like Clip, ClipMax, ExtraRounds, Damage, Spread, etc) table -into- the actual weapon in the player’s hands. Each item is a table with a bunch of variables defining it ‘customization’. Each instance of an item can contain special info (so a player could have a weapon with a ClipMax (magazine size) of 30 bullets, but another player might have a weapon with 23 max bullets [for example]).

If a player equips a weapon item, I want these variables to transfer into the weapon in their hand.
I tried editing the item base to inherit data from this table but it just didn’t work out so well…

Any suggestions? I can provide more info if need be.

Use **[Player.GetActiveWeapon

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.GetActiveWeapon)** to get the entity of the weapon the players holding, and then change those variables in its table directly, which will over-ride the original ones.

For example;

[lua]
hook.Add( “WeaponEquip”, “AdminFTW”, function( wep )

timer.Simple( 0.1, function() -- when this hook is called the weapons owner isn't valid yet

    if not ValidEntity( wep:GetOwner() ) then return end

    if wep:GetOwner():IsAdmin() then

        wep.Primary.ClipSize = 100 -- admins get 100 shots per clip

    end

end )

end )
[/lua]

Depending on how you have things set up, you might be able to use **[Table.Merge

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Table.Merge)** or **[Table.Add

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Table.Add)** to actually copy values from your customization table into the weapon table.

I had something like that going last night - I will try something like that out and post the sourcecode once I’m done :slight_smile: