@name Motion Sensor
@persist Planted NoTeam Range
@model models/hunter/plates/plate025x025.mdl
if(first()){
 runOnTick(1)
 runOnChat(1)
 entity():propFreeze(0)
 entity():setColor(0,0,0,0)
 timer("A",2500)
 holoCreate(50)
 holoModel(50,"hq_rcylinder_thick")
 holoScale(50,vec(1.5,1.5,0.45))
 holoParent(50,entity())
 holoCreate(51)
 holoModel(51,"hq_torus")
 holoPos(51,entity():toWorld(vec(0,0,3)))
 holoScale(51,vec(0.75,0.75,1))
 holoParent(51,entity())
 holoCreate(52)
 holoModel(52,"hq_sphere")
 holoPos(52,entity():toWorld(vec(0,0,3.25)))
 holoScale(52,vec(0.6,0.6,0.2))
 holoParent(52,entity())
 holoColor(50,vec(20,20,20),255)
 holoColor(51,vec(20,20,20),255)
 holoColor(52,vec(0,25,0),255)
 Range = 2000
}
if(chatClk(owner())){  
    if(owner():lastSaid()=="/team"){ 
    hideChat(1)
    NoTeam = !NoTeam
    print("NoTeam has been toggled to "+NoTeam)
}
    S = owner():lastSaid():explode(" ")
    if(S[1,string]=="/range"){
     hideChat(1)
     Range = S[2,string]:toNumber()
     print("Motion Sensor range set to "+Range)   
    }
    if(owner():lastSaid()=="/plant"&!Planted){
        hideChat(1)
        entity():setAng(ang())
        entity():propFreeze(1)
        soundPlay(2,0,"/buttons/combine_button_locked.wav")
        timer("PS",1000)
        print("Motion Sensor has been planted")
        Planted = 1
    }
    if(owner():lastSaid()=="/unplant"&Planted){
        entity():setAng(ang())
        entity():propFreeze(0)
        soundPlay(3,0,"/buttons/blip2.wav")
        timer("UPS",1000)
        print("Motion Sensor has been unplanted")
        Planted = 0   
    }
}
if(clk("A")){
    stoptimer("A")
    timer("A",3000)
    #Updating goes here
    entity():soundPlay(1,0,"/buttons/blip1.wav")
    print("Time of scan at the time of ["+time("sec")+"] seconds on motion sensor #"+entity():id())
    timer("Color",200)
    timer("Sound",300)
    holoColor(52,vec(0,150,0))
    for(I=1,players():count()){
     Player=players()[I,entity]
     if(Player:pos():distance(entity():pos())<Range&Player!=owner()){
        if(Player:team()==owner():team()&!NoTeam){
        } elseif(Player:team()==owner():team()|Player:team()!=owner():team()){
        print(Player:name()+" is near the motion sensor at the distance of "+Player:pos():distance(entity():pos()))
    }
    }
    }
}
if(clk("Color")){
 stoptimer("Color")
 holoColor(52,vec(0,25,0))   
}
if(clk("Sound")){
 stoptimer("Sound")
 soundStop(1)   
}
if(clk("PS")){
 stoptimer("PS")
 soundStop(2)   
}
if(clk("UPS")){
 stoptimer("UPS")
 soundStop(3)   
}
if(entity():vel():length()<5){
 timer("B",1000)   
}
if(clk("B")&entity():vel():length()==0){
 stoptimer("B")
 entity():setAng(ang())
}
if(clk("B")){
 stoptimer("B")   
}
if(dupefinished()){
 reset()   
}
if(!Planted&owner():pos():distance(entity():pos())<100&owner():aimEntity()==entity()&changed(owner():keyUse())&owner():keyUse()){
    entity():setAng(ang())
    entity():propFreeze(1)
    soundPlay(2,0,"/buttons/combine_button_locked.wav")
    timer("PS",1000)
    print("Motion Sensor has been planted")
    Planted = 1
}

if(Planted&owner():pos():distance(entity():pos())<100&owner():aimEntity()==entity()&changed(owner():keyAttack2())&owner():keyAttack2()){
    entity():setAng(ang())
    entity():propFreeze(0)
    soundPlay(3,0,"/buttons/blip2.wav")
    timer("UPS",1000)
    print("Motion Sensor has been unplanted")
    Planted = 0
}

if(!entity():isFrozen()){
 Planted = 0   
}

