Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: [E2] Tribbles V1

  1. #1
    Wire Sofaking postman's Avatar
    Join Date
    Mar 2010
    Location
    oregon
    Posts
    1,089

    Default [E2] Tribbles V3

    These are tribbles, they are tiny workers that's only goal is to travel to a tree, collect some wood, and deliver it to the mill.

    mostly this project has given me something to do, but i like it, and i plan to improve it.

    requirements:
    *wire extras, and prop core turned on.
    *wiremod
    *holo model any turned on.

    note: you need to spawn tribbles for it to work, their model is (the tiny sphere in phx misc.)
    "models/hunter/misc/sphere025x025.mdl"

    Features:
    *tribbles will goto a tree, and take a piece of wood.
    *then they roll back to the mill and place it in the mills "stock pile".
    *it adjusts how many trees spawn based on the ammount of tribbles.
    *other various things
    *(they look kinda like round ants from above ^^)
    New features from V2(actually v6, but w/e)
    *There is now 3 materials, wood, metal, and rocks.-
    Make them collect metal too
    *Each material has its own set of "gibs" (small thing that goes above their heads when they are done gathering)
    *they now wait at the resource for 5 seconds(i think), before returning to the mill(they also have different tools, im aware a skill saw isnt very good for cutting metal XD)
    *resources are randomly spawned, and timed

    New as of V3
    Tribbles are spawned by the e2, you can now buy tribbles using "/buy tribble"
    You can check the price(it changes based on how many tribbles are out) by typing "/tribblecost"
    Code is even more laggy, and hits the quota at around 15 tribbles i think, i really need help optimizing.
    A feature that makes the tribbles jump if they get stuck.

    Things to add for v3 (planned)
    Tribbles are controlled and spawned by the mill, you will no longer spawn them(this will use resources)Done.
    Other things can be made using the materialsNot yet.
    Cleaner code perhaps, maybe not hitting 3500 ops with 10 resources and tribbles Need help.




    notes:
    Dont spawn more then 15? of them for your own safety.(e2 crash)
    the code isnt very well optimized.
    (despite the fact it says V4 on the chip, its V1 release, ill be making it better and adding a purpose to it later.)
    its best to use the remover tool on the mill, rather then spamming Z, cause there is required to be at least 1 tribble, so it will keep spawning.



    code:
    Code:
    @name Tribbles_V7
    @inputs 
    @outputs [Materials TG MaterialsHp GatherMatType]:array
    @persist [WoodGibs RockGibs MetalGibs Tribbles GMaterials]:array
    @persist [Tribble Material GatheringMaterial SpawnedMaterial]:entity
    @persist [Model Type MaterialToSpawn GatherMat Plurl]:string V:vector
    @persist G S Work [Wood Rock Metal] MaterialHp NextSpawn TribbleRate
    @model models/props_forest/sawhorse.mdl
    runOnTick(1)
    runOnChat(1)
    Mill=entity()
    propSpawnEffect(0)
    MaterialHp=MaterialsHp[1,number]
    GatheringMaterial=Materials[1,entity]
    setName("Tribbles_V7 ("+Tribbles:count()+" tribble"+Plurl+") || Wood: "+Wood+" || Rock: "+Rock+" || Metal: "+Metal)
    Work=1
    S++
    TribbleRate=Tribbles:count()+5
    
    #the first
    if(first())
    {
        WoodGibs=array(
        "models/Gibs/wood_gib01a.mdl",
        "models/Gibs/wood_gib01b.mdl",
        "models/Gibs/wood_gib01c.mdl",
        "models/Gibs/wood_gib01d.mdl",
        "models/props_junk/wood_crate001a_Chunk07.mdl",
        "models/props_junk/wood_crate001a_Chunk04.mdl",
        "models/props_junk/wood_pallet001a_chunka4.mdl",
        "models/props_wasteland/wood_fence02a_board08a.mdl")
        
        RockGibs=array(
        "models/props_foliage/rock_forest01c.mdl",
        "models/props_foliage/rock_forest01d.mdl",
        "models/props_mining/rock_caves01.mdl",
        "models/props_mining/rock_caves01b.mdl",
        "models/props_junk/Rock001a.mdl")
        
        MetalGibs=array(
        "models/props_junk/garbage_metalcan001a.mdl",
        "models/props_c17/metalPot002a.mdl",
        "models/props_c17/TrapPropeller_Lever.mdl",
        "models/props_c17/tools_wrench01a.mdl",
        "models/props_canal/mattpipe.mdl")
        
        GMaterials=array(
        "models/props_foliage/tree_dead01.mdl|tree",
        "models/props_foliage/tree_pine04.mdl|tree",
        "models/props_foliage/tree_pine05.mdl|tree",
        "models/props_foliage/fallentree01.mdl|tree",
        "models/props_foliage/forestrock_cluster01.mdl|rock",
        "models/props_canal/rock_riverbed02c.mdl|rock",
        "models/props_wasteland/rockcliff01k.mdl|rock",
        "models/Gibs/helicopter_brokenpiece_03.mdl|metal",
        "models/Gibs/helicopter_brokenpiece_04_cockpit.mdl|metal",
        "models/Gibs/helicopter_brokenpiece_05_tailfan.mdl|metal")
        
        
        entity():setColor(255,150,150)
    
        
        hint("Mill is found and ready.",5)
        timer("MaterialSpawn",1000)
    }
    
    #spawn a tribble if there are none
    if(changed(Tribbles:count())&Tribbles:count()==0|changed(owner():keyUse())&owner():keyUse())
    {
        SpawnedTribble=propSpawn("models/hunter/misc/sphere025x025.mdl",entity():pos()+vec(0,0,70),ang(),0)
        Tribbles:pushEntity(SpawnedTribble)
    }
    
    #some thing used for a fake for loop with materials.
    if(G>=GMaterials:count()){G=1}else{G++}
    #grammer me speak is good!
    if(Tribbles:count()>1){Plurl="s"}else{Plurl=""}
    
    
    
    
    if(clk("MaterialSpawn")|owner():weapon():type()=="weapon_physcannon"&owner():keyUse())
    {
        timer("MaterialSpawn",randint(NextSpawn*1000))
        
        if(Materials:count()<=15)
        {
            Object = GMaterials[G,string]:explode("|")
            Model = Object[1,string]
            Type = Object[2,string]
            MaterialToSpawn=Model
            
            SpawnedMaterial=propSpawn(MaterialToSpawn,entity():pos()+vec(random(-1000,1000),random(-1000,1000),0),ang(),1)
            Materials:pushEntity(SpawnedMaterial)
            MaterialsHp[Materials:count(),number]=randint(10,20)
            GatherMatType[Materials:count(),string]=Type
        }
    }
    
    
    if(changed(Tribbles:count())&Tribbles:count()<=3){NextSpawn=40}
    if(changed(Tribbles:count())&Tribbles:count()<=6&Tribbles:count()>3){NextSpawn=38}
    if(changed(Tribbles:count())&Tribbles:count()<=10&Tribbles:count()>15){NextSpawn=30}
    if(changed(Tribbles:count())&Tribbles:count()<=15&Tribbles:count()>10){NextSpawn=20}
    if(changed(Tribbles:count())&Tribbles:count()<=20&Tribbles:count()>15){NextSpawn=18}
    if(changed(Tribbles:count())&Tribbles:count()>=21){NextSpawn=15}
    
    
    
    #various things to do when work is started
    if(changed(Work)&Work)
    {
        timer("TribblesCount",3000)
    }
    
    
    
    if(clk("TribblesCount")&Tribbles:count()>=1)
    {
        hint("Tribbles are getting to work.",5)
        hint("There are "+Tribbles:count()+" Tribbles working.",5)
    }
    elseif(clk("TribblesCount")&Tribbles:count()<=0)
    {
        hint("There are no tribbles present.",5)
        hint("Work will not be done",5)
    }
    
    #clean up tribbles, it cant take much more then this before a crash.
    if(Tribbles:count()>19)
    {
        Tribbles[Tribbles:count(),entity]:propDelete()
    }
    
    
    
    #if they should work
    if(Work&Tribbles:count()>=1)
    {
        
        
        for(I=1,Tribbles:count())
        {
            Tribble=Tribbles[I,entity]
    
            Tribble:setMaterial("phoenix_storms/egg")
            Tribble:setColor(150,150,150)
            
            #make the tribbles *jump* when they are not moving very fast, this helps them
            #get unstuck.
            if(Tribble:vel():length()<=15&(TG[I,string] == "stock"|TG[I,string] == "gathering"))
            {
                Tribble:applyForce(Tribble:up()*60000)
                Tribble:setColor(255,0,255)
            }
            
            #Removes the tribbles if the entity disapears
            if(!Tribble)
            {
                Tribbles:removeEntity(I)
            }
            
            #since TG:removeString(I) isnt working in this case, 
            #im just clearing the array, and it refills is-self imidiately.
            if(TG:count()>Tribbles:count())
            {
                TG:clear()
            }
            
    
            
            #the part for tribbles that need to goto the Materials
            if(TG[I,string] == "mill")
            {
                if(GatheringMaterial)
                {
                    V=(GatheringMaterial:pos()-Tribble:pos())*1.2
                }
                
                
                Tribble:setMass(200)
                
                #delete the wood prop above them.
                if(holoEntity(I))
                {
                    holoDelete(I)
                }
                
                #set the group to "stock" if they are near the target Material,
                # also remove a piece of wood from that Material
                if (Tribble:pos():distance(GatheringMaterial:pos()) < 100&TG[I,string] != "stock") 
                {
                    TG[I,string] = "gathering"
                    MaterialsHp[1,number]=MaterialsHp[1,number]-1
                    timer("axe"+I,5000)
                }
                
            }
            #the part of the loop for those that are cutting said wood.
            elseif(TG[I,string] == "gathering")
            {
                if(GatheringMaterial)
                {
                    V=(GatheringMaterial:pos()-Tribble:pos())*3
                }
                elseif(changed(GatheringMaterial)&!GatheringMaterial)
                {
                    V=Tribble:pos()-Tribble:pos()
                }
                
                holoCreate(I)
                
                
                if(GatherMatType[1,string]=="tree"){holoModel(I,"models/props_forest/axe.mdl")}
                elseif(GatherMatType[1,string]=="rock"){holoModel(I,"models/props_mining/pickaxe01.mdl")}
                elseif(GatherMatType[1,string]=="metal"){holoModel(I,"models/props_forest/circularsaw01.mdl")}
                
                holoPos(I,Tribble:pos()+vec(0,0,50))
                holoAng(I,ang(S,S,S))
                
                if(clk("axe"+I))
                {
                    TG[I,string] = "stock"
                    
                    #create the resource above them.
                    if(GatherMatType[1,string]=="tree")
                    {
                        holoModel(I,WoodGibs:string(randint(1,WoodGibs:count())))
                    }
                    elseif(GatherMatType[1,string]=="rock")
                    {
                        holoModel(I,RockGibs:string(randint(1,RockGibs:count())))
                    }
                    elseif(GatherMatType[1,string]=="metal")
                    {
                        holoModel(I,MetalGibs:string(randint(1,MetalGibs:count())))
                    }
                }
            }
            #the part of the loop for those that need to goto the mill.
            elseif(TG[I,string] == "stock")
            {
                V=(Mill:pos()-Tribble:pos())*1.7
                
                #they are fatter on the way back ^_^
                Tribble:setMass(300)
                
                
                #etc, etc.
                holoPos(I,Tribble:pos()+vec(0,0,50))
                holoAng(I,ang(S,S,S))
                
                #add them back to the mill if they go near it and 
                #add a piece of resource to the mill's stock pile
                if (Tribble:pos():distance(Mill:pos()) < 78 & TG[I, string]!="mill") 
                {
                    
                    if(GatherMatType[1,string]=="tree"){Wood++}
                    elseif(GatherMatType[1,string]=="rock"){Rock++}
                    elseif(GatherMatType[1,string]=="metal"){Metal++}
                    
                    TG[I,string] = "mill"
                }
                
            }
            #if they are not in a group, be put into the mill group.
            elseif(TG[I,string] == "")
            {
                TG[I,string] = "mill" 
                Tribble:setColor(255,0,0)
            }
            
        
            
            #move the tribbes
            Tribble:applyForce(V)
            
        }
        
        
        
    }
    
        #Materials loop
        for(T=1,Materials:count())
        {
            Material=Materials[T,entity]
            MaterialHp=MaterialsHp[T,normal]
            GatherMat=GatherMatType[T,string]
                    
            #remove the Material and its hp from the arrays if they get removed for whatever reason.
            if(!Material)
            {
                Materials:removeEntity(T)
                MaterialsHp:removeString(T)
                GatherMatType:removeString(T)
            }
    
            
            #kill them Materials >:D
            if(MaterialHp<=0)
            {
                Material:propDelete()
            }
        }
        
    
    #now to make more tribbles :DDD
    
    if(owner():lastSaid():explode(" "):string(1) == "/setmats")
    {
        CheatMat=owner():lastSaid():explode(" "):string(2):toNumber()
        Wood=CheatMat
        Metal=CheatMat
        Rock=CheatMat
    }
    
    
    
    if(chatClk(owner())&owner():lastSaid()=="/buy tribble")
    {
        if(Wood>=TribbleRate-2&Rock>=TribbleRate-5&Metal>=TribbleRate-6)
        {
            if(Tribbles:count()<=19)
            {
                SpawnedTribble=propSpawn("models/hunter/misc/sphere025x025.mdl",entity():pos()+vec(0,0,70),ang(),0)
                Tribbles:pushEntity(SpawnedTribble)
                
                Wood-=TribbleRate-2
                Rock-=TribbleRate-5
                Metal-=TribbleRate-6
                hint("Spawned a new tribble!",5)
                hint("There are now "+Tribbles:count()+" tribbles working",5)
            }
            elseif(Tribbles:count()>19)
            {
                hint("The maximum number of tribbles has been reached.",5)
                hint("this cannot be fixed due to limitations in expression2",5)
            }
            
        }
        else
        {
            hint("You cannot afford this!",5)
            hint("You will have to wait for the "+Tribbles:count()+" Tribble(s) that you have to collect enough.",5)
        }
    }
    
    if(chatClk(owner())&owner():lastSaid()=="/tribblecost")
    {
        hint("Tribble cost for wood is: "+(TribbleRate-2),5)
        hint("Tribble cost for rock is: "+(TribbleRate-5),5)
        hint("Tribble cost for metal is: "+(TribbleRate-6),5)
    }
    The code is around 350 lines, i think you may want to copy it into a file, rather then strait into gmod.

    Pics:





    Last edited by postman; 03-01-2011 at 08:37 PM. Reason: Version three

  2. #2
    Wire Sofaking ShadowBrain's Avatar
    Join Date
    Oct 2008
    Location
    The Netherlands
    Posts
    1,160

    Default Re: [E2] Tribbles V1

    Make them collect metal too, then bring it to some forgery or something.
    Nice job.
    I maek 3D mdoels adn paly veido gaems!

    Hey! I make Android games now! https://play.google.com/store/apps/d...id=ShadowBrain
    Check out the company I made some 3D models for!

  3. #3
    has a custom title mattwd0526's Avatar
    Join Date
    Apr 2009
    Posts
    2,817

    Default Re: [E2] Tribbles V1

    That's actually really cool

    Just a small note, you don't need to initialize variables as null values (in your if(first()) you set your arrays to be array(), E2 automatically wipes all persists and outputs on a code update/reset/spawn)
    Another small nitpicking (just finding these as I read your code), you don't need to clear the Tribbles array before you set it to the findToArray(), it will be completely replaced by the findToArray()


    For the hologram wood that they carry:
    Instead of creating it once and then setting its position and angle every time the loop runs, just create it and parent it once
    Parenting with holos gets rid of the need to update position and angle, thus reducing ops

    This part:
    Code:
    #add them back to the mill if they go near it
                if (Tribble:pos():distance(Mill:pos()) < 78) 
                {
                    TG[I,string] = "mill"
                }
                
                #add a piece of wood to the mills stack if they return.
                if(changed(TG[I,string])&TG[I,string] == "mill")
                {
                    Wood++
                }
    Can be changed to

    Code:
    #add them back to the mill if they go near it and add a piece of wood to the mill's stack
                if (Tribble:pos():distance(Mill:pos()) < 78 & TG[I, string]!="mill") 
                {
                    Wood++
                    TG[I,string] = "mill"
                }
    Last edited by mattwd0526; 02-22-2011 at 11:38 PM.

  4. #4
    Wire Sofaking postman's Avatar
    Join Date
    Mar 2010
    Location
    oregon
    Posts
    1,089

    Default Re: [E2] Tribbles V1

    yeah, thanks for the info, but again, this is like a v1, (i had left some things in there from before) its not even ready for release imo, but i wanted to release it anyways, makes me feel proud ^_^

    to shadow brain: i could do that, as long as i can optimize it where it doesnt hit 3000 ops with 10 of the fuckers rolling around.

  5. #5
    has a custom title mattwd0526's Avatar
    Join Date
    Apr 2009
    Posts
    2,817

    Default Re: [E2] Tribbles V1

    I updated my above post.

    It's pretty damn good for a V1, I really like the idea behind it

  6. #6
    Wire Sofaking postman's Avatar
    Join Date
    Mar 2010
    Location
    oregon
    Posts
    1,089

    Default Re: [E2] Tribbles V1

    Ill keep in mind the code from above, but im aware its best to parent holos, i cant do this, because the balls are rolling when they move.

    there for the holo would fly around all funky if i parent it.
    Also, the angle is so the wood spins around all fancy like.
    Last edited by postman; 02-23-2011 at 08:35 AM.

  7. #7
    Wirererer andre124's Avatar
    Join Date
    Apr 2009
    Posts
    152

    Default Re: [E2] Tribbles V1

    Quote Originally Posted by postman View Post
    Ill keep in mind the code from above, but im aware its best to parent holos, i cant do this, because the balls are rolling when they move.

    there for the holo would fly around all funky if i parent it.
    Also, the angle is so the wood spins around all fancy like.
    I suppose you could parent it and just set its angle instead of pos and angle. It wouldnt save much ops, and its not much of a big deal but, just putting it out there

  8. #8
    Wire Sofaking Officer Tibbles's Avatar
    Join Date
    Aug 2008
    Location
    Barnus Philbert Boulevard
    Posts
    890

    Default Re: [E2] Tribbles V1

    Tibbles approves of these here Tribbles

  9. #9
    Wirererer holy knife's Avatar
    Join Date
    Feb 2010
    Posts
    225

    Default Re: [E2] Tribbles V1

    I thought of tibbles when I saw these tribbles.

  10. #10
    Wire Sofaking postman's Avatar
    Join Date
    Mar 2010
    Location
    oregon
    Posts
    1,089

    Default Re: [E2] Tribbles V1

    Updated OP.
    Tribbles is now V2, check it out
    (new features in op, again)

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
unnecessary
unnecessary
unnecessary
unnecessary
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots