@name Wand
@outputs DEBUG
@persist O:entity Command:string Side:string EYE_ANG:angle APARATION CMD:string Ball:array A_AP AP_Timer M13_ALT AP_TYPE:string ProtegoSize AP_TIMER_STOP M13_SPACE AP_TIMER AP_X AP_Y P_Timer AP_Z M13 M13_W M13_A M13_S M13_D TIMER_AV X_AV Y_AV M11 M12 Man11 LV_Timer LV_X LV_Y LV_DIST_ENT Wand LMTime LV_V:vector Sk10 LMent:entity M8 M9 M10 LeveDist LeveEntity:entity LMentGo:entity M7 VAI:vector TimerAIM Man10 Target:entity AutoAIM_AT:entity AutoAIM:entity BlockPT LMPos:vector Timer VectorLM:vector LvL LvLMax Rank LvLT:string LvLProgress WandGet ShowXpTitle AvadaEnd Sk1_h Sk2_h Sk3_h Sk7_h Sk8_h Sk9_h Cof Sk1 Sk2 Sk3 Sk4 Sk5 Sk6 Sk7 Sk8 Man9 Man1 Man2 Man3 Man4 Man5 Man6 Man7 Man8 ShAlpha ProRand VFX:string PmaxPos:vector V:vector PmaxT PmaxA ProSound:string Sh2Holo Protego:entity OWT:string Mana ManaMax ShSound:string M1 M2 M3 MaxRate M4 M5 M6 Rand Change Avada:entity Shiled:entity AimEnt:entity Prop:array Pulso:array Time:array Mode Index Weapon:string R G B ShA ShStop
@persist R_AP G_AP B_AP OH OH2 OG Man12 Impedimenta:array TIMER_IMP_1 TIMER_IMP_2 IMP_ENTITY:entity M14 GRAV_SPRITE:entity PROTEGO_SPRITE:array
@persist SPRITE_EXP:array SPRITE_ACTION:array 
#=============================
timer("hp",1000)
#if(clk("hp")) {owner():setHealth(owner():health() + 100)}
if(first()){ Change=1 Mode=1 Index=0
Weapon="weapon_stunstick"
Cof=150
fileLoad("wand_lvl.txt")
LvLMax=20
ShowXpTitle=1
CMD="rank"
Wand=1
MaxRate=21
ManaMax=1001
Sk9_h=ManaMax
ManaMax=ManaMax+(LvL*200)
Mana=ManaMax
R=0 G=180 B=255
Side="good"
Prop = array()
Pulso = array()
Time = array()
Man1=5
Man2=10
Man3=40
Man4=75
Man5=400
Man6=1000
Man7=1
Man8=0.3
Man9=25
Man10=500
Man11=1
Man12=150
FirstLoad=1
if(LvL>=LvLMax){LvLProgress = 100}
#======================================================
findExcludeModel("hqsphere2")
findExcludeEntity(holoEntity(3))
findExcludeModel("sprites/light_glow02")
findExcludeModel("models/XQM/Rails/trackball_1.mdl")
findExcludePlayer(owner())
findExcludeClass("sprite")
findExcludeClass("gmod_*")
findExcludeClass("sent_*")
findExcludeClass("light")
findExcludeClass("vehicle")   
#======================================================

#entitySpawn(Weapon,owner():shootPos(),1)
runOnTick(1)
#runOnKey(1)
runOnFile(1) 
#e2pPassword(e2pGetPassword())
hint("Wand Chip - by men232",7)
hint("v.1.9.8 RC",7)}
#=============================
if(!LvL) {
if(fileClk("wand_lvl.txt")) {   
LvL=fileRead():toNumber()
if(LvL<=0){fileWrite("wand_lvl.txt","1") LvL=1}    
} else {exit()}
if(LvL>=LvLMax){LvL = LvLMax fileWrite("wand_lvl.txt",toString(LvL))}
if(LvL>=LvLMax){LvLProgress=100}
}
#=============================
#if(WandGet&O:isAlive()){LvL_RS=LvLProgress=LvLProgress-25 print("XP Down("+-25+")") #entitySpawn(Weapon,owner():shootPos(),1) WandGet=0}
if(LvLProgress<0){LvL=LvL-1 LvLProgress=100+LvL_RS CMD="rank" print("LvL Down("+LvL+")") fileWrite("wand_lvl.txt",toString(LvL))}
V=owner():pos()+vec(0,0,65)-(-owner():eye()*Cof)
O=owner()
Command=owner():lastSaid()
M1=O:keyUse()
M2=O:keyAttack2()
M3=O:keyAttack1()
M4=O:keyReload()
M5=keyPress("Walk")
M6=O:keyUse()
M7=clKeyPress(17)
M8=clKeyPress(18)
M9=clKeyPress(90)
M10=clKeyPress(88)
M11=clKeyPress(91)
M12=clKeyPress(89)
M13=clKeyPress(79) M13_W=clKeyPress(33) M13_A=clKeyPress(11) M13_S=clKeyPress(29) M13_D=clKeyPress(14) M13_SPACE=clKeyPress(65) M13_ALT=clKeyPress(81) 
M14=clKeyPress(20)
PEP=O:aimPos()
AimEnt=O:aimEntity()
OWT=O:weapon():type()
EYE_ANG=O:eyeAngles()



