"Un-strip" weapons

Excuse me for any grammatical errors.

I am editing a weapon that when you shoot someone, you strip all his weapons, I would like to make after some seconds he receive all his stripped weapons.

I make something like this (This is only an example, I writed it here, so excuse me if there is some errors):

Weapons = {}

function SWEP:PrimaryAttack(ply)
--The function
table.insert(Weapons, ply:GetWeapons())

function anotherfunction(ply)
ply:Give( Weapons ) --I think the problem is here, because I can't put a table here, but I don't know another method to do it

Can someone help me?
Thank you!

Store all the players weapons in a table when they are stripped. And run a loop for each weapon in the table and give it back when you want to.

First things first, you need to make it so that the weapons table is local, and has a copy for every time you strip (or else 2 people using the weapon will overwrite the stripped table, and both players will get back the 2nd person’s weapons!)

function SWEP:PrimaryAttack(shooter)
    local ply = shooter:GetEyeTrace().Entity --Find the entity the shooter shot at
    if not ply:IsPlayer() then return end --Don't do anything if we didn't shoot a player
    local weps = ply:GetWeapons() --weps holds the player's weapons
    timer.Simple(20,function() --after 20 seconds
        for _,v in pairs(weps) do
            ply:Give(v) --Give the player each weapon in the table weps

*code is untested

Thank you, I’m editing the code!

[editline]22nd August 2016[/editline]

But there is a problem, because I have to give the weapon in another function, but I made weps locally, how can I fix this problem?

I actually recommend an entirely different approach. Make another SWEP that’s literally no weapon at all, so when that weapon is equipped, it would look and feel just like the player has no weapons. When you want to strip the player, don’t actually take away their weapons - instead, give them the new SWEP and force them to switch to it with


When you want to give them all their weapons back, simply take away that useless SWEP and switch them back to the old one.

Hook into

GM:PlayerSwitchWeapon and return true if the old weapon is the useless one - this prevents players from switching away while they’re supposed to be stripped.

Also hook into

GM:PlayerBindPress and prevent the binds that relate to switching weapons if the player’s active weapon is the useless one. This will stop the UI from showing their weapons.

By doing it this way, players will keep the exact same weapons and ammo that they had before.

Edit: if anyone knows of a way to make a player appear and feel stripped without actually stripping them and without a dummy weapon, that may be a better option.