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

#models:
#Filtered Ore: models/sprops/geometry/sphere_24.mdl (coloured)
#Input: models/props/cs_militia/militiarock05.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") # autism
    holoPos(I, E:toWorld(vec(40,40,-27)))
    holoAng(I, E:toWorld(ang(0,0,0)))
    holoParent(I,E)
    holoScaleUnits(I, vec(10,10,0.1))
    holoColor( I,vec(255,255,0) ), I++
    
    holoCreate(I)
    holoModel(I, "hq_cylinder") 
    holoPos(I, E:toWorld(vec(0,40,-27))) # gmodite
    holoAng(I, E:toWorld(ang(0,0,0)))
    holoParent(I,E)
    holoScaleUnits(I, vec(10,10,0.1))
    holoColor( I,vec(0,0,255) ), I++
    
    holoCreate(I)
    holoModel(I, "hq_cylinder") #sourcium
    holoPos(I, E:toWorld(vec(-40,40,-27)))
    holoAng(I, E:toWorld(ang(0,0,0)))
    holoParent(I,E)
    holoScaleUnits(I, vec(10,10,0.1))
    holoColor( I,vec(255,0,0) ), I++
    
    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" ) 
    { 
        Find:propDelete()
        if ( Fuel+25>100 ) { Fuel=100 } else { Fuel+=25 } 
    }
    if ( Find:model()=="models/sprops/geometry/sphere_24.mdl" && Hold<3 )
    {
        Find:propDelete()
        Hold++
        if ( Hold>=3 )
        {
            OutInc=0
            OutTime=random(15,30)   
        }            
    }
    
    # Increment/decrement values
    if ( mod(X,2)==0 && Fuel > 0 && Hold>=3 ) { Fuel-- }
    
    if ( Hold >= 3 && Fuel>0 ) # per second
    {
        OutInc++
        if ( OutInc >= OutTime ) 
        {
            for ( I=1, random(2,3) ) # Autism
            {    
                Out=propSpawn("models/sprops/geometry/sphere_3.mdl",E:toWorld(vec(40,40,I*5)),ang(0),0)
                Out:setMaterial("models/debug/debugwhite")
                Out:setColor(vec(255,255,0))
                Out["oretype",number]=1 #1: autism 2: gmodite 3: sourcism 4: Gaben
            }
            for ( I=1, random(1,2) ) # gmodite
            {    
                Out=propSpawn("models/sprops/geometry/sphere_3.mdl",E:toWorld(vec(0,40,I*5)),ang(0),0)
                Out:setMaterial("models/debug/debugwhite")
                Out:setColor(vec(0,0,255))
                Out["oretype",number]=2 #1: autism 2: gmodite 3: sourcism 4: Gaben
            }
            if ( random(0,1) ) # sourcism
            {
                Out=propSpawn("models/sprops/geometry/sphere_3.mdl",E:toWorld(vec(-40,40,I*5)),ang(0),0)
                Out:setMaterial("models/debug/debugwhite")
                Out:setColor(vec(255,0,0))
                Out["oretype",number]=3 #1: autism 2: gmodite 3: sourcism 4: Gaben        
            }
            OutInc=0
            OutTime=random(15,30)
            Hold=0      
        }           
    }
    
    #Update name
    setName( "Seperator - "+Hold+"/3 mixed elements - Fuel: "+Fuel+"%" )
    
    if ( changed(Fuel>0 && Hold==3) && Fuel>0 && Hold==3 ) 
    {
        E:soundPlay(1,0,"ambient/music/country_rock_am_radio_loop.wav")    
    }
    elseif ( changed(!(Fuel>0 && Hold==3)) && !(Fuel>0 && Hold==3) ) { soundStop(1) } 
}

