@inputs Player
@outputs X Y
@name Cash Detecter
@persist I Off 
runOnTick(1)
if(duped() == 1) {selfDestructAll()}

findByModel("models/props/cs_assault/Money.mdl")
Props = findToArray()
E = Props:entity(1)  
EE=entity()
Dist = E:pos():distance(EE:pos())


# nice little beeping that makes it kindof like a metal detecter
if (clk("Beep") & Props:entity(1)) {
    soundVolume(0,(1/4))
    soundPitch(0,200-E:pos():distance(EE:pos())/10)
    timer("Stop",1000)
}

if (clk("Stop")) {
    soundVolume(0,0)
    timer("Beep",Dist)
}

#find the angle the arrow will point (math stuff)
Slope = (E:pos():y()-EE:pos():y())/(E:pos():x()-EE:pos():x())

Y = sign(E:pos():y()-EE:pos():y())
X = sign(E:pos():x()-EE:pos():x())
 
if (sign(E:pos():y()-EE:pos():y()) == 1 & sign(E:pos():x()-EE:pos():x()) == 1) {
ArrowAngle = atan(Slope)+90
}
elseif (sign(E:pos():y()-EE:pos():y()) == -1 & sign(E:pos():x()-EE:pos():x()) == 1) {
ArrowAngle = atan(Slope)+90
}
elseif (sign(E:pos():y()-EE:pos():y()) == 1 & sign(E:pos():x()-EE:pos():x()) == -1) {
ArrowAngle = atan(Slope)-90
}
elseif (sign(E:pos():y()-EE:pos():y()) == -1 & sign(E:pos():x()-EE:pos():x()) == -1) {
ArrowAngle = atan(Slope)-90
}


#if there is money it will make the arrow green and tracking starts
if (Props:entity(1)) {
    holoColor(1,vec(0,255,0),255)
    holoColor(0,vec(0,255,0),255)
    timer("Beep",Dist)
    holoAng(1,ang(0,ArrowAngle,90))
    
    
    #item Position (with a little arrow :D)
    holoCreate(2)
    holoModel(2,"cone")
    holoPos(2,(E:pos()+vec(0,0,5)))
    holoParent(2,E)
    holoScale(2,vec((1/4),(1/4),(1/4)))
    holoColor(2,vec(255,0,0),100)
    holoAng(2,ang(180,0,0))
    
    
    #stem :D i could have left it a cone but I like you!
    #you can remove if you have more than this chip going
    holoCreate(3)
    holoModel(3,"cylinder")
    holoPos(3,(E:pos()+vec(0,0,8)))
    holoParent(3,E)
    holoScale(3,vec((1/8),(1/8),(1/4)))
    holoColor(3,vec(255,0,0),100)
    holoAng(3,ang(180,0,0))
    
}


#This will make the noise stop and turn the arrow red
if (!Props:entity(1)) {
    holoColor(1,vec(255,0,0),255)
    holoColor(0,vec(255,0,0),255)
    soundVolume(0,0) # I use volume instead of purge because i find it easier
}


if (first() | duped())
    {
    soundPlay(0,100,"synth/saw.wav")
    timer("Beep",Dist)
    hint("Made by DrFrev",1)
    #My first expression done completely by me
    #Dr.Frev #1
    
    #arrow stem
    holoCreate(1)
    holoModel(1,"cylinder")
    holoPos(1,EE:pos()+vec(0,0,7))
    holoScale(1,vec((1/8),(1/8),(1/4)))
    holoColor(1,vec(255,0,0),255)
    holoParent(1,EE)
    holoAng(1,ang(90,0,90))
    
    #arrow point
    holoCreate(0)
    holoModel(0,"cone")
    holoPos(0,EE:pos()+vec(0,-3,7))
    holoScale(0,vec((1/4),(1/4),(1/4)))
    holoColor(0,vec(255,0,0),255)
    holoParent(0,1)
    holoAng(0,ang(90,0,90))
}
