Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name Forest Gen
- @inputs
- @outputs CurrentCount Cleanup [AllProps For]:array
- @persist [For SnowArray GrassArray Exist AllProps]:array Gen A A2 Radius Count Grass Snow IX
- @trigger
- runOnTick(1)
- runOnChat(1)
- E=entity()
- if(first()|dupefinished())
- {
- #For:pushString("models/foliage/tree01.mdl")
- #For:pushString("models/foliage/tree05.mdl")
- #For:pushString("models/foliage/tree10.mdl")
- #For:pushString("models/foliage/tree11.mdl")
- #For:pushString("models/foliage/tree12.mdl")
- #For:pushString("models/foliage/tree13.mdl")
- #For:pushString("models/foliage/tree15.mdl")
- For:pushString("models/foliage/bush01.mdl")
- For:pushString("models/foliage/bush01b.mdl")
- For:pushString("models/foliage/bush01c.mdl")
- SnowArray:pushString("models/foliage/pine_2m.mdl")
- SnowArray:pushString("models/foliage/pine_3m.mdl")
- SnowArray:pushString("models/foliage/pine_7m.mdl")
- SnowArray:pushString("models/foliage/pine_9m.mdl")
- GrassArray:pushString("models/props_foliage/ah_grass_512x512_001.mdl")
- #GrassArray:pushString("models/props_foliage/ah_grass_512x512_001_flowers.mdl")
- Count=256
- Radius=4096
- Grass=0
- Snow=0
- }
- if(chatClk(owner()))
- {
- if(owner():lastSaid():lower()=="!gen")
- {
- hideChat(1)
- if(!Gen)
- {
- print("Generating...")
- Gen=1
- A=0
- }
- else
- {
- print("Already Generating")
- }
- timer("ErrorCheck",8128*4)
- }
- if(owner():lastSaid():lower()=="!stop")
- {
- hideChat(1)
- print("Generation Stopped")
- Gen=0
- A=0
- }
- if(owner():lastSaid():lower()=="!clean")
- {
- hideChat(1)
- Cleanup=1
- Gen=0
- A=0
- }
- if(owner():lastSaid():lower():sub(1,7)=="!count ")
- {
- hideChat(1)
- if(!Gen)
- {
- Count=clamp(owner():lastSaid():lower():sub(8):toNumber(),16,1024)
- print("Count changed to "+Count)
- }
- else
- {
- print("You can't change that while generating!")
- }
- }
- if(owner():lastSaid():lower():sub(1,8)=="!radius ")
- {
- hideChat(1)
- if(!Gen)
- {
- Radius=clamp(owner():lastSaid():lower():sub(9):toNumber(),16,16384)
- print("Radius changed to "+Radius)
- }
- else
- {
- print("You can't change that while generating!")
- }
- }
- }
- if(changed(Gen)&!Gen)
- {
- Exist:clear()
- A=0
- }
- if(Gen)
- {
- if(Exist:count()<Count){if(findCanQuery()){A+=1}}
- else{print("Done "+AllProps:count()) Gen=0 stoptimer("ErrorCheck")}
- if(changed(A))
- {
- for(I=A,A)
- {
- if(Grass)
- {
- rangerHitEntities(0)
- rangerHitWater(1)
- Vec=E:pos()+vec(randint(-Radius,Radius),randint(-Radius,Radius),1024)
- Rang=rangerOffset(50000,Vec,vec(0,0,-1))
- Pos=Rang:pos()
- Z=clamp((1-(Rang:hitNormal():z())*320),-2,8)
- #Z=0
- findIncludeClass("gmod_wire_hologram")
- findInSphere(Pos,256)
- Closest=findClosest(Pos)
- Distance=round(Closest:pos():distance(Pos))
- #Closest:setColor(vec(255,0,0))
- if(Pos:isInWorld())
- {
- if(Distance>128)
- {
- if(Rang:hitTexture()=="**displacement**")
- {
- if(positive(Rang:hitNormal()):z()>=0.2)
- {
- if(Rang:matType()=="grass")
- {
- if(holoCanCreate())
- {
- A2+=1
- Holo=holoCreate(A2,Pos-vec(0,0,Z),vec(1),Rang:hitNormal():toAngle()+ang(90,0,randint(0,0)),vec(255),GrassArray[randint(1,GrassArray:count()),string])
- #holoAng(A2,holoEntity(A2):angles():setYaw(randint(0,360)))
- Exist:insertEntity(1,Holo)
- AllProps:insertEntity(1,Holo)
- stoptimer("ErrorCheck")
- timer("ErrorCheck",8128*4)
- }
- }
- }
- }
- }
- }
- }
- elseif(Snow)
- {
- rangerHitEntities(0)
- rangerHitWater(1)
- Vec=E:pos()+vec(randint(-Radius,Radius),randint(-Radius,Radius),1024)
- Rang=rangerOffset(50000,Vec,vec(0,0,-1))
- Pos=Rang:pos()
- Z=clamp((1-Rang:hitNormal():z())*360,6,36)
- findIncludeClass("prop_physics")
- findInSphere(Pos,1024)
- Closest=findClosest(Pos)
- Distance=round(Closest:pos():distance(Pos))
- if(Pos:isInWorld()&Pos:z()>E:pos():z())
- {
- if(Distance>(Closest:boxSize():x()+Closest:boxSize():y())/3)
- {
- #print(Rang:hitTexture())
- if(Rang:hitTexture()=="**displacement**")
- {
- #print(positive(Rang:hitNormal()))
- if(positive(Rang:hitNormal()):z()>=0.9)
- {
- if(Rang:matType()=="snow")
- {
- if(propCanCreate())
- {
- Prop=propSpawn(SnowArray[randint(1,SnowArray:count()),string],Pos-vec(0,0,Z),ang(randint(-2.5,2.5),randint(0,360),randint(-2.5,2.5)),1)
- Prop:setSkin(2)
- Prop:setColor(255,0,0)
- Exist:insertEntity(1,Prop)
- AllProps:insertEntity(1,Prop)
- stoptimer("ErrorCheck")
- timer("ErrorCheck",8128*4)
- }
- }
- }
- }
- }
- }
- }
- else
- {
- rangerHitEntities(0)
- rangerHitWater(1)
- Vec=E:pos()+vec(randint(-Radius,Radius),randint(-Radius,Radius),1024)
- Rang=rangerOffset(50000,Vec,vec(0,0,-1))
- Pos=Rang:pos()
- Z=clamp((1-Rang:hitNormal():z())*360,-4,8)
- findIncludeClass("prop_physics")
- findInSphere(Pos,1024)
- Closest=findClosest(Pos)
- Distance=round(Closest:pos():distance(Pos))
- if(Pos:isInWorld())
- {
- if(Distance>((Closest:boxSize():x()+Closest:boxSize():y())/5))
- {
- #print(Rang:hitTexture())
- if(Rang:hitTexture()=="**displacement**")
- {
- #print(positive(Rang:hitNormal()))
- if(positive(Rang:hitNormal()):z()>=0.9)
- {
- if(Rang:matType()=="grass")
- {
- if(propCanCreate())
- {
- RAN=randint(1,For:count())
- if(RAN==1)
- {
- Z=-16
- }
- elseif(RAN==3)
- {
- Z=72
- }
- elseif(RAN==4)
- {
- Z=36
- }
- elseif(RAN==5)
- {
- Z=64
- }
- #Prop=propSpawn(For[RAN,string],Pos+vec(0,0,Z),ang(randint(-2.5,2.5),randint(0,360),randint(-2.5,2.5)),1)
- Prop=propSpawn("models/props_junk/PopCan01a.mdl",Pos-vec(0,0,16),ang(randint(-2.5,2.5),randint(0,360),randint(-2.5,2.5)),1)
- IX+=1
- #Entity=holoCreate(number index,vector position,vector scale,angle ang,vector color,string model)
- holoCreate(IX,Prop:pos(),vec(1),Prop:angles(),vec(255),For[RAN,string])
- Prop:setColor(vec(255,0,0))
- Exist:insertEntity(1,Prop)
- AllProps:insertEntity(1,Prop)
- stoptimer("ErrorCheck")
- timer("ErrorCheck",8128*4)
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if(clk("ErrorCheck"))
- {
- print("Error: Ran out of areas to generate in")
- print("Generation Stopped at "+AllProps:count()+" props")
- Gen=0
- }
- }
- if(Cleanup)
- {
- if(AllProps:count())
- {
- AllProps[1,entity]:propDelete()
- AllProps:shift()
- }
- else
- {
- Cleanup=0
- print("Done Cleaning")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement