Announcement

Collapse
No announcement yet.

Spawning Statics From Type [MOOSE]

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Spawning Statics From Type [MOOSE]

    I'm trying to spawn random slingloadable crates from a table.

    The problem is I didn't manage to use NewFromType() properly.

    I even tried to obtain type and category with GetTypeName() and GetCategoryName() – from a ME crate – to no avail

    Code:
    local crate_zone = ZONE:New( 'Crate Zone' )
    
    -- Just to certify type and category are correct
    local crate = STATIC:FindByName( 'Crate' )
    local type = crate:GetTypeName()
    local category crate:GetCategoryName() -- EDIT: missing '='
    
    local crate_static = SPAWNSTATIC
      :NewFromType( type, category, country.id.USA )
      :SpawnFromZone( crate_zone )
    I got the following error:

    Code:
    ERROR   SCRIPTING: Mission script error: [string "C:\Users\Scifer\AppData\Local\Temp\DCS.openbeta\/~mis0000458A.lua"]:11008: attempt to index field '?' (a nil value)
    stack traceback:
    	[C]: ?
    	[string "C:\Users\Scifer\AppData\Local\Temp\DCS.openbeta\/~mis0000458A.lua"]:11008: in function 'GetStaticGroupTemplate'
    	[string "C:\Users\Scifer\AppData\Local\Temp\DCS.openbeta\/~mis0000458A.lua"]:24791: in function 'SpawnFromPointVec2'
    	[string "C:\Users\Scifer\AppData\Local\Temp\DCS.openbeta\/~mis0000458A.lua"]:24880: in function 'SpawnFromZone'
    	[string "C:\Users\Scifer\AppData\Local\Temp\DCS.openbeta\/~mis00004726.lua"]:10: in main chunk
    What am I doing wrong?
    Last edited 10-17-2020, 06:24 PM.

    #2
    Not sure what went wrong there. If you used exactly that script, there is a "=" missing in the category line.

    Anyway, if you have a static which you want to "clone", you can spawn it even simpler

    Code:
    local crate_static=SPAWNSTATIC:NewFromStatic("Crate"):SpawnFromZone(ZONE:New('Crate Zone'))
    crate_static:SmokeRed()
    A warrior's mission is to foster the success of others.
    i7-8700K | Asus RTX 2080Ti Strix OC | 32 GB Ram 3200 MHz DDR-4 | Asus Maximus Hero X | Samung EVO 960 Pro SSD | VKB Gunfighter Pro | MFG Crosswind | Rift S
    RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss

    Comment


      #3
      Originally posted by funkyfranky View Post
      If you used exactly that script, there is a "=" missing in the category line.
      Thanks for noticing but I got exactly the same error after correcting this.

      Comment


        #4
        Originally posted by funkyfranky View Post
        Anyway, if you have a static which you want to "clone", you can spawn it even simpler

        Code:
        local crate_static=SPAWNSTATIC:NewFromStatic("Crate"):SpawnFromZone(ZONE:New('Crate Zone'))
        crate_static:SmokeRed()
        Thanks for your suggestion but I don't want to manually place each static type in ME.

        Comment


          #5
          Originally posted by Scifer View Post
          Thanks for your suggestion but I don't want to manually place each static type in ME.

          Then you will have to use something other than moose to do this, moose needs template objects
          Click here for tutorials for using Virpil Hardware and Software


          Click here for Virpil Flight equipment dimensions and pictures.
          .

          Comment


            #6
            Originally posted by HC_Official View Post
            Then you will have to use something other than moose to do this, moose needs template objects
            What is NewFromType() for then?

            Comment


              #7
              Originally posted by Scifer View Post
              What is NewFromType() for then?
              not sure never used it


              but going by your code in your first post you are using a static template already ?


              local crate = STATIC:FindByName( 'Crate' )
              Click here for tutorials for using Virpil Hardware and Software


              Click here for Virpil Flight equipment dimensions and pictures.
              .

              Comment


                #8
                Originally posted by Scifer View Post
                Thanks for your suggestion but I don't want to manually place each static type in ME.
                Okay, no problem. Which static object do you want to spawn exactly? I'm not sure if the category returned is the one, that is required as input for the static template. I even think there is no way to extract that via scripting. I usually get that by looking in the mission file that is located inside the miz.

                But it is definitely possible to spawn all statics without any template in the mission.
                A warrior's mission is to foster the success of others.
                i7-8700K | Asus RTX 2080Ti Strix OC | 32 GB Ram 3200 MHz DDR-4 | Asus Maximus Hero X | Samung EVO 960 Pro SSD | VKB Gunfighter Pro | MFG Crosswind | Rift S
                RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss

                Comment


                  #9
                  After updating MOOSE, I came across an even better way – NewFromTemplate() – and finally managed to spawn random cargos:
                  Code:
                  local cargo_table = {
                    {
                      type = 'ammo_cargo',
                      mass = 1000,
                    },
                    {
                      type = "barrels_cargo",
                      mass = 480,
                    },
                    {
                      type = 'm117_cargo',
                      mass = 840,
                    },
                  }
                  
                  local cargo_template = cargo_table[math.random(#cargo_table)]
                  local cargo_zone = ZONE:New( 'Cargo Zone' )
                  
                  local cargo_static = SPAWNSTATIC
                    :NewFromTemplate( cargo_template, country.id.USA )
                    :SpawnFromZone( cargo_zone, 0, 'Cargo' )
                  Thanks everyone for your support!

                  Comment

                  Working...
                  X