Atari800XL Posted February 19, 2024 Posted February 19, 2024 (edited) Ahoi, I have a little trainingmission where a carrier spawns randomly around the marianna-island. Some other ships are randomly spawned aroud this carrier, everythings looks fine, see atachment. Now I want for randomly place some Hornets on the deck of the carrier. If the carrier is not "late activation" everything works fine, there appear some Hornets. But without "late activation" I cannot spawn the carrier using MOOSE randomly in one of my placed zones. I spawn the carrier randomly with MOOSE: local carrierSpawn = "CARRIER" .. math.random(1, 999) BRC = math.random(1, 359) local SP = SPAWN:NewWithAlias('CARRIER',carrierSpawn):InitCountry(country.id.USA):InitHeading(BRC):SpawnInZone(spawnZone, true) The code I use to spawn some Hornet on my spawned carrier (it's part of an iteration, i is index, x,y,angle are from a randomized table of available positions on the carrier): CGI = Group.getByName(carrierSpawn) CGI2 = Group.getID(CGI) local staticObj = { ["name"] = "Hornet_"..i, ["livery_id"] = "vfa-37", ["category"] = "Planes", ["offsets"] = { ["y"] = ypos, ["angle"] = angle, ["x"] = xpos }, ["type"] = "FA-18C_hornet", ["groupId"] = 1, ["unitId"] = 1, ["y"] = 0, ["x"] = 0, ["heading"] = 0, ["linkUnit"] = CGI2, ["linkOffset"] = true, ["dead"] = false } coalition.addStaticObject(country.id.USA, staticObj) BUT this only works with a static placed carrier. When I initially spawn my carrier with MOOSE the addStaticObject-function doesn't work. Has anyone a hint for me to use addStaticObject ON a MOOSE-spawned carrier? A dump of all units filtered for the carrier looks like this: 2024-02-19 17:41:25.611 INFO SCRIPTING (Main): #DBG# iterate CARRIER#001 ID:1002638 -- spawned one 2024-02-19 17:41:25.611 INFO SCRIPTING (Main): #DBG# iterate CARRIER ID:1 -- originally "late activation" one Credits, Greetings and Thanks go out to @Adalla for his great dynamic deck templates, I desperately try to use his way of spawning static units in my training-mission! thanks and best regards, Andreas Edited February 20, 2024 by Atari800XL DCS MT, all maps except channel, FC3, F-16C Viper, F-15E, F/A-18C, AH-64D, F-5E, F-4E, P-51D, Spitfire, Fw-190D, MiG-21bis, L-39, AJS-37 Supercarrier, WWII-AP, CA, TrackIR5, F/A-18-Stick + Thrustmaster 16000, Stream Deck 8x4, 2x MFD Cougar Ryzen9 5950X SMT off, 64GB RAM, RTX 4070 SUPER TI, UWQHD 3440x1440, Win11+DCS from separate M.2
Grimes Posted February 20, 2024 Posted February 20, 2024 Link unit would be the unitId of the carrier, not the groupId. Also the groupid and unitId of the static object should be unique, which you could comment out and allow DCS to figure it out for you or I'm sure there is some function in moose that would give you an unused id for either. Might also be a good idea to wait a tick or two before spawning the statics on the spawned ship. I'd have to look through my test code to see if I had made something to verify it works on spawned ships, pretty sure I did, but it wouldn't have used moose, so I can't help on that part of it. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Atari800XL Posted February 20, 2024 Author Posted February 20, 2024 (edited) The decoration is allready delayed: if getFlag('randomDeckHornets') == 1 then timer.scheduleFunction(dekoDeck, {}, timer.getTime() + 10) end That would be great if you have something like this. I think I found the bug. This is from my little library.lua: -- (list) getAllUnitnames() -- returns a list of strings with all unitnames of the current map function getAllUnitnames() -- 0 = neutral, 1 = red, 2 = blue local ret = {} for i, gp in pairs(coalition.getGroups(0)) do table.insert(ret, Group.getName(gp)) end for i, gp in pairs(coalition.getGroups(1)) do table.insert(ret, Group.getName(gp)) end for i, gp in pairs(coalition.getGroups(2)) do table.insert(ret, Group.getName(gp)) end for i, gp in pairs(coalition.getStaticObjects(0)) do table.insert(ret, StaticObject.getName(gp)) end for i, gp in pairs(coalition.getStaticObjects(1)) do table.insert(ret, StaticObject.getName(gp)) end for i, gp in pairs(coalition.getStaticObjects(2)) do table.insert(ret, StaticObject.getName(gp)) end return ret end I allways handle with groupID's ... omg. But for now I have to move to the office Edited February 20, 2024 by Atari800XL DCS MT, all maps except channel, FC3, F-16C Viper, F-15E, F/A-18C, AH-64D, F-5E, F-4E, P-51D, Spitfire, Fw-190D, MiG-21bis, L-39, AJS-37 Supercarrier, WWII-AP, CA, TrackIR5, F/A-18-Stick + Thrustmaster 16000, Stream Deck 8x4, 2x MFD Cougar Ryzen9 5950X SMT off, 64GB RAM, RTX 4070 SUPER TI, UWQHD 3440x1440, Win11+DCS from separate M.2
Solution Atari800XL Posted February 20, 2024 Author Solution Posted February 20, 2024 (edited) And finally ... it works! My solution to get the ID of (MOOSE-)spawned carrier: local carrierSpawn = "CARRIER" .. math.random(1, 999) local BRC = math.random(1, 359) local allZones = shuffleList(inListLike('CSZ', getAllTriggerZones())) -- shuffleList(), inListLike(), getAllTriggerZones() are self coded functions local spawnZone = ZONE:New(allZones[1]) local SP = SPAWN:NewWithAlias('CARRIER', carrierSpawn):InitCountry(country.id.USA):InitHeading(BRC):SpawnInZone(spawnZone, true) -- -- code,code,code... -- local CGI = Group.getByName(carrierSpawn.."#001"):getUnits() local CGI2 = CGI[1]:getID() -- ID of the carrier The attachment shows un-randomized parking hornets. Edited February 20, 2024 by Atari800XL DCS MT, all maps except channel, FC3, F-16C Viper, F-15E, F/A-18C, AH-64D, F-5E, F-4E, P-51D, Spitfire, Fw-190D, MiG-21bis, L-39, AJS-37 Supercarrier, WWII-AP, CA, TrackIR5, F/A-18-Stick + Thrustmaster 16000, Stream Deck 8x4, 2x MFD Cougar Ryzen9 5950X SMT off, 64GB RAM, RTX 4070 SUPER TI, UWQHD 3440x1440, Win11+DCS from separate M.2
Recommended Posts