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:
[code]
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)
[/code]
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.
[code]
false
look true
false
[/code]
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.
You are setting the variable on client, but not server, that's your problem. You gotta use net library for this.
Is there a way for a client to carry their own global values or is that completely impossible? I saw some ConVar client command, but it looks like its static; is a dynamic global variable only possible via server side?
Sorry, you need to Log In to post a reply to this thread.