Weapon constant variable.

I want to make a weapon that counts the number of times it has been clicked.

So what I did was that I made some variables like



function SWEP:SetupDataTables()
      self:NetworkVar("Float",0,"Clicked")
end


so I gave it to my m8 and the counter reset…

Is there any way to fix this, like a variable that is constant even though the wep gets dropped…

Where do you update it?
Also you might as well just do self.Weapon:SetNWInt( “Clicked”, value )

Why would you say self.Weapon

Like it’s on a SWEP so it’s like Weapon.Weapon…

[editline]19th April 2017[/editline]

No solution yet.

I think in an earlier version of gmod you had to access the weapon entity with self.Weapon

[editline]19th April 2017[/editline]

I’ve tried to recreate your weapon, but dropping the weapon and picking it up doesn’t seem to reset the counter for me





SWEP.PrintName = "Counter"
SWEP.Spawnable = true

SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"


function SWEP:SetupDataTables()
      self:NetworkVar("Float",0,"Clicked")
end


function SWEP:PrimaryAttack()
    self:SetClicked(self:GetClicked() + 1)
    print(self:GetClicked())
end


function SWEP:Reload()
    if SERVER then
        self.Owner:DropWeapon(self)
    end
end


function SWEP:Equip()
    print("Count on Equip:".. self:GetClicked())
end


Really wired, I copied your code over to test if it worked, and now it does???

  • But anyways Thanks!