How do I get the variable of a clientside weapon?

Alright, so I could be completely misreading a large swath of Lua code, but many TTT weapons have block of code like this:

if CLIENT then
	SWEP.PrintName = "AK47"
	SWEP.Slot      = 2 -- add 1 to get the slot number key

	SWEP.ViewModelFOV  = 72
	SWEP.ViewModelFlip = true

-- Always derive from weapon_tttbase.
SWEP.Base				= "weapon_tttbase"

Why is there an “if CLIENT then” conditional? These are just variables, are they not? Setting them outside of the conditional doesn’t seem like it should cause any harm.

So onto my question. I need to get the slot of a weapon in the pointshop of my server, because when players buy a weapon, it isn’t forcing the player to drop their previous weapon first. I can get players to drop their weapons, but only if I can read the Slot attribute on my custom weapons (for which I removed the “if CLIENT then” check). Is this possible? I’ve been trying things like this:

lua_run p = player:GetByID(5)
lua_run p:SendLua("w = weapons.Get('weapon_ttt_ak47')  ; print('say ' .. w.Slot)")

But I don’t even know how I would save w.Slot to a variable. Any ideas?

Don’t remove the if client check just move SWEP.Slot outside of it

Aren’t they the exact same result?

Send Lua is apparently a big no no I’ve heard…

Try creating a function with the ply as a variable and do your work there

Only a big no if you are sending user defined information.
This is fine since there isn’t much the client can do

You’re limited to 255 characters if I recall correctly. Personally, if used in a private dev-tool then whatever. In a production release I’d rather use net messages. But, because of my net system I haven’t used it in any of my dev-tools…

I have used it in some of my examples for chat.AddText, in the _systems directory, and some use net, and others use dynamic function names and dynamic first argument depending on if the server console typed in the command vs a player…

Also, somewhat related so as not to start a new thread: is it possible to get the value of a client-side console variable while iterating though player.GetAll()?


I kept searching keywords along the line of “client console variable garry’s mod”, but could only find this.

Reminds me of setinfo in EventScripts.

Sadly, it doesn’t work for what I want it to. I tried to run:

for k, p in pairs(player.GetAll()) do print(p:GetInfo('ttt_spectator_mode')) end

But according to the this, it does not work because it is not flagged as user info. I’ll post on the TTT forums about this.

And if anyone finds a way to query clientside variables of weapons, replies are still welcome.