Hi, I’m working on a new gamemode for practice and for fun and I’ve run into a problem. I’ve got the following code:
function GM:PlayerSwitchWeapon( ply, oldWeapon, newWeapon )
if newWeapon:GetClass() != "weapon_physcannon" or "weapon_physgun" or "gmod_tool" then
ply:GodDisable()
else
return false
end
end
However, whenever I switch my weapon to grav gun or tool gun, it disables god. Same with any other weapon too. What am I doing wrong?
Thanks!
You should be using and since or will pass if one element is true. Also, you can’t test them in a series like that when using a != operator; you must test each one.
Your code:
function PlayerSwitchWeapon( ply, oldWeapon, newWeapon )
if newWeapon ~= "weapon_physcannon" or "weapon_physgun" or "gmod_tool" then
print"passed" else print"didn\'t pass"
end
end
PlayerSwitchWeapon( "", "", "weapon_physcannon")
PlayerSwitchWeapon( "", "", "weapon_physgun")
PlayerSwitchWeapon( "", "", "gmod_tool")
PlayerSwitchWeapon( "", "", "weapon_yeah")
Output:
passed
passed
passed
passed
New code:
function PlayerSwitchWeapon( ply, oldWeapon, newWeapon )
if newWeapon ~= "weapon_physcannon" and newWeapon ~= "weapon_physgun" and newWeapon ~= "gmod_tool" then
print"passed" else print"didn\'t pass"
end
end
PlayerSwitchWeapon( "", "", "weapon_physcannon")
PlayerSwitchWeapon( "", "", "weapon_physgun")
PlayerSwitchWeapon( "", "", "gmod_tool")
PlayerSwitchWeapon( "", "", "weapon_yeah")
Output:
didn't pass
didn't pass
didn't pass
passed
[editline]5th January 2015[/editline]
Comment that out and try again; do they still turn pink?