@name Lightsaber by Dad, Danking, and OmicroN
@outputs Toggle Light On [SC Approved]:string Clk Clk3 Colors:table

if(!On){ interval(1000) }else{ interval(10) }

LS = lastSpoke():owner():lastSaid():lower()
C = chatClk(owner())

E = owner()
Clk = E:keyAttack2() & owner():weapon():type()=="weapon_crowbar" & On
Clk3 = E:keyAttack1() & owner():weapon():type()=="weapon_crowbar" & On
Toggle = owner():keyUse()& owner():weapon():type()=="weapon_crowbar"

if(first() | duped() | (C & LS == "-list")){
    runOnChat(1)
    hideChat(1)
    On = Light = 0
    print("Holo LightSaber by Dad Danking and OmicroN!")
    printColor(vec(255,0,0),("             Hold E button to place lightsaber in hand"))
    printColor(vec(255,155,0),("Available colors are:"))
    printColor(vec(255,0,0),"           -red",vec(50,50,255)," -blue",vec(100,255,0)," -green",vec(0,255,0)," -green2",vec(255,255,0)," -yellow",vec(255,0,255)," -purple")
    printColor(vec(255,0,0),"           -ared",vec(0,100,255)," -ablue",vec(255,255,255)," -alig -disco -gmod")
    printColor(vec(255,155,0),("Type '-list' to view this again!"))
    Approved = "red blue green green2 yellow purple ared ablue alig disco gmod"
    Colors["red",vector] = vec(255,255,255) , Colors["red",string] = "cable/redlaser"
    Colors["blue",vector] = vec(50,50,255) , Colors["blue",string] = "cable/xbeam"
    Colors["green",vector] = vec(255,255,255) , Colors["green",string] = "cable/hydra"
    Colors["green2",vector] = vec(20,200,20) , Colors["green2",string] = "cable/xbeam"
    Colors["yellow",vector] = vec(255,200,20) , Colors["yellow",string] = "cable/xbeam"
    Colors["purple",vector] = vec(100,20,200) , Colors["purple",string] = "cable/xbeam"
    Colors["ared",vector] = vec(255,255,255) , Colors["ared",string] = "models/props_combine/tprings_globe"
    Colors["ablue",vector] = vec(255,255,255) , Colors["ablue",string] = "models/alyx/emptool_glow"
    Colors["alig",vector] = vec(255,255,255) , Colors["alig",string] = "models/effects/comball_sphere"
    Colors["disco",vector] = vec(255,255,255) , Colors["disco",string] = "effects/flashlight/tech"
    Colors["gmod",vector] = vec(255,255,255) , Colors["gmod",string] = "effects/flashlight/logo"
}

