@name FailCake Happy Tree
@outputs Lvl Water Die Status:string Rdys Grow NoSun Sun InWater GrowTime
@outputs Once S R B Name:string Str:array
@persist Ran:ranger [Pos Time]:array Sd
@trigger all
@model models/props_junk/terracotta01.mdl
runOnTick(1)
runOnChat(1)

E = entity()

if(first()){
propSpawnEffect(0)   
    
holoCreate(1)
holoModel(1,"hqcylinder")   
holoPos(1,E:toWorld(vec(-0.5,0,12)))
holoScaleUnits(1,vec(17,17,1))
holoMaterial(1,"models/props_wasteland/dirtwall001a")
holoParent(1,E)

holoCreate(2)
holoModel(2,"models/props_foliage/bush2.mdl")   
holoPos(2,E:toWorld(vec(-0.5,0,12)))
holoScaleUnits(2,vec(0,0,0))
holoParent(2,E)

holoCreate(3)
holoModel(3,"models/props_foliage/tree_deciduous_03b.mdl")   
holoPos(3,E:toWorld(vec(3,0,12)))
holoScaleUnits(3,vec(0,0,0))
holoAlpha(3,0)
holoParent(3,E)

Pos[1,vector] = vec(14,8,44)
Pos[2,vector] = vec(-20,12,42)
Pos[3,vector] = vec(-14,-12,40)
Pos[4,vector] = vec(0,-10,24)
Pos[5,vector] = vec(-4,10,50)

Lvl = 1
Water = 100
Die = 0
Sun = 100
Status = "*Happy*"
S = 3
Name = "None"
}

Str = owner():lastSaid():explode(" ")


if(chatClk(owner())){
    
if(Str:string(1)=="-name"){
Name = Str:string(2)
hint("* Name Changed To "+Name+" ! *",7)
}

}

setName("---FailCake Happy Tree---" + "
    Name = " + Name +"
    Lvl = " + Lvl + "%" +"
    Sun = " + Sun + "%" +"
    Water = " + Water + "%" +"
    Status = " + Status)
    

rangerFilter(holoEntity(1))
rangerFilter(holoEntity(2))
Ran = rangerOffset(600,E:pos(),E:up())

if(Die == 0){
if(E:isUnderWater()){
InWater = 1    
}else{
InWater = 0
}

if(InWater){
timer("Drain",600)
if(clk("Drain")){
    
if(Water < 150){
Water+=1
}else{
Die = 1
}

if(Water > 110){
Status = "* Overfloading D= *"  
}else{
Status = "* Drinking Water *" 
}

}
}

if(InWater == 0){
timer("waterconsume",1000)
if(clk("waterconsume")){
    
if(Water > 0){
Water-=1

if(Water <= 50 & Water >= 10){
Status = "* Thirsty *"    
}

if(Water >= 50 & Water <= 100){
Status = "* Happy *"    
}

if(Water <= 10 & Water >= 1){
Status = "* Dieng *"    
}

}else{
Die = 1
}
    
}
}


if(Ran:hit()){
NoSun =1   
}else{
NoSun = 0
}

if(NoSun){
timer("removesun",700)

if(clk("removesun")){
    
if(Sun > 0){
Sun-=1
}else{
Die = 1
}

}

}else{
timer("givesun",600)
if(clk("givesun")){
if(Sun < 100){
Sun+=1
}    
}
}



timer("grow",GrowTime)
if(clk("grow")){
Grow+=1

if(Grow >= 20){
Lvl+=1
Grow = 0    
}
   
}


if(Lvl >= 3){
GrowTime = 1000

if(Rdys){
timer("DropO",300)
if(clk("DropO")){
    
for(Sd=1,Time:count()){
Time[Sd,number] = Time[Sd,number] - 1  
}

if(Time[Sd,number] < 0){
Orange = propSpawn("models/props/cs_italy/orange.mdl",holoEntity(Sd+3):pos(),ang(0,0,0),0)    
print("HoloEntity "+Sd+3+" Removed")
holoDelete(Sd+3)
Time:remove(Sd)
}

if(Time:count() <= 0){
Rdys = 0
S = 3
Pos[1,vector] = vec(14,8,44)
Pos[2,vector] = vec(-20,12,42)
Pos[3,vector] = vec(-14,-12,40)
Pos[4,vector] = vec(0,-10,24)
Pos[5,vector] = vec(-4,10,50)
B = 0    
}

}  
}

if(Rdys == 0){
timer("SpawnOrange",7000)
if(clk("SpawnOrange")){
    
if(Pos:count() > 0){
S+=1
B+=1
R=randint(1,Pos:count())
holoCreate(S)
holoModel(S,"models/props/cs_italy/orange.mdl")   
holoPos(S,E:toWorld(Pos[R,vector])) 
holoScale(S,vec(0.5,0.5,0.5))
holoParent(S,E)
Time[B,number] = randint(100,200)
Pos:remove(R)
print("HoloEntity "+S+" Given " + Time[B,number])
}else{
Rdys= 1
}

}   
}
}

if(Lvl == 2){
GrowTime = 300
holoAlpha(3,255)
holoScaleUnits(3,vec(Grow*4,Grow*4,Grow*4))   
}

if(Lvl == 1){
GrowTime = 200
holoScaleUnits(2,vec(Grow,Grow,Grow))    
} 
   
}else{

Status = "* Dead *"
Water = 0
Sun = 0
holoColor(2,vec(90,90,90))
holoColor(3,vec(90,90,90))
holoColor(1,vec(90,90,90))
E:setColor(90,90,90)
if(Once == 0){
Once = 1
E:soundPlay(1000,100,"music/hl2_song23_suitsong3.mp3")    
}
}

if(duped()){
selfDestructAll()    
}