#[LvL Systeam]#
if(LvL<LvLMax)
{
if(LvLProgress>=100){O:effectSpawn("VortDispel",O:pos(),10) LvL=LvL+1 print("New LvL "+LvL) LvLProgress=0 ManaMax=ManaMax+(LvL*200) Mana=ManaMax-1 CMD="rank"}
}

#=============================
if(O:lastSaid()=="!good"){Side="good"}
if(O:lastSaid()=="!evil"){Side="evil"}

if(O:lastSaid()=="!showxp"){ShowXpTitle=1}
if(O:lastSaid()=="!hidexp"){ShowXpTitle=0}

if(Side=="good"){R=0 G=180 B=255 R_AP = 255 G_AP = 255 B_AP = 255 Sk1=50-LvL  Sk2=2.5+(LvL/10) Sk3=75+(LvL*2) Sk4=8 Sk5=0 Sk7=2+(LvL*2) Sk8=0.2+(LvL/100) Sk10=0.5*LvL}
if(Side=="evil"){R=255 G=0 B=0   R_AP = 0   G_AP = 0   B_AP = 0   Sk1=70-LvL  Sk2=2.5+(LvL/10) Sk3=50+(LvL*2) Sk4=9 Sk5=1 Sk7=3+(LvL*2) Sk8=0.2+(LvL/100) Sk10=0.5*LvL}

if(Side=="good"){Sk1_h=50  Sk2_h=2.5 Sk3_h=75 Sk7_h=2 Sk8_h=0.2}
if(Side=="evil"){Sk1_h=70  Sk2_h=2.5 Sk3_h=50 Sk7_h=3 Sk8_h=0.2}

