Search code examples
garrys-mod

Know type of entity by eyetrace


How can a know an entity before me by GetEyeTrace. I want to check this and if entity == Weapon then do anything...

Whatever like below:

if ply:GetEyeTrace().Entity.IsWeapon() then
        print("+")
    end

But IsWeapon() function have no.


Solution

  • It should be :IsWeapon()

    You should also really be checking if the entity is valid.

    local ent = ply:GetEyeTrace().Entity
    if(!IsValid(ent)) then return end 
    if(ent:IsWeapon()) then
        print("This is a weapon.")
    end