@name Scriptis' Precision Helper

interval(100)
Ent=owner():aimEntity()
    EntPos=Ent:pos()
    Size=Ent:aabbSize()/2
    TargetPos=vec(round(EntPos:x()),round(EntPos:y()),round(EntPos:z()))

Pos=owner():aimPos()
Face=Ent:toLocal(Pos)

Dir=0
PrintStr=""
NudgeDist=0
Offset=0
## Determine Face
#1 Up
#2 Down
#3 Left
#4 Right
#5 Forward
#6 Back

if (Ent) {
    local Offset=Ent:toWorld(TargetPos)
    if (Face:z()>=Size:z()) {
        Dir=1
        NudgeDist=Offset:z()
    }
    
    elseif (Face:z()<=-Size:z()) {
        Dir=2
        NudgeDist=-Offset:z()
    }
    
    elseif (Face:x()>=Size:x()) {
        Dir=3
        NudgeDist=Offset:x()
    }
    
    elseif (Face:x()<=-Size:x()) {
        Dir=4
        NudgeDist=-Offset:x()
    }
    
    elseif (Face:y()>=Size:y()) {
        Dir=5
        NudgeDist=Offset:y()
    }
    
    elseif (Face:y()<=-Size:y()) {
        Dir=6
        NudgeDist=-Offset:y()
    }
    
    local AimMatrix=array("Up","Down","Left","Right","Forward","Back")
    if (EntPos!=TargetPos) {
        PrintStr+="Not Aligned"
    } else {
        PrintStr+="Aligned"
    }
    PrintStr+="
"+AimMatrix[Dir,string]+"
"+NudgeDist
    print(_HUD_PRINTCENTER,PrintStr)
    concmd("precision_nudge "+NudgeDist)
}
