Help with ttt swep

I’m building this swep as proof of concept that I can create a swep that removes itself and gives another swep as a replacement replacement. The final product will do this randomly but for now I just want one that works. This one just seems to vanish and give nothing in return. It works fine when the weapon goes into another slot




if SERVER then
   AddCSLuaFile( "shared.lua" )
end

SWEP.HoldType = "pistol"


if CLIENT then
   SWEP.PrintName = "Test gun"
   SWEP.Slot = 1

   SWEP.Icon = "VGUI/ttt/icon_glock"
end

SWEP.Kind = WEAPON_PISTOL
SWEP.WeaponID = AMMO_GLOCK

SWEP.Base = "weapon_tttbase"
SWEP.Primary.Recoil	= 0.9
SWEP.Primary.Damage = 12
SWEP.Primary.Delay = 0.10
SWEP.Primary.Cone = 0.028
SWEP.Primary.ClipSize = 20
SWEP.Primary.Automatic = true
SWEP.Primary.DefaultClip = 20
SWEP.Primary.ClipMax = 60
SWEP.Primary.Ammo = "Pistol"
SWEP.AutoSpawnable = true
SWEP.AmmoEnt = "item_ammo_pistol_ttt"

SWEP.UseHands			= true
SWEP.ViewModelFlip		= false
SWEP.ViewModelFOV		= 54
SWEP.ViewModel  = "models/weapons/cstrike/c_pist_glock18.mdl"
SWEP.WorldModel = "models/weapons/w_pist_glock18.mdl"

SWEP.Primary.Sound = Sound( "Weapon_Glock.Single" )
SWEP.IronSightsPos = Vector( -5.79, -3.9982, 2.8289 )

SWEP.HeadshotMultiplier = 1.75

function SWEP:Equip()
--	self.Owner:StripWeapon('1test_gun')         
	timer.Simple( 3, function() 
        	self:Remove()
		self.Owner:Give('weapon_zm_pistol')

	end)

end



Put self:Remove() before the timer.

Now it just deletes as soon as I pick it up, no weapon given.

Oops. That’s because every time you equip a new weapon, it instantly removes it, as it will call SWEP:Equip every time you get a new weapon. Afaik, there’s not a way to remove a weapon and give the same weapon back automatically – would be easier if it were a different weapon. A solution to this would be to either have a separate script that handles the removal and giving of the SWEP, or have a concommand that removes and gives a new copy of the weapon.

It’s not the same weapon though. I’m taking a “test_gun” and giving a “weapon_zm_pistol”

Instead of self:Remove(), use self.Owner:StripWeapon(“weapon_test_gun”) --or whatever it’s called

No, put it AFTER

you have to create the damn timer first before you kill the SWEP

[editline]16th March 2014[/editline]

StripWeapon is the correct method, however

Yeah, I wasn’t thinking there.

After the timer and with strip weapon and still no gun.

Post your updated code.



if SERVER then
   AddCSLuaFile( "shared.lua" )
end

SWEP.HoldType = "pistol"


if CLIENT then
   SWEP.PrintName = "Test gun"
   SWEP.Slot = 1

   SWEP.Icon = "VGUI/ttt/icon_glock"
end

SWEP.Kind = WEAPON_PISTOL
SWEP.WeaponID = AMMO_GLOCK

SWEP.Base = "weapon_tttbase"
SWEP.Primary.Recoil	= 0.9
SWEP.Primary.Damage = 12
SWEP.Primary.Delay = 0.10
SWEP.Primary.Cone = 0.028
SWEP.Primary.ClipSize = 20
SWEP.Primary.Automatic = true
SWEP.Primary.DefaultClip = 20
SWEP.Primary.ClipMax = 60
SWEP.Primary.Ammo = "Pistol"
SWEP.AutoSpawnable = true
SWEP.AmmoEnt = "item_ammo_pistol_ttt"

SWEP.UseHands			= true
SWEP.ViewModelFlip		= false
SWEP.ViewModelFOV		= 54
SWEP.ViewModel  = "models/weapons/cstrike/c_pist_glock18.mdl"
SWEP.WorldModel = "models/weapons/w_pist_glock18.mdl"

SWEP.Primary.Sound = Sound( "Weapon_Glock.Single" )
SWEP.IronSightsPos = Vector( -5.79, -3.9982, 2.8289 )

SWEP.HeadshotMultiplier = 1.75

function SWEP:Equip()
--	self.Owner:StripWeapon('1test_gun')         
	timer.Simple( 3, function() 
--		self:Remove()
		timer.Simple( 1, function() 

			self.Owner:Give('weapon_zm_pistol')
		end)
		self.Owner:StripWeapon("1test_gun")
	end)

end


You put a useless timer inside of a timer… Change it to this


function SWEP:Equip()       
	timer.Simple( 1, function() 
        self.Owner:Give('weapon_zm_pistol')
	end)
    self.Owner:StripWeapon("1test_gun")
end

Same effect only instant, the 3 second timer keeps the gun around before it switches so I can verify that I picked it up.

Yes, this can be done. Here is an example of what I did earlier:



function SWEP:Equip()
 if SERVER then

  if self.Owner:PS_HasItemEquipped("katana") then
   self.Owner:Give("weapon_ttt_katana")
   self:Remove()
  end

  if self.Owner:HasWeapon("weapon_ttt_katana") then
   self:Remove()
  end

 end
end


Sounds to me like your test weapon is broken :v

Well, you’re running it on server, maybe I should try that. Was there a reason you decided to do that?

You can’t remove weapons from the client iirc.