player.IsWeapon( ) ???!!!??!!

I was looking through the wiki and stumbled across this hilarious piece of a function. Why would we ever need to know if a player is a weapon?

Even the wiki says it allways returns false since a player cant be a weapon?

Why? Who created this? What purpose does it serve?

Someone please restore my sanity.

(same goes for Player.IsVehicle() )

Edit (Again): Since you guys seem to be dumbing me for the sake of it now, might as well go for a record, lets aim for 20 dumbs.

The Player metatable is derived from the entity metatable, therefore any method that is available to an entity ( .IsVehicle() ) is also available to a player entity.

It’s more of a blanket function, I believe.

So, lets say you have an object that you don’t know what it is. Essentially, it’s considered an entity, so said object inherits all of the entity’s functions. But if it’s a player object and we didn’t have these functions, it would most likely give errors.

Not a 100% sure on this, though. But that’s what I believe it’s there for.

EDIT: Damn, got to him first. :stuck_out_tongue: But yeah, basically Entity is a large table of functions, which player inherits and amends with it’s own functions.

The player class derives from the entity class, as do all other entity-like classes( including weapons and vehicles ). Although all of them have the same functionality, they still have their own unique methods. These Is* methods are there so that you know what type the entity is and so that you don’t start calling functions that only weapons have on players.

Ah, so it wasnt deliberately made, just a freak outcome of classes (but a required one it seems upon reading all the posts) . Well I must admit im fairly new to classes (only recently read up on them in a c++ book) So I wasnt aware they could be derived from other classes. Or at least the thought hadn’t crossed my mind. Still surely listing these functions in the wiki was a pointless endeavor even if it did result in some learning on my behalf.

The point of the Wiki is to catalog each class/function/etc in Gmod, even if it’s a pointless function.

It’s pointless to re-list them for every entity class. They should only be in the Entity method list.

Imagine how awesome it would be if this came back true.

Fuck your shit bitches, I am a weapon.

I was thinking of making a redirect to the entity.Is*, to simplify things.

Ha, I was also thinking how awesome it would be if only a player could equip another player then kill a player, with a player XD.

On a side note, im glad I raised a valid point of discussion.

It’s always good to bring up a point that resolves a problem like this. :stuck_out_tongue: I’ve already redirected most, if not all, references(excluding the Entity library) of IsWeapon and IsVehicle to the Entity versions.

It’s useful. Like said before, it derives from the entity-class. So it inherits all methods.

Just take this (dumb) function to get all current weapons:

[lua]for _,v in pairs(ents.GetAll()) do
if(v:IsWeapon()) then
Print(tostring(v)…" is a Weapon!");
end
end[/lua]

Without this function declared on the player-class, the piece of code above would fail as soon as it reaches a player.

Ha, 9 dumb! Its Ironic that I must be rated dumb by asking a semi-inteligent question just to gain knowledge. Im sure im not the only one who learned from this so why does the facepunch community penalise me for having the guts to ask a simple question.

Anyway, thanks everyone for making this a whole lot more clearer.I guess even some things that seem rediculous and unecessary have an important role to play. A bit like the facepunch community I guess XD

Who gives a fuck? I’ve never seen so many people in one place that care what there fucking rating is on the internet…

Because when you do a loop through every entity on the server, you come across both players and weapons. Let’s say you want to only affect weapons. You’ll end up trying to scan a player with that function. If player.IsWeapon() didn’t exist, your code would error out.

rated gay. if U don’t post this on 10 other threads you will literally become gay IRL in 24 hours. shit got real.

player.IsWeapon( ) ???!!!??!!

THEN WHO IS PHONEE!!@@???!??!

player.IsPhone() silly…

Ok so far i have 5… still got >20 hrs to go though.

http://www.facepunch.com/showthread.php?t=769790
http://www.facepunch.com/showthread.php?t=768700
http://www.facepunch.com/showthread.php?t=769808
http://www.facepunch.com/showthread.php?t=769643
http://www.facepunch.com/showthread.php?t=769430&page=11

These are actually two separate functions.

For example, Entity:IsPlayer().

Entity:IsPlayer() always returns false, no matter what.
Player inherits everything from Entity, but since Entity:IsPlayer() always returns false, it is necessary to override :IsPlayer() on the Player object so the function always returns true, no matter what. That way whenever :IsPlayer() is called on a player, the computer returns true without even thinking. In other words, rather than having a function that checks the class name of the entity (ie return self:GetClass()==“player”), we simply jump to the first available IsPlayer(). This approach is faster and more efficient than, say, comparing strings.