Double question: Using Player. at the start of function names, and Entity.IsWeapon error

Question 1
If I do:
[lua]
function Player.IsModerator(ply)
[/lua]
can I later do:
[lua]
if ply:IsModerator() == true then
[/lua]
or should I name it
[lua]
function IsModerator(ply)
[/lua]
and would it work as
[lua]
if ply:IsModerator() == true then
[/lua]

Question 2
In my code
[lua]
if ent:IsPlayer() == false and ent:IsNPC() == false and ent:IsWorld() == false and ent:IsVehicle() == false and ent:GetClass() != “crate” then
[/lua]
SWEPs don’t execute my function.
It seems like props, SENTs and SWEPs should all pass that check, right?

@your first question
If you have your function as Player.IsModerator(ply) that is adding the function “IsModerator” to the “Player” table - you may be able to call it as ply:IsModerator() that way though I am not certain (That kinda stuff always confuses me)
If you declare it the second way you listed, you would have to call it like “if IsModerator(ply) then” as it is not apart of the Player or Entity class.

@your second question
Instead of checking if something is NOT what you’re looking for, check to see if it IS what you are looking for.
Also you can shorten your boolean checks (I personally thing “if var == false” looks ugly) you can enter “if not var and not anothervar then”

Thanks for the prompt response!
What though, is the function for checking for a SENT? And also, I have made it:
[lua]
if ent:IsWeapon() then
–codecodecode
[/lua]
And it dosen’t work.

SENT’s are treated as any other entity, they have their own class name given by the creator of the SENT.
I don’t believe there is a function to check to see if an entity is a SENT or an engine entity.

Are you trying to check for SENT’s in general or a specific SENT?

[editline]27th March 2011[/editline]

And back at your first question - after reading another thread I BELIEVE you can do something like

[lua]
function _R.Player:IsModerator()
//your code
end
[/lua]
And can then run it as
ply:IsModerator()