@name Gabenizer
@inputs 
@persist [E, O, Find]:entity X
@persist Hold Fuel 
@persist OutInc OutTime
@outputs
@model models/props_wasteland/laundry_washer001a.mdl

#models:
#Gaben: models/sprops/geometry/sphere_3.mdl (material models/alyx/emptool_glow)
#Input: models/sprops/geometry/sphere_24.mdl
#Fuel: models/props_junk/gascan001a.mdl

###########
#Main Code#
###########
if ( first() || dupefinished() )
{
    runOnTick(1)
    E = entity()
    O = owner()
    
    Fuel=0
    
    # Holo Stuff
    I = 1
    holoCreate(I)
    holoModel(I, "hq_cylinder")
    holoPos(I, E:toWorld(vec(50,0,-33)))
    holoAng(I, E:toWorld(ang(0,0,0)))
    holoParent(I,E)
    holoScaleUnits(I, vec(10,10,0.1))
    holoColor( I,vec(255,0,0) )
    
    timer("",1000)
}
elseif ( clk("") )
{
    timer("",1000)
    X++
    
    findIncludeModel("models/props_junk/gascan001a.mdl")
    findIncludeModel("models/sprops/geometry/sphere_24.mdl")
    findInSphere(E:pos(),75)
    findAllowPlayerProps(O)
    findSortByDistance(E:pos())
    Find = find()
    #print(findToArray())
    if ( Find:isValid() && Find:model()=="models/props_junk/gascan001a.mdl" ) 
    { 
        if ( Find["gaben",number] )
        {
            Find:propDelete()
            if ( Fuel+25>100 ) { Fuel=100 } else { Fuel+=10 }
        }
        else
        {
            E:soundPlay(3,3,"buttons/button8.wav")
            Find:propBreak()    
        }
    }
    if ( Find:model()=="models/sprops/geometry/sphere_24.mdl" && Hold<15 )
    {
        Find:propDelete()
        Hold++
        if ( Hold>=15 )
        {
            OutInc=0
            OutTime=60    
        }            
    }
    
    # Increment/decrement values
    if ( mod(X,2)==0 && Fuel > 0 && Hold>=15 ) { Fuel-- }
    
    if ( Hold >= 15 && Fuel>0 ) # per second
    {
        OutInc++
        if ( OutInc >= OutTime ) 
        {
            Out=propSpawn("models/sprops/geometry/sphere_3.mdl",E:toWorld(vec(50,0,0)),ang(0),0)
            Out:setMaterial("models/alyx/emptool_glow")
            Out["oretype",number]=4 #1: autism 2: gmodite 3: sourcism 4: Gaben
            OutInc=0
            OutTime=60
            
            Hold=0      
        }           
    }
    
    #Update name
    setName( "Gabenizer - "+Hold+"/15 mixed elements - Fuel: "+Fuel+"%" )
    
    if ( changed(Fuel>0 && Hold==15) && Fuel>0 && Hold==15 ) 
    {
        E:soundPlay(1,0,"ambient/machines/electrical_hum_2.wav")    
    }
    elseif ( changed(!(Fuel>0 && Hold==15)) && !(Fuel>0 && Hold==15) ) { soundStop(1) } 
}
