@name Cool Camera
@persist [E P H]:entity D
if(first() | dupefinished() | duped())
{
    runOnTick(1)
    E = entity():isConstrainedTo()
    if(E:type()!="gmod_cameraprop")
    {
        selfDestruct()
    }
    
    entity():deparent()
    entity():propNotSolid(1)
    entity():setPos(owner():shootPos())
    
    entity():setColor(vec4())
    
    E:propFreeze(1)
    E:setColor(vec4())
    E:propNotSolid(1)
    
    P = owner()
    
    D = 150
    
    runOnChat(1)
}

if(chatClk(owner()))
{
    LS = owner():lastSaid():lower():explode(" ")
    if(LS[1,string][1]=="-")
    {
        hideChat(1)
        switch(LS[1,string])
        {
            case "-d",
                D = LS[2,string]:toNumber()
            break
            
            case "-t",
                P = findPlayerByName(LS[2,string]) ?: P
        }
    }
}

#[
if(P:keyAttack1())
{
    if(!H:isValid())
    {
        H = P:aimEntity()
    }
}else
{
    H = noentity()
}
]#

findByClass("crossbow_bolt")
findSortByDistance(P:pos())
H = (find():vel():length() > 0 ? find() : noentity())

#V = H:isValid() ? (P:shootPos()+vec(0,0,30) + (H:pos()))/2 : P:shootPos()+vec(0,0,10)
V = H ? H:pos() : P:shootPos() + vec(0, 0, 10)
#V = (H:isValid() ? (P:shootPos() + vec(cos(P:eyeAngles():yaw() - 90) * D/2, sin(P:eyeAngles():yaw() - 90) * D/2, 25)) : P:shootPos()) - P:eye() * D
A = H:isValid() ? (H:pos() - E:pos()):toAngle() : P:eyeAngles()
E:setPos(E:toWorld(E:toLocal(V+(V-E:pos()):normalized()*-D)/(H:isValid() ? 2 : 10)))
#E:setPos(E:toWorld(E:toLocal(V)/(P != owner() ? 5 : 3)))
E:setAng(E:toWorld(E:toLocal((V-E:pos()):toAngle())/10))
#E:setAng(E:toWorld(E:toLocal(A)/(P != owner() ? 10 : 3)))
