Jump to content

Spawning Statics From Type [MOOSE]


Scifer

Recommended Posts

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 :(

 

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:

 

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?


Edited by Scifer
Link to comment
Share on other sites

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

 

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.

i9-12900K | MSI RTX 3080Ti Suprim X | 128 GB Ram 3200 MHz DDR-4 | MSI MPG Edge Z690 | Samung EVO 980 Pro SSD | Virpil Stick, Throttle and Collective | MFG Crosswind | HP Reverb G2

RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss

Link to comment
Share on other sites

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

 

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.

Link to comment
Share on other sites

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

No more pre-orders

Click here for tutorials for using Virpil Hardware and Software

 

Click here for Virpil Flight equipment dimensions and pictures.

.

Link to comment
Share on other sites

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' )

No more pre-orders

Click here for tutorials for using Virpil Hardware and Software

 

Click here for Virpil Flight equipment dimensions and pictures.

.

Link to comment
Share on other sites

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.

i9-12900K | MSI RTX 3080Ti Suprim X | 128 GB Ram 3200 MHz DDR-4 | MSI MPG Edge Z690 | Samung EVO 980 Pro SSD | Virpil Stick, Throttle and Collective | MFG Crosswind | HP Reverb G2

RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss

Link to comment
Share on other sites

After updating MOOSE, I came across an even better way – NewFromTemplate() – and finally managed to spawn random cargos:

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' )

:thumbup: Thanks everyone for your support!

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...