if((Toggle & $Toggle) & !On){
    On = 1 , Light = 0
    printColor(vec(0,255,0),("Lightsaber is Out!"))
    printColor(vec(255,0,255),("Right Click to TURN ON Lightsaber"))
    for(I=0,11){
        if(I<4 | I>5){
        holoCreate(I)
        }
    #holoCreate(0) #dummy hologram to receive occasional Pos bug
    holoAlpha(0,0)
    holoAng(0,owner():attachmentAng("anim_attachment_RH"))
    holoPos(0,owner():attachmentPos("anim_attachment_RH"))
    holoParentAttachment(0,owner(),"anim_attachment_RH")
    holoScale(0,vec(0.01,0.01,0.01)) 
    holoPos(0,holoEntity(0):toWorld(vec(0,0,0)))
    holoAng(0,holoEntity(0):toWorld(ang(0,0,0)))
        
    # Handle
    holoModel(1,"hqcylinder2")
    holoAng(1,owner():attachmentAng("anim_attachment_RH"))
    holoPos(1,owner():attachmentPos("anim_attachment_RH"))
    holoParentAttachment(1,owner(),"anim_attachment_RH")
    holoScale(1,vec(0.15,0.15,0.7)) 
    holoColor(1,vec(20,20,20))
    holoMaterial(1,"phoenix_storms/chrome")
    holoPos(1,holoEntity(1):toWorld(vec(0,0,1)))
    holoAng(1,holoEntity(1):toWorld(ang(0,0,0)))
    
    # Black things
    holoModel(2,"cube")
    holoScale(2,vec(0.05,0.2,0.3)) 
    holoMaterial(2,"")
    holoPos(2,holoEntity(1):toWorld(vec(0,0,-2.2)))
    holoAng(2,holoEntity(1):toWorld(ang(0,0,0)))
    holoParent(2,1)
    holoColor(2,vec(0,0,0))
    
    # hand guard thing
    holoModel(3,"cube")
    holoScale(3,vec(0.2,0.05,0.3))
    holoColor(3,vec(0,0,0))
    holoMaterial(3,"models/props_pipes/GutterMetal01a")
    holoPos(3,holoEntity(1):toWorld(vec(0,0,-2.2)))
    holoAng(3,holoEntity(1):toWorld(ang(0,0,0)))
    holoParent(3,1)
    
    holoModel(6,"dome2")
    holoAng(6,owner():attachmentAng("anim_attachment_RH"))
    holoPos(6,owner():attachmentPos("anim_attachment_RH"))
    holoParentAttachment(6,owner(),"anim_attachment_RH")
    holoScale(6,vec(0.15,0.15,0.13)) 
    holoColor(6,vec(0,0,0))
    holoMaterial(6,"")
    holoPos(6,holoEntity(1):toWorld(vec(0,0,4.5)))
    holoAng(6,holoEntity(1):toWorld(ang(-140,0,0)))
    
    holoModel(7,"hqcylinder2")
    holoAng(7,owner():attachmentAng("anim_attachment_RH"))
    holoPos(7,owner():attachmentPos("anim_attachment_RH"))
    holoParentAttachment(7,owner(),"anim_attachment_RH")
    holoScale(7,vec(0.17,0.17,0.17)) 
    holoColor(7,vec(20,20,20))
    holoMaterial(7,"phoenix_storms/chrome")
    holoPos(7,holoEntity(1):toWorld(vec(0,0,0)))
    holoAng(7,holoEntity(1):toWorld(ang(0,0,0)))
    
    holoModel(8,"squere")
    holoAng(8,owner():attachmentAng("anim_attachment_RH"))
    holoPos(8,owner():attachmentPos("anim_attachment_RH"))
    holoParentAttachment(8,owner(),"anim_attachment_RH")
    holoScale(8,vec(0.05,0.15,0.17)) 
    holoColor(8,vec(255,200,20))
    holoMaterial(8,"")
    holoPos(8,holoEntity(1):toWorld(vec(0.2,0.2,0)))
    holoAng(8,holoEntity(1):toWorld(ang(0,-40,0)))
    
    holoModel(9,"hqcylinder2")
    holoAng(9,owner():attachmentAng("anim_attachment_RH"))
    holoPos(9,owner():attachmentPos("anim_attachment_RH"))
    holoParentAttachment(9,owner(),"anim_attachment_RH")
    holoScale(9,vec(0.05,0.05,0.05)) 
    holoColor(9,vec(255,200,20))
    holoMaterial(9,"")
    holoPos(9,holoEntity(1):toWorld(vec(1.03,0,3)))
    holoAng(9,holoEntity(1):toWorld(ang(90,0,0)))
    
    holoModel(10,"hqcylinder2")
    holoAng(10,owner():attachmentAng("anim_attachment_RH"))
    holoPos(10,owner():attachmentPos("anim_attachment_RH"))
    holoParentAttachment(10,owner(),"anim_attachment_RH")
    holoScale(10,vec(0.065,0.065,0.095)) 
    holoColor(10,vec(255,200,20))
    holoMaterial(10,"phoenix_storms/chrome")
    holoPos(10,holoEntity(1):toWorld(vec(0.6,0,3)))
    holoAng(10,holoEntity(1):toWorld(ang(90,90,90)))
    
    holoModel(11,"hqcylinder2")
    holoAng(11,owner():attachmentAng("anim_attachment_RH"))
    holoPos(11,owner():attachmentPos("anim_attachment_RH"))
    holoParentAttachment(11,owner(),"anim_attachment_RH")
    holoScale(11,vec(0.16,0.16,0.16)) 
    holoColor(11,vec(0,0,0))
    holoMaterial(11,"")
    holoPos(11,holoEntity(1):toWorld(vec(0,0,3.25)))
    holoAng(11,holoEntity(1):toWorld(ang(0,0,0)))
    }
}elseif((Toggle & $Toggle) & On){
    for(I=0,11){
        holoDelete(I)
    }
    printColor(vec(255,0,0),("Lightsaber is Put Away!"))
    soundPurge()
    On = 0
}

if(C){
    if(LS:index(1)=="-" & Approved:find(LS:right(LS:length()-1))){
        hideChat(1)
        Color = Colors[LS:right(LS:length()-1),vector]
        Mat = Colors[LS:right(LS:length()-1),string]
        holoColor(4,Color)
        holoMaterial(4,Mat)
        holoColor(5,Color)
        holoMaterial(5,Mat)
        print("Lightsaber color is now '"+LS:right(LS:length()-1)+"'!")
    }elseif(LS:index(1)=="-" & !Approved:find(LS:right(LS:length()-1))){
        hideChat(1)
        printColor(vec(255,0,0),LS:right(LS:length()-1)+" is NOT an approved color, for a list type '-list'")
    }
}    
    
    if(Clk & $Clk){
        if(!Light){
            owner():soundPlay(0,0,"weapons/physgun_off.wav")
            soundPitch(0,160)
            owner():soundPlay(1,0,"ambient/atmosphere/city_beacon_loop1.wav")
            soundPitch(1,90)
        }
        Light = !Light
        
        if(!holoEntity(4)){
            holoCreate(4)
        }
        if(!holoEntity(5)){
            holoCreate(5)
        }
        holoModel(4,"hqcylinder2") 
        holoMaterial(4,"cable/redlaser")
        holoPos(4,holoEntity(1):toWorld(vec(0,0,15)))
        holoAng(4,holoEntity(1):toWorld(ang(0,-90,0)))
        holoParent(4,1)
        holoColor(4,vec(255,255,255))
        
        #second side of laser
        holoModel(5,"hqcylinder2") 
        holoMaterial(5,"cable/redlaser")
        holoPos(5,holoEntity(1):toWorld(vec(0,0,15)))
        holoAng(5,holoEntity(1):toWorld(ang(0,90,0)))
        holoParent(5,1)
        holoColor(5,vec(255,255,255))
        holoScale(5,vec(0.1,0.1,2.5))
        holoSca