if(CMD=="rank")
{
    ManaMax=1001
    ManaMax=ManaMax+(LvL*200)
    Mana=ManaMax
    hint("Expulso speed: +"+(Sk1_h-Sk1),7)
    hint("Incendio power: +"+(Sk2-Sk2_h),7)
    hint("Freeze time: +"+(Sk3-Sk3_h),7)
    hint("Expelliarmus power: +"+(Sk7-Sk7_h),7)
    hint("Mana speed: +"+(Sk8-Sk8_h),7)
    hint("Mana: +"+(ManaMax-Sk9_h),7)
    hint("Lumus max time: +"+(100*LvL),7)
    hint("Auto AIM: +"+(Sk10),7)
    hint("Apparition: +"+(5*LvL),7)
    fileWrite("wand_lvl.txt",toString(LvL))
    CMD="done"
}
#=============================
if(OWT==Weapon){
#=======================================
# Mode1
if(M3&$M3 & Mode==1 & BlockPT & Mana-Man1>0)
{
    Mana=Mana-Man1
    Pulso[Pulso:count()+1,entity]=E=propSpawn("models/weapons/hunter_flechette.mdl",V,EYE_ANG,0)
    if(E!=noentity()){E:drawSprite("sprites/light_glow02",E:pos(),vec(R,G,B),255,50,50)}
    #E:setAlpha(0)
    E:setMass(4)
    E:propGravity(0)
    E:setdLight(E:pos(),vec(R,G,B),5,150,0)
    E:setTrails(15,0.01,1,"trails/laser",vec(R,G,B),255)
    Pos=owner():pos()+vec(0,0,65)-(-owner():eye()*1000000)
    E:setVel(Pos)
    E:applyAngForce(ang(0,0,2000))
}

# Mode5
if(M3 & Mode==5 & BlockPT & Mana-Man2>0)
{
    if($M3&M3){P_Timer = 100}else{P_Timer++}
    if(P_Timer >= (Sk1/2))
    {
    Mana=Mana-Man2
    Rand=Rand+3
    Pulso[Pulso:count()+1,entity]=E=propSpawn("models/weapons/hunter_flechette.mdl",V,EYE_ANG,0)
    if(E!=noentity()){E:drawSprite("sprites/light_glow02",E:pos(),vec(R,G,B),255,50,50)}
    E:setMass(4)
    E:propGravity(0)
    E:setdLight(E:pos(),vec(R,G,B),5,150,0)
    E:setTrails(15,0.01,1,"trails/laser",vec(R,G,B),255)
    Pos=owner():pos()+vec(0,0,65)-(-owner():eye()*1000000)
    Alt_V = vec(5000,5000,5000)
    Alt_Pos = randvec(Alt_V, -Alt_V)
    E:setVel(Pos + Alt_Pos)
    E:applyAngForce(ang(0,0,2000))
    P_Timer = 0
    }
}else{runOnTick(1) Rand=0 P_Timer = 0}

# Mode2
if(M3&$M3 & Mode==2 & BlockPT & Mana-Man3>0)
{
Mana=Mana-Man3
Pulso[Pulso:count()+1,entity]=E=propSpawn("models/props_phx/misc/potato_launcher_explosive.mdl",V,0)
if(Sk5){E:ignite(99999999)}
E:setAlpha(0)
E:setMass(2+Sk2)
E:propGravity(0)
E:setdLight(E:pos(),vec(255,100,0),5,500,0)
if(E!=noentity()){E:drawSprite("sprites/light_glow02",E:pos(),vec(255,100,0),255,80,80)}
E:setTrails(40,0.01,1,"trails/laser",vec(255,100,0),255)
Pos=owner():pos()+vec(0,0,65)-(-owner():eye()*1000000)
E:setVel(Pos)
E:applyAngForce(ang(0,0,0.5))
}

# Mode3
if(M3&$M3 & Mode==3 & BlockPT & Mana-Man4>0)
{
Mana=Mana-Man4
O:effectSpawn("ToolTracer",O:attachmentPos("anim_attachment_RH"),PEP,vec(0,0,0),1)
effectSpawn("cball_explode",PEP,1)

if(AimEnt:isPlayer() | AimEnt:isNPC())
{
    AimEnt:weapon():remove()
    ES_POS = (((O:shootPos() - AimEnt:shootPos()):normalized())*100)+AimEnt:shootPos()
    ES=entitySpawn(AimEnt:weapon():type(),ES_POS,0)
    ES:propFreeze(1) ES:propFreeze(0)
    ES:setVel((O:shootPos()-ES:pos()))
}else
{
    AimPos = AimEnt:pos() - O:pos()
    if(M13_ALT){AimPos = -AimPos}
    AimEnt:setVel((AimPos:normalized()*4000)*Sk7)
    SPRITE_ACTION[SPRITE_ACTION:count()+1, entity] = drawSprite("sprites/light_glow02",PEP,vec(0,180,255),255,300,200)   
}
}

# Mode4
if(M3&$M3 & Mode==4 & BlockPT & Mana-Man5>0)
{
Mana=Mana-Man5
effectSpawn("GlassImpact",PEP,10)

AimEnt:soundPlay(0,1000,"physics/glass/glass_strain2.wav")
if(AimEnt!=noentity()){
AimEnt:effectSpawn("entity_remove",owner():pos(),10)
Prop[Prop:count()+1,entity]=AimEnt
Time[Prop:count(),number]=10+Sk3

AimEnt:setdLight(AimEnt:pos(),vec(random(255),255,255),50,10,0)
}
}

#Mode7
if(Mode==7 & AimEnt & IMP_ENTITY!=AimEnt){if(AimEnt:isPlayer() | AimEnt:isNPC()){IMP_ENTITY=AimEnt print("Target ("+IMP_ENTITY:name()+")")}}
if($M3&M3 & Mode==7 & BlockPT & Mana-Man12>0 & Impedimenta:count()==0)
{
    Mana=Mana-Man12
    Pulso[Pulso:count()+1,entity]=Impedimenta[1,entity]=propSpawn("models/props_phx/misc/potato_launcher_explosive.mdl",V,EYE_ANG,0)
    Pulso[Pulso:count()+1,entity]=Impedimenta[2,entity]=propSpawn("models/props_phx/misc/potato_launcher_explosive.mdl",V,EYE_ANG,0)
    
    Pulso[Pulso:count()+1,entity]=Impedimenta[3,entity]=propSpawn("models/props_phx/misc/potato_launcher_explosive.mdl",V,EYE_ANG,0)
    Pulso[Pulso:count()+1,entity]=Impedimenta[4,entity]=propSpawn("models/props_phx/misc/potato_launcher_explosive.mdl",V,EYE_ANG,0)
    
    Impedimenta[1,entity]:noCollide(Impedimenta[2,entity]) Impedimenta[1,entity]:noCollide(Impedimenta[3,entity]) Impedimenta[1,entity]:noCollide(Impedimenta[4,entity])
    Impedimenta[2,entity]:noCollide(Impedimenta[1,entity]) Impedimenta[2,entity]:noCollide(Impedimenta[3,entity]) Impedimenta[2,entity]:noCollide(Impedimenta[4,entity])
    Impedimenta[3,entity]:noCollide(Impedimenta[1,entity]) Impedimenta[3,entity]:noCollide(Impedimenta[2,entity]) Impedimenta[3,entity]:noCollide(Impedimenta[4,entity])
    Impedimenta[4,entity]:noCollide(Impedimenta[1,entity]) Impedimenta[4,entity]:noCollide(Impedimenta[2,entity]) Impedimenta[4,entity]:noCollide(Impedimenta[3,entity])
    
    for(I=1,4)
    {
    Impedimenta[I,entity]:setTrails(15,0.01,1,"trails/laser",vec(255,100,0),255)
    if(Side=="evil"){Impedimenta[I,entity]:ignite(99999999)}
    Impedimenta[I,entity]:setAlpha(0)
    Impedimenta[I,entity]:propGravity(0)
    Impedimenta[I,entity]:setMass(2+Sk2)
    Impedimenta[I,entity]:setdLight(Impedimenta[1,entity]:pos(),vec(255,100,0),5,500,0)
    if(Impedimenta[I,entity]!=noentity()){Impedimenta[I,entity]:drawSprite("sprites/light_glow02",Impedimenta[I,entity]:pos(),vec(255,100,0),255,80,80)}
    Pos=owner():pos()+vec(0,0,65)-(-owner():eye()*1000000)
    Impedimenta[I,entity]:setVel(Pos)
    } 
    TIMER_IMP_1=3 TIMER_IMP_2=5
}

if(Impedimenta[1,entity]!=noentity() | Impedimenta[2,entity]!=noentity() | Impedimenta[3,entity]!=noentity() | Impedimenta[4,entity]!=noentity())
{

    TIMER_IMP_1 = TIMER_IMP_1 - 0.1
    TIMER_IMP_2 = TIMER_IMP_2 - 0.1
    
    if(TIMER_IMP_1==0 & IMP_ENTITY!=noentity())
    {
        Pos=Impedimenta[1,entity]:right()-Impedimenta[1,entity]:forward()-Impedimenta[1,entity]:up()
        Impedimenta[1,entity]:setVel(-Pos*1000000)
        
        Pos=Impedimenta[2,entity]:right()+Impedimenta[2,entity]:forward()+Impedimenta[2,entity]:up()  
        Impedimenta[2,entity]:setVel(Pos*1000000)
        
        Pos=Impedimenta[3,entity]:right()-Impedimenta[3,entity]:forward()  
        Impedimenta[3,entity]:setVel(-Pos*1000000)
        
        Pos=Impedimenta[4,entity]:right()+Impedimenta[4,entity]:forward()
        Impedimenta[4,entity]:setVel(Pos*1000000)            
    }
    if(TIMER_IMP_2<0 & IMP_ENTITY!=noentity())
    {     
        for(I=1,4)
        {
            Pos1=IMP_ENTITY:pos()-Impedimenta[I,entity]:pos()
            Impedimenta[I,entity]:setVel(Pos1*50)
        }
        
        if(TIMER_IMP_2<-5*LvL){for(I=1, 4){Impedimenta[I,entity]:propBreak() Impedimenta:remove(I)}}
    }
}else{TIMER_IMP_1=0 TIMER_IMP_2=0 Impedimenta:remove(1) Impedimenta:remove(2) Impedimenta:remove(3) Impedimenta:remove(4) if(!IMP_ENTITY:isAlive()){IMP_ENTITY=noentity()}}

# AUTO AIM
if(M7&$M7 & BlockPT & Mana-Man10>0 & AimEnt:isPlayer())
{
    if(AutoAIM==noentity())
    {
        AutoAIM=holoCreate(13)
        Mana=Mana-Man10
        findExcludeEntity(AutoAIM)
        AutoAIM:propNotSolid(1)
        AutoAIM:setAlpha(0)
        AutoAIM:setTrails(3,0.01,1,"trails/laser",vec(255,255,0),255)
        AutoAIM:drawSprite("sprites/light_glow02",AutoAIM:pos(),vec(255,255,0),255,35,35)
        AutoAIM_AT = AimEnt
        TimerAIM = Man10
    }
}

if(AutoAIM & TimerAIM > 0)
{
    holoPos(13, AutoAIM_AT:pos()+vec(0,0,100))
    TimerAIM = TimerAIM - 0.1
    
    if( TimerAIM <= 0 )
    {
        holoDelete(13)
        AutoAIM = noentity()        
    } 
}

# Mode8
if($M3 & Mode==8 & BlockPT & Mana-Man6>0)
{
    if(AvadaEnd==0){
    Mana=Mana-Man6
    TIMER_AV = 0
    AvadaEnd=1
    Avada=propSpawn("models/XQM/Rails/trackball_1.mdl",V,0)
    Avada:noCollideAll(1)
    if(Avada!=noentity()){Avada:drawSprite("sprites/light_glow02",Avada:pos(),vec(0,255,0),255,150,150)}
    #--
    Avada:soundPlay(0,1000,"ambient/outro/lowercitadelexplosiongroup.wav")
    Avada:setAlpha(0)
    Avada:setMass(99999999999)
    Avada:setdLight(Avada:pos(),vec(0,255,0),5,500,0)
    Avada:setTrails(40,0.01,1,"trails/laser",vec(0,255,0),255)
    Avada:propGravity(0)
    Pos=owner():pos()+vec(0,0,65)-(-owner():eye()*1000000)
    Avada:setVel(Pos)
    Avada:applyAngForce(ang(0,0,10000))
    
    holoCreate(300, Avada:pos()) holoParent(300, Avada) holoAlpha(300, 0)
    holoCreate(301, Avada:pos()) holoParent(301, Avada) holoAlpha(301, 0)
    
    holoEntity(300):setTrails(10,0.01,1,"trails/laser",vec(0,255,0),255)
    holoEntity(301):setTrails(10,0.01,1,"trails/laser",vec(0,255,0),255)
    
    holoEntity(300):drawSprite("sprites/light_glow02",holoEntity(300):pos(),vec(0,255,0),255,15,15)
    holoEntity(301):drawSprite("sprites/light_glow02",holoEntity(301):pos(),vec(0,255,0),255,15,15)  
    }
}

if(Avada:vel():length()<1000)
{
    Avada:propBreak()
    AvadaEnd=0
    if(Avada){effectSpawn("Explosion",Avada:pos()+vec(0,0,10),1) holoDelete(3) holoDelete(300) holoDelete(301)}
}

    if(Avada)
{
    Avada:effectSpawn("VortDispel",Avada:pos(),10)
    Avada:effectSpawn("TeslaHitboxes",Avada:pos(),2)
    
    #--
    TIMER_AV = TIMER_AV + 0.05
    X_AV=(sinr(TIMER_AV))*50
    Y_AV=(cosr(TIMER_AV))*50
    
    holoPos(300, Avada:pos()+vec(X_AV, Y_AV, Y_AV))
    holoPos(301, Avada:pos()+vec(-X_AV, -Y_AV, -Y_AV))  
    #---

    findInSphere(Avada:pos(),100)
    #--
    C=findToArray()
    
    for(I=0,C:count())
    {
        E1=C:entity(I)
        E1:effectSpawn("TeslaHitboxes",E1:pos(),2)
        if(E1:isPlayer() | E1:isNPC()){E1:takeDamage(9999999999999999999999999,noentity(),owner())}
        else{
        F=E1:pos()-Avada:pos()
        E1:setVel(F*10) }   
    }
    #--
}

for(I=1, Prop:count())
{
    if(Prop[I,entity]==noentity()){Prop:remove(I) Time:remove(I)}else{
    Time[I,number]=Time[I,number]-0.1
    if(Time[I,number]<=0){
        Prop[I,entity]:setColor(255,255,255) if(Prop[I,entity]:weapon()){Prop[I,entity]:weapon():setColor(255,255,255)}
        Prop[I,entity]:propFreeze(0)
        Prop[I,entity]:playerUnFreeze()
        Prop[I,entity]:effectSpawn("GlassImpact",Prop[I,entity]:pos(),10)

        Prop[I,entity]:soundPlay(0,1000,"physics/glass/glass_pottery_break4.wav")
        Prop[I,entity]:dLightRemove()
        Time:remove(I)
        Prop:remove(I)}
        else{
        Prop[I,entity]:setColor(0,150,255) if(Prop[I,entity]:weapon()){Prop[I,entity]:weapon():setColor(0,150,255)}
        Prop[I,entity]:propFreeze(1)
        Prop[I,entity]:playerFreeze()}
        }
}

for(I=1, Pulso:count())
{
    if(Pulso[I,entity]==noentity()){Pulso:remove(I)}
    if(Pulso[I,entity]:vel():length()<1000)
    {
        if(Pulso[I,entity]!=noentity()){effectSpawn("cball_explode",Pulso[I,entity]:pos(),1)}
        if(Pulso[I,entity]:model()=="models/weapons/hunter_flechette.mdl")
        {SPRITE_EXP[SPRITE_EXP:count()+1,entity]=drawSprite("sprites/light_glow01",Pulso[I,entity]:pos(),vec(R,G,B),255,200,200)}
        Pulso[I,entity]:propBreak()
        Pulso:remove(I)
    }
    else
    {
        if(AutoAIM & M7)
        {
            AIMPOST = AutoAIM:pos()-vec(0,0,50) - Pulso[I,entity]:pos()
            Pulso[I,entity]:applyForce(AIMPOST / (11 - Sk10))
            if(Pulso[I,entity]:model() == "models/props_phx/misc/potato_launcher_explosive.mdl")
            {
                if(floor(Pulso[I,entity]:pos():distance(AutoAIM:pos()-vec(0,0,50))) < 50){Pulso[I,entity]:propBreak()}                
            }
            Mana = Mana - 0.1                           
        }
    }
}

for(I=1, SPRITE_EXP:count())
{
    SPRITE_ENT = SPRITE_EXP[I,entity]
    SPRITE_ALPHA = SPRITE_ENT:getAlpha()
    SPRITE_ALPHA -=5
    SPRITE_ENT:setAlpha(SPRITE_ALPHA)
    if(SPRITE_ALPHA<=0){SPRITE_ENT:remove() SPRITE_EXP:remove(I)}    
}

# LEVETATION
if($M8&M8)
{
    LeveEntity = AimEnt
    LeveDist = floor(LeveEntity:pos():distance(O:pos()))
    holoCreate(100, LeveEntity:pos()) holoParent(100, LeveEntity) holoAlpha(100, 0)
    holoCreate(101, LeveEntity:pos()) holoParent(101, LeveEntity) holoAlpha(101, 0)
    
    holoEntity(100):drawSprite("sprites/light_glow02",holoEntity(100):pos(),vec(R,G,B),255,15,15)
    holoEntity(101):drawSprite("sprites/light_glow02",holoEntity(101):pos(),vec(R,G,B),255,15,15)
    
    holoEntity(100):setTrails(5,0.01,1,"trails/laser",vec(R,G,B),255)
    holoEntity(101):setTrails(5,0.01,1,"trails/laser",vec(R,G,B),255)
    
    LV_Timer = 0   
}

LV_DIST_ENT = floor(LeveEntity:pos():distance(O:pos()))

if(M8&LeveEntity!=noentity() & LV_DIST_ENT < (100 * LvL))
{
    if(LeveEntity:isPlayer() | LeveEntity:isNPC()){LV_MIN = LeveEntity:vel()}
    if(!GRAV_SPRITE){GRAV_SPRITE = drawSprite("sprites/light_glow02",LeveEntity:pos(),vec(R,G,B),0,LeveEntity:radius()*4,LeveEntity:radius()*4)}
    if(GRAV_SPRITE:getAlpha()<255){GRAV_SPRITE:setAlpha(GRAV_SPRITE:getAlpha()+5)}
    Point = (owner():shootPos()+owner():eye()*LeveDist)-LV_MIN
    LV_V = ((Point-LeveEntity:pos()))
    if(LeveEntity:inNoclip()){LeveEntity:playerNoclipOff()}
    LeveEntity:setVel(LV_V)
    Mana = Mana - 0.5
    BlockPT=0
    
    ParVec=vec(LeveEntity:radius(),LeveEntity:radius(),LeveEntity:radius())
    ParPos=O:attachmentPos("anim_attachment_RH")+randvec( -vec(5,5,5), vec(5,5,5))
    ArtPos=LeveEntity:pos()+vec(0,0,20)+randvec( -ParVec, ParVec)
    particleGravity(vec(0,0,0))
    particle((ArtPos-ParPos):length()/300,1,1,"sprites/light_ignorez",vec(R,G,B),ParPos,(ArtPos-ParPos):normalized()*300 ) 
    
    if(M10){LeveDist = LeveDist + 5}
    if(M9){LeveDist = LeveDist - 5}
    if(M12){LeveEntity:setAng(LeveEntity:angles()+ang(0,2,0))}
    if(M11){LeveEntity:setAng(LeveEntity:angles()-ang(0,2,0))}
    
}else
{
    if(GRAV_SPRITE)
    {
        GRAV_ALPHA = GRAV_SPRITE:getAlpha()
        GRAV_ALPHA -=5
        GRAV_SPRITE:setAlpha(GRAV_ALPHA)
        if(GRAV_ALPHA<1)
        {
            GRAV_SPRITE:remove()
            LeveEntity = noentity()
        }
        holoDelete(100)
        holoDelete(101)
    }
}

if(LeveEntity!=noentity())
{
    LV_Timer = LV_Timer + 0.1
    LV_X=(sinr(LV_Timer))*LeveEntity:radius()
    LV_Y=(cosr(LV_Timer))*LeveEntity:radius()
        
    holoPos(100, LeveEntity:pos()+vec(LV_X, LV_Y, 0))
    holoPos(101, LeveEntity:pos()+vec(-LV_X, -LV_Y, 0))   
    if(!LeveEntity:isAlive()){GRAV_V = LeveEntity:pos()}
    if(LeveEntity:isAlive()){GRAV_V = LeveEntity:pos()+vec(0,0,LeveEntity:height()/2)}
    GRAV_SPRITE:setPos(GRAV_V)       
}

# Protego
if(M2&Mana-Man7>0&Mana-50>0)
{
BlockPT=0
findInSphere(O:pos(),200)
A=findToArray()

for(I=1,A:count())
{
    ProRand=randint(1,14)
    if(ProRand<10){ProSound="weapons/fx/nearmiss/bulletltor0"+ProRand+".wav"}
    if(ProRand>10){ProSound="weapons/fx/nearmiss/bulletltor"+ProRand+".wav"}
    
    E:setMass(E:mass()+1)
    E=A[I, entity]
    if(E:mass()!=0 | E:isAlive())
    {
        if(E:isAlive()){SP_POS = E:pos()+vec(0,0,E:height()/2)}else{SP_POS = E:pos()}
        if(!PROTEGO_SPRITE[I, entity]:isValid() & PROTEGO_SPRITE:count() < 8 & PROTEGO_SPRITE[I, entity]:getVarNum("ID_PROTEGO") != E:id())
        {
            PROTEGO_SPRITE[I, entity]:remove() PROTEGO_SPRITE:remove(I)
            PROTEGO_SPRITE[I, entity]:setVarNum("ID_PROTEGO", E:id())
            PROTEGO_SPRITE[PROTEGO_SPRITE:count()+1, entity] = E:drawSprite("sprites/light_glow02",SP_POS,vec(R,G,B),255,E:radius()*5,E:radius()*5)
        }
        if(E!=noentity()){E:soundPlay(0,1000,ProSound)}
        if(E:isAlive()& E!=O)

        {
            E:playerNoclipOff()
            FP=E:pos()-O:pos()
            E:setVel(FP*3)
        }
    
        if(!E:isAlive()){E:setVel(owner():eye()*E:mass()*1000)}
    
        if(A:count()!=0){Mana=Mana-Man7 ShAlpha=255}
    }
}
}else{holoDelete(2) BlockPT=1}
for(I=1,PROTEGO_SPRITE:count())
{
    E=PROTEGO_SPRITE:entity(I)
    E:setAlpha(E:getAlpha() - 10)
    if(E:getAlpha() < 1)
    {
        E:remove()
        PROTEGO_SPRITE:remove(I)
    }      
}

# Lumus
if(M6 & Mana-Man8>0)
{
    Mana=Mana-Man8
    if($M6)
    {
        holoCreate(1,O:attachmentPos("anim_attachment_RH"))
        holoEntity(1):soundPlay(1,1000,"buttons/lightswitch2.wav")
        holoEntity(1):setdLight(owner():pos(),vec(255,255,255),5,200,0)
        holoParent(1, O)
        holoEntity(1):setAlpha(0)
    }     
}
else{holoDelete(1) soundStop(1)}

# APARATION
if($M13&Mana-Man11>0&AP_TIMER==1)
{
    Mana=Mana-Man11
    holoCreate(600, O:pos()) holoParent(600, O) holoAlpha(600, 0)
    holoCreate(601, O:pos()) holoParent(601, O) holoAlpha(601, 0)
    holoCreate(602, O:pos()) holoParent(602, O) holoAlpha(602, 0)
    holoCreate(603, O:pos()) holoParent(603, O) holoAlpha(603, 0)
    holoCreate(604, O:pos()) holoParent(604, O) holoAlpha(604, 0)
    holoCreate(605, O:pos()) holoParent(605, O) holoAlpha(605, 0)
    holoCreate(606, O:pos()) holoParent(606, O) holoAlpha(606, 0)
    holoCreate(607, O:pos()) holoParent(607, O) holoAlpha(607, 0)
    holoCreate(608, O:pos()) holoParent(608, O) holoAlpha(608, 0)
    
    
    if(Side=="good"){AP_TYPE="trails/laser"}
    if(Side=="evil"){AP_TYPE="trails/smoke"}
    
    if(Side=="good"){
    holoEntity(600):drawSprite("sprites/light_glow02",holoEntity(600):pos(),vec(R_AP,G_AP,B_AP),255,15,15)
    holoEntity(601):drawSprite("sprites/light_glow02",holoEntity(601):pos(),vec(R_AP,G_AP,B_AP),255,15,15)
    holoEntity(602):drawSprite("sprites/light_glow02",holoEntity(602):pos(),vec(R_AP,G_AP,B_AP),255,15,15)
    holoEntity(603):drawSprite("sprites/light_glow02",holoEntity(603):pos(),vec(R_AP,G_AP,B_AP),255,15,15)
    holoEntity(604):drawSprite("sprites/light_glow02",holoEntity(604):pos(),vec(R_AP,G_AP,B_AP),255,15,15)
    holoEntity(605):drawSprite("sprites/light_glow02",holoEntity(605):pos(),vec(R_AP,G_AP,B_AP),255,15,15)
    holoEntity(606):drawSprite("sprites/light_glow02",holoEntity(606):pos(),vec(R_AP,G_AP,B_AP),255,15,15)
    holoEntity(607):drawSprite("sprites/light_glow02",holoEntity(607):pos(),vec(R_AP,G_AP,B_AP),255,15,15)
    holoEntity(608):drawSprite("sprites/light_glow02",holoEntity(608):pos(),vec(R_AP,G_AP,B_AP),255,15,15)}
    
    holoEntity(600):setTrails(5,0.01,1,AP_TYPE,vec(R_AP,G_AP,B_AP),255)
    holoEntity(601):setTrails(5,0.01,1,AP_TYPE,vec(R_AP,G_AP,B_AP),255)
    holoEntity(602):setTrails(5,0.01,1,AP_TYPE,vec(R_AP,G_AP,B_AP),255)
    holoEntity(603):setTrails(5,0.01,1,AP_TYPE,vec(R_AP,G_AP,B_AP),255)
    holoEntity(604):setTrails(5,0.01,1,AP_TYPE,vec(R_AP,G_AP,B_AP),255)
    holoEntity(605):setTrails(5,0.01,1,AP_TYPE,vec(R_AP,G_AP,B_AP),255)
    holoEntity(606):setTrails(5,0.01,1,AP_TYPE,vec(R_AP,G_AP,B_AP),255)
    holoEntity(607):setTrails(5,0.01,1,AP_TYPE,vec(R_AP,G_AP,B_AP),255)
    holoEntity(608):setTrails(5,0.01,1,AP_TYPE,vec(R_AP,G_AP,B_AP),255)
    
    APARATION = 1
    AP_TIMER = 0     
}
if(APARATION&!AP_TIMER)
{
O:setColor(0,0,0) O:weapon():setAlpha(0) O:setMaterial("Models/effects/vol_light001")

    AP_Timer = AP_Timer + 0.2
    AP_X=(sinr(AP_Timer))*50
    AP_Y=(cosr(AP_Timer))*50
    AP_Z=AP_Z+A_AP        
    if(AP_Z>50){A_AP=-0.5}
    if(AP_Z<1){A_AP=0.5}
    holoPos(600, O:pos()+vec(AP_X, AP_Y, AP_Z+randint(15,10)))
    holoPos(601, O:pos()+vec(-AP_Z, -AP_Y, AP_Y+randint(15,10)))
    holoPos(602, O:pos()+vec(-AP_X, -AP_Y, AP_Z+randint(15,10)))
    holoPos(603, O:pos()+vec(-AP_X, -AP_Z, AP_X+randint(15,10)))
    holoPos(604, O:pos()+vec(-AP_Z, -AP_Y, AP_X+randint(15,10)))
    holoPos(605, O:pos()+vec(-AP_X, -AP_Y, AP_Z+randint(15,10)))
    holoPos(606, O:pos()+vec(-AP_X, -AP_Y, AP_Y+randint(15,10)))
    holoPos(607, O:pos()+vec(-AP_Y, -AP_Z, AP_X+randint(15,10)))
    holoPos(608, O:pos()+vec(-AP_X, -AP_Y, AP_Z+randint(15,10)))
    
}

if(M13&Mana-Man11>0&!AP_TIMER&APARATION)
{
    Mana=Mana-Man11
    Vac_AP = vec()
    if(M13_D){Vac_AP=Vac_AP + O:right()}
    if(M13_A){Vac_AP=Vac_AP + (-O:right())}
    if(M13_S){Vac_AP=Vac_AP + (-O:forward())}
    if(M13_W){Vac_AP=Vac_AP + O:forward()}
    if(M13_SPACE){Vac_AP=Vac_AP + O:up()}

OH=O:health() OG=O:isOnGround()
if(changed(OG)&OG&OH<OH2){Del=OH2-OH owner():heal(Del)}
OH2=OH

    O:setVel(Vac_AP*(2*LvL))
    AP_TIMER_STOP=5
}
else{
    if(!AP_TIMER)
    {
    AP_Z=0
if(APARATION){
O:effectSpawn("WheelDust",owner():pos(),10) O:effectSpawn("WheelDust",owner():pos(),10)
O:effectSpawn("WheelDust",owner():pos(),10) O:effectSpawn("WheelDust",owner():pos(),10)}
O:weapon():setAlpha(255) O:setColor(255,255,255,255) O:setMaterial("BlaH")

    APARATION = 0
    AP_TIMER_STOP=AP_TIMER_STOP-0.1
    
    holoUnparent(600) holoUnparent(601) holoUnparent(602) holoUnparent(603) holoUnparent(604)
    holoUnparent(605) holoUnparent(606) holoUnparent(607) holoUnparent(608)
    }
    
    if(AP_TIMER_STOP<=0&!AP_TIMER)
    {
    AP_TIMER=1
    holoDelete(600) holoDelete(601) holoDelete(602)
    holoDelete(603) holoDelete(604) holoDelete(605)
    holoDelete(606) holoDelete(607) holoDelete(608)
}
}  

# Lumus Max
if($M3&Mode==6&Mana-Man9>0)
{
    if($M3&!LMent)
    {
        Mana=Mana-Man9
        LMTime=1000
        Timer=0
        if(O:aimEntity()){LMentGo=O:aimEntity()}else{LMPos=O:aimPos()}
        if(M5){LMentGo=O}
        LMent=propSpawn("models/Gibs/HGIBS.mdl",V,0)
        findExcludeEntity(LMent)
        LMent:propNotSolid(1)
        LMent:setAlpha(0)
        LMent:setTrails(10,0.01,1,"trails/laser",vec(255,255,255),255)
        LMent:propGravity(0)
        LMent:setdLight(LMent:pos(),vec(255,255,255),2,1000,0)
        LMent:drawSprite("sprites/light_glow02",LMent:pos(),vec(255,255,255),255,100,100)
    }   
}

if(LMent)
{
    Timer=Timer+0.003
    LM_X=(sinr(Timer))*100
    LM_Y=(cosr(Timer))*100
    if(LMentGo){LMPos=LMentGo:pos()}
    VectorLM = LMPos - LMent:pos()+vec(LM_X,LM_Y,100)
    LMent:applyForce($VectorLM*100+VectorLM)
}

LMTime=LMTime-(1.5/LvL) if(LMTime<=0){LMTime=0 LMent:remove() LMentGo=noentity()}else{LMent:dLightSize(LMTime)}

# Chenge Mode
if(M4&$M4){Change=Change+1
if(Change==Sk4){Change=1}

if(Change==1){print("Stupefy ("+ Man1+")") Mode=1}
if(Change==2){print("Incendio ("+ Man3+")") Mode=2}
if(Change==3){print("Expelliarmus ("+ Man4+")") Mode=3}
if(Change==4){print("Petrificus Totalus ("+ Man5+")") Mode=4}
if(Change==5){print("Expulso ("+ Man2+")") Mode=5}
if(Change==6){print("Lumus maxima ("+ Man9+")") Mode=6}
#if(Change==7){print("Auto AIM ("+ Man10+")") Mode=7}
if(Change==7){print("Impedimenta ("+ Man12+")") Mode=7}
if(Change==8){print("Avada Kedavra ("+ Man6+")") Mode=8}}
if(LvL<LvLMax&ShowXpTitle){LvLT=" | XP: %"+floor(LvLProgress)+" ("+LvL+")"}else{LvLT=""}
if(Mana<ManaMax){print(_HUD_PRINTCENTER , "Magic: "+floor(Mana)+LvLT)}
}else{holoDelete(0) holoDelete(1) holoDelete(2) holoDelete(5) Shiled:propBreak() Wand=1 LMent:remove() LMentGo=noentity()     holoDelete(600) holoDelete(601) holoDelete(602)
    holoDelete(603) holoDelete(604) holoDelete(605)
    holoDelete(606) holoDelete(607) holoDelete(608) AP_TIMER=1}
Mana=Mana+Sk8
if(Mana<0){Mana=0}
if(Mana>=ManaMax){Mana=ManaMax}else{LvLProgress=LvLProgress+0.05/LvL}
if(Pulso:count()>MaxRate){Pulso[1,entity]:propBreak() Pulso:shift() print("Magic Limit")}
if(Prop:count()>MaxRate){Prop[1,entity]:propBreak() Prop:shift() print("Magic Limit")}
if(Time:count()>MaxRate){Time:shift()}

if(!O:isAlive()){WandGet=1}

for(I=0, SPRITE_ACTION:count())
{
    E_ACTIO = SPRITE_ACTION[I, entity]
    E_ACTIO:setAlpha(E_ACTIO:getAlpha()-5)
    
    if(E_ACTIO:getAlpha()<1)
    {
        E_ACTIO:remove()
        SPRITE_ACTION:remove(I)
    }
}
