Hi, Im trying to make a gun that can carry a global variable, as well as change it, right now this is what it looks like:
SWEP.Spawnable = true SWEP.AdminOnly = true SWEP.UseHands = true SWEP.ViewModel = "models/weapons/c_pistol.mdl" SWEP.WorldModel = "models/weapons/w_pistol.mdl" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.PrintName = "Gun" SWEP.Slot = 3 SWEP.SlotPos = 1 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true SWEP.UseHands = true local VAR function SWEP:Initialize() VAR = false end function SWEP:PrimaryAttack() print(VAR) end function SWEP:SecondaryAttack() if(SERVER) and !VAR then VAR = true end if(CLIENT) then VAR = true end print("look ", VAR) end function ZoomView(ply, pos, angles, fov) if VAR then print("happy") VAR = false end end hook.Add("CalcView", "ZoomView", ZoomView)
As you can see I have no idea what im doing, I’ve tried a number of things and cant seem to really get any results.
Heres some example output if I press mouse1, mouse 2, mouse 1.
false look true false
if I throw a print(VAR) at the beginning of ZoomView it prints nil; can anyone give me some advice on what Im doing wrong? do I have to use a usermessage or something? Shouldnt all of this data be shared? I really havent the faintest clue why this doesnt work.