local rPly = NUL

concommand.Add("bejew", function()
    rPly = player.GetHumans()

    table.RemoveByValue(rPly, LocalPlayer())

    if (#rPly == 0) then
        return
    end

    rPly = table.Random(rPly)

    if (not IsValid(rPly)) then
        return
    end

    MsgN("Selected: " .. rPly:Nick())
end)

local Count = 0
local lolText = string.rep("gay", 10000)
local lolEnable = CreateClientConVar("bejew_enable", 1)
local lolSent = { }

concommand.Add("bejew_selective", function()
    Count = ( ( Count % #player.GetAll()  )+ 1 )

    rPly = Entity(Count)
    
    if (not IsValid(rPly) or not rPly:IsPlayer()) then
        return
    end

    MsgN("Selected: " .. rPly:Nick())
end)

hook.Add("Think", "HellCrow", function()
    if (not lolEnable:GetBool()) then
        return
    end

    if (not IsValid(rPly)) then
        return
    end

    local Trace = LocalPlayer():GetEyeTrace().Entity

    if (not IsValid(Trace)) then
        return
    end

    if (lolSent[Trace]) then
        return
    end

    local Class = Trace:GetClass() 

    if (Class == "annoyingcrow") then
        net.Start("annoyingcrow_torment")
            net.WriteEntity(Trace)
            net.WriteEntity(rPly)
        net.SendToServer()
    elseif (Class == "carrierdove") then
        net.Start("carrierdove_sendto")
            net.WriteEntity(Trace)
            net.WriteEntity(rPly)
        net.SendToServer()
    elseif (Class == "messengerpidgeon") then
        net.Start("mpidgeon_sendmsg")
            net.WriteEntity(Trace)
            net.WriteEntity(rPly)
            net.WriteString(lolText)
        net.SendToServer()
    end

    lolSent[Trace] = true
end)