@name Seller
@inputs 
@persist [E, O]:entity EntType
@persist Ready GT:gtable X Z 
@outputs Balance
@model models/props_lab/citizenradio.mdl
#Input: models/sprops/geometry/sphere_3.mdl ( E["oretype",number] )

###########
#Main Code#
###########
if ( first() || dupefinished() )
{
    runOnTick(1)
    E = entity()
    O = owner()
    Ready=1
    
    GT=gTable("rbank",1)
    Balance=GT[O:steamID(),number]
    
    # Holo Stuff
    I = 1
    holoCreate(I)
    holoModel(I, "models/props_lab/tpplug.mdl")
    holoPos(I, E:toWorld(vec(0,0,15)))
    holoAng(I, E:toWorld(ang(-90,0,0)))
    holoParent(I,E)
    holoScale(I, vec(2))
    I++
    
    holoCreate(I)
    holoModel(I, "hq_sphere")
    holoPos(I, E:toWorld(vec(0,0,70)))
    holoAng(I, E:toWorld(ang(0,0,0)))
    holoParent(I,E)
    holoScaleUnits(I, vec(3))
    holoAlpha(2,0)
    
    
    timer("",10)
}
# Update output
if ( clk("") )
{
    timer("",10)
    
    if ( !Ready )
    {
        Z+=3
        holoPos(2,E:toWorld(vec(0,0,Z))) 
        
        if ( Z>2000 )
        {
            holoAlpha(2,0)
            holoEntity(2):removeTrails()
            Bam=propSpawn( "models/props_c17/oildrum001_explosive.mdl",E:toWorld(vec(0,0,Z)),1 )  
            Bam:propBreak()  
            
            if ( EntType==1 ) { Balance += 5 } #Autsim = r$5
            elseif ( EntType==2 ) { Balance += randint(50,100) } #Gmodite = r$50-100
            elseif ( EntType==3 ) { Balance += randint(100,250) } #Sourcium = r$100-250
            elseif ( EntType==4 ) { Balance += randint(500,1500) } #Gaben = r$5000-10000
            GT[O:steamID(),number] = GT[O:steamID(),number]+Balance
            
            E:soundPlay(5,3,"buttons/blip2.wav")
            
            Ready=1
        }           
    }
    
    setName( "Seller - Balance R$"+GT[O:steamID(),number] )       
} 

if ( Ready )
    {
        findIncludeModel("models/sprops/geometry/sphere_3.mdl")
        findInSphere(E:pos(),25) 
        Ent=find()
        if ( Ent:isValid() && Ent["oretype",number]!=0 )
        {
            Z=40
            holoPos(2,E:toWorld(vec(0,0,Z)))
            holoAlpha(2,255)
            holoColor(2,Ent:getColor())
            holoMaterial(2,Ent:getMaterial())
            holoEntity(2):setTrails(10,10,5,"trails/smoke",vec(0),75)
            
            Ready=0
            EntType=Ent["oretype",number]
            #print(EntType)
            Ent:propDelete()
            
            E:soundPlay(4,3,"hl1/ambience/steamburst1.wav")      
        }   
    }
