Scifer Posted October 11, 2020 Posted October 11, 2020 (edited) 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 October 17, 2020 by Scifer
funkyfranky Posted October 12, 2020 Posted October 12, 2020 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 | RTX 4090 | 128 GB Ram 3200 MHz DDR-4 | Quest 3 RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss
Scifer Posted October 12, 2020 Author Posted October 12, 2020 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.
Scifer Posted October 12, 2020 Author Posted October 12, 2020 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.
HC_Official Posted October 13, 2020 Posted October 13, 2020 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. .
Scifer Posted October 13, 2020 Author Posted October 13, 2020 Then you will have to use something other than moose to do this, moose needs template objects What is NewFromType() for then?
HC_Official Posted October 13, 2020 Posted October 13, 2020 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. .
funkyfranky Posted October 13, 2020 Posted October 13, 2020 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 | RTX 4090 | 128 GB Ram 3200 MHz DDR-4 | Quest 3 RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss
Scifer Posted October 18, 2020 Author Posted October 18, 2020 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!
Recommended Posts