################
# > HoloDraw 3: Draw things using your mouse and holograms.
# > How to use: Left click in 2 places to draw a line between. Right click to remove the last line.
################

@name HoloDraw 3
@persist VectorA:vector VectorB:vector 
@persist Position Angle:angle
@persist I DrawA Colour:vector Thickness
@persist EPos:vector

interval(10)

if (first()|duped()) {
    hint("Welcome to HoloDraw!",8)
    hint("Created by Runeneo :D",8)
    Colour = vec(0,0,255)
    Thickness = 0.5
    EPos = round(entity():pos()/(Thickness*12))*(Thickness*12)
    holoCreate(1337)
    holoCreate(1338)
    holoPos(1338,EPos)
}

Aim = round(owner():aimPos()/(Thickness*12))*(Thickness*12)
Click = owner():keyAttack1()
Remove = owner():keyAttack2()

holoPos(1337,Aim)

if (changed(Click)&Click) {
    if (!VectorA) {
        VectorA=Aim
    }
    elseif (VectorA&!VectorB) {
        VectorB=Aim
        Position=VectorA:distance(VectorB)
        DrawA=1
    }
    elseif (VectorA&VectorB) {
        VectorA=Aim
        VectorB=vec(0,0,0)
    }
}
if (DrawA&Position<600) {
    Position=VectorA:distance(VectorB)
    Angle=(VectorA-VectorB):toAngle()
    holoCreate(I)
    holoPos(I, ((VectorA+VectorB)/2))
    holoScale(I, vec(Position/12,Thickness,Thickness)+vec(Thickness,0,0))
    holoAng(I, Angle)
    holoColor(I, Colour)
    print(EPos-holoEntity(I):pos())
    print((vec(Position/12,Thickness,Thickness)+vec(Thickness,0,0)))
    print(holoEntity(I):angles())
    I++
    DrawA=0
}
elseif (DrawA&!Position<600) {
hint("Error: Selected line is too long!",8)
DrawA=0
}

if (changed(Remove)&Remove) {
    if (I < 1) {
        hint("Error: There are no more holograms!",8)
    }
    else {
        I--
        holoDelete(I)
        hint("Hologram ID: "+I+" has been removed!",8)
    }
}
