@name Sonic Distraction
@inputs 
@outputs N Deg Tag S On T:entity W B M 
@persist Deg Tag S W B M On T:entity
@trigger 
Sound="/player/footsteps/concrete"
Ext=".wav"
Bolts="/weapons/crossbow/hit1.wav"
SMGS="/weapons/smg1/smg1_fireburst1.wav"
N=randint(1,4)

O=owner()
runOnChat(1)
Chat=owner():lastSaid()
Com="SD"
Walk1="W"
Walk0="w"
Bolt1="B"
Bolt0="b"
Smg1="M"
Smg0="m"
Brk=" "
COM=Chat:find(Com)
WALK1=Chat:find(Walk1)
WALK0=Chat:find(Walk0)
BOLT1=Chat:find(Bolt1)
BOLT0=Chat:find(Bolt0)
SMG1=Chat:find(Smg1)
SMG0=Chat:find(Smg0)

if(chatClk(O)&COM){
    Tar=Chat:explode(Brk)[2,string]   
    if(Tar){
        T=findPlayerByName(Tar)
        print("Sonic Distractions Targeting "+T:name())
    }
    if(WALK1){W=1 timer("walk",1) print("Ghost walk enabled")}
    if(WALK0){W=0 print("Ghost walk disabled")}
    if(BOLT1){B=1 timer("bolt",1) print("Ghost bolts enabled")}
    if(BOLT0){B=0 print("Ghost bolts disabled")}
    if(SMG1){M=1 timer("smg",1) print("Ghost SMG enabled")}
    if(SMG0){M=0 print("Ghost SMG disabled")}
}
if(first()){
    Tag=1 
    On=1 
    print("Welcome to Sonic Distractions")
    print("Type "+Com+" plus a '"+Brk+"' and a name fragment to target someone.")
    print("before the '"+Brk+"' include a '"+Smg1+"' '"+Walk1+"' or a '"+Bolt1+"' to enable SMG, Walking, or bolt audio halucinations.")
    print("or use '"+Smg0+"' '"+Walk0+"' '"+Bolt0+"' To disable SMG, Walk and Bolt audio halucinations, respectively.")
}
    
if(clk("walk")){On=1 Deg=0}
Rad=150
Speed=50
if(T){
interval(350)
    if(W&On){ 
        if(!holoEntity(1)){holoCreate(1,T:pos())}
        Deg+=5*Tag
        holoPos(1,T:pos()+vec(cos(curtime()*Speed)*Rad,sin(curtime()*Speed)*Rad,0))
        if(Deg<0){Tag=1 On=0 timer("walk",randint(1,20)*1000)}
        if(Deg>randint(22,45)){Tag=-1}
        holoVisible(1,players(),0)
        #holoVisible(1,O,1)
        S=sin(Deg)
        
        holoEntity(1):soundPlay(1,3,Sound+N+Ext)
        soundVolume(1,S)
    }else{holoDelete(1)}
    if(B&clk("bolt")){
        holoCreate(2,T:pos()+randvec(vec(Rad,Rad,0),vec(-Rad,-Rad,0)))
        holoEntity(2):soundPlay(2,2,Bolts)
        holoVisible(2,players(),0)
        timer("bolt",randint(1,30)*1000)
    }else{holoDelete(2)}
    
    if(M&clk("smg")){
        holoCreate(3,T:pos()+randvec(vec(Rad,Rad,0),vec(-Rad,-Rad,0)))
        holoEntity(3):soundPlay(2,4,SMGS)
        holoVisible(3,players(),0)
        timer("smg",randint(1,30)*1000)
    }else{holoDelete(3)}
    
}

