@name iTorch E2
@inputs Light:wirelink
@outputs [E Me Fire]:entity [Weapon]:string Players:array
@outputs OnFire Ignite M1 M2 Use Holding Place Active Mounted
@model models/Gibs/furniture_gibs/FurnitureDrawer002a_gib05.mdl
interval(150)
if(first()|duped())
{
    E=entity()
    Me=owner()
    holoCreate(1)
    holoAlpha(1,0)
    holoScale(1,vec(0.3,0.3,0.3))
    holoCreate(2)
    holoAlpha(2,0)
    holoScale(2,vec(0.3,0.3,0.3))
    holoCreate(3)
    holoModel(3,"models/Gibs/furniture_gibs/FurnitureDrawer002a_gib05.mdl")
    holoAlpha(3,0)
    holoPos(1,E:toWorld(vec(0,0,15)))
    holoParent(1,E)
    #ifdef particle(S,E)
        particle("portal_2_projectile_ball",holoEntity(1))
    #else
        print("You dont have the E2 particle Extention. The torch will still work, but it wont be as fun....")
    #endif
    E:soundPlay(1,0,"ambient/fire/fire_small1.wav")
    E:soundPlay(2,0,"ambient/fire/mtov_flame2.wav")
    Weapon="weapon_crowbar"
    Light:entity():propNotSolid(1)
    Light:entity():setPos(holoEntity(1):pos())
    Light:entity():setAng(holoEntity(1):angles())
    Light:entity():setAlpha(0)
    Light:entity():parentTo(E)
    OnFire=1
}

Use=Me:keyUse()
M1=Me:keyAttack1()
M2=Me:keyAttack2()
Dist=Me:pos():distance(E:pos())
if(Me&Me:weapon():type()==Weapon&Me:pos():distance(E:pos())<=100)
{Active=1}else{Active=0}

if(Active)
{    
    holoPos(2,Me:attachmentPos("anim_attachment_RH"))
    holoAng(2,Me:attachmentAng("anim_attachment_RH"))
    holoParentAttachment(2,Me,"anim_attachment_RH")
    if(changed(Use)&Use&Me:aimEntity()==E&Dist<=100)
    {
        E:setPos(holoEntity(2):toWorld(vec(0,0,10)))
        E:setAng(holoEntity(2):toWorld(ang(0,0,0)))
        Me:weapon():setAlpha(0)
        E:propNotSolid(1)
        E:propFreeze(1)
        Holding=1
        Mounted=0
        timer("hold",300)
    }
    if(clk("hold"))
    {
        E:parentTo(holoEntity(2))
    }
    if(Holding&Me:eyeTrace():distance()<=200&Me:eyeTrace():hitNormal()!=vec(0,0,-1)&!Me:aimEntity())
    {
        holoAlpha(3,100)
        if(Me:eyeTrace():hitNormal()!=vec(0,0,1))
        {
            holoPos(3,Me:aimPos()+Me:eyeTrace():hitNormal()*5)
            holoAng(3,angnorm(Me:eyeTrace():hitNormal():toAngle()+ang(15,0,0)))
            Wall=1
        }
        if(Me:eyeTrace():hitNormal():dot(vec(0,0,1)) > 0.8)
        {
            holoPos(3,Me:aimPos()+Me:eyeTrace():hitNormal()*(E:boxSize():length()-20))
            holoAng(3,angnorm(Me:eyeTrace():hitNormal():toAngle()+ang(90,0,0)))
            Wall=0
        }   
        if(changed(M2)&M2)
        {
            E:deparent()
            E:propNotSolid(0)
            E:setPos(holoEntity(3):toWorld(vec()))
            E:setAng(holoEntity(3):toWorld(ang()))
            Holding=0 
            Active=0
            Place=1
            Mounted=1
        }
    }else
    {
        holoAlpha(3,0)
    }
    
}elseif(!Active)
{
    holoAlpha(3,0)
    E:deparent()
    Holding=0
    Me:weapon():setAlpha(255)
    if(OnFire)
    {
        findIncludeClass("player")
        findInSphere(E:pos(),100)
        findSortByDistance(E:pos())
        Me=findResult(1)
    }
}
if(changed(Holding)&Holding&Place)
{
    Place=0
}elseif(changed(Holding)&!Holding&!Place&!Mounted)
{
    E:propFreeze(0)
    E:propNotSolid(0)
    E:setPos(Me:toWorld(vec(50,0,50)))
}


if(OnFire)
{   
    Light["GlowSize",number]=1300
    Light["RGB",vector]=vec(255,126,0)*abs((50+randint(1,50))/100)
    Light["GlowBritness",number]=5
}
if(changed(E:isUnderWater())&E:isUnderWater()&OnFire)
{
    OnFire=0
    Light["RGB",vector]=vec()
    holoDelete(1)
    soundPurge()
    E:soundPlay(2,0.6,"misc/hologram_start.wav")
}
if(!OnFire)
{
    findIncludeClass("prop_*")
    findInSphere(E:pos(),20)
    findSortByDistance(E:pos())
    Fire=findResult(1)
    if(Fire:isOnFire())
    {
        Ignite=1
    }else
    {
        Ignite=0
    }
}
if(changed(Ignite)&Ignite)
{
    OnFire=1
    E:soundPlay(2,0,"ambient/fire/mtov_flame2.wav")
    E:soundPlay(1,0,"ambient/fire/fire_small1.wav")
    holoCreate(1)
    holoAlpha(1,0)
    holoPos(1,E:toWorld(vec(0,0,15)))
    holoParent(1,E)
    #ifdef particle(S,E)
        particle("portal_2_projectile_ball",holoEntity(1))
    #endif
}
#Credits: Someguynamedpie, Random, Zoombah
