RE: Where to put file - reference
https://wiki.garrysmod.com/page/Beginner_Tutorial_IntroPlace your file in garrysmod\lua\autorun\server, unless the mod you're working with has a recommendation already.
(Example, our ULib library, and ULX admin mod have a modules folder similar to the Gmod autorun - difference? Our folders only load modules after our libraries and functions have been initialized. A function written for ULib could error if a Ulib command was called on the server before ULib had loaded (same for ULX, before ULX loaded)
Re: Ensure code is running constantly
1) A) You can't test this in a single player game. Reference the very top of the PlayerSwitchWeapon hook - it's a predicted hook that requires server comms - not run in client domain unless on server too.
B) I _think_ this could be tested on a listen server (server started while in game client, not srcds)
2) It's a hook - Hooks are always 'running', that is, trying to hook into a game event, in this case, a weapon switch. They do have 'domains' - server, client, shared. This hooks is a shared hook, with a limitation (see #1A)
LOGIC
I see a challenge here.
Let me verify - you want to make sure the person being spawned is ONLY switching to a tool, camera, or physgun, right?
Think TRUE or FALSE.
With your IF statement the way it is now, _ANY_ item not matching the other two comes out false.
if newwep ~= "weapon_physgun" and newwep ~= "gmod_camera" and newwep ~= "gmod_tool" then
Say I switch to a camera.
(true and false and true) == false
switch to physgun
(false and true and true) == false
switch to any tool
(true and true and false) == false
Try checking to see if newwep IS any of the 3, and use OR, but with a negate in front of the check, and parenthesis to group.
if not (newwep == "weapon_physgun" or newwep == "gmod_camera" or newwep == "gmod_tool") then
physgun
not (true or false or false) == false (not true = false)
camera
not (false or true or false) == false (not true = false)
tool
not (false or false or true) == false (not true = false)
WEAPON
not (false or false or false) == TRUE (not false = true - KILL PROTECTION)