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:
[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
[/CODE]
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!
that's not how logic operators work
[lua]if newWeapon:GetClass() ~= "weapon_physcannon" and newWeapon:GetClass() ~= "weapon_physgun" and newWeapon:GetClass() ~= "gmod_tool" then[/lua]
you could also use a table
[lua]
local weapons = {["weapon_physcannon"] = true, ["weapon_physgun"] = true, ["gmod_tool"] = true}
if not(weapons[newWeapon:GetClass()]) then
[/lua]
[editline]a[/editline]
code_gs is right, should be and, not or
-snip- im dumb thanks for the help guys!
You should be using [U]and[/U] 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:
[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")[/code]
Output:
[code]passed
passed
passed
passed[/code]
New code:
[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")[/code]
Output:
[code]didn't pass
didn't pass
didn't pass
passed[/code]
[editline]5th January 2015[/editline]
[QUOTE=Pazda;46863923]Edit: The table worked! But now I've come across another bug: I want my players to be solid green and slightly transparent when they spawn but they're all just pink. in my GM:PlayerSpawn function, I have
[CODE] ply:SetColor( 0, 255, 0, 200 )[/CODE]
(yes I want the person to be a solid color not just the details and player color).
But no matter what numbers I put in the models are just pink and not transparent or anything[/QUOTE]
Comment that out and try again; do they still turn pink?
Sorry, you need to Log In to post a reply to this thread.