ckfinite -> RE: Lua - Paradrop (7/24/2016 5:26:56 PM)
|
First off, I would suggest using my KeyValue library to make the code easier to write - no need for all the gsub anymore, the library does that. You can get it here. There's two more libraries that will make writing this easier, my math library and my scene utilities library, here and here, respectively. You'll need to put those into the scene initialized event, with the key store library being loaded first. Now, for the actual coding: Don't do initialization of units in scene initialized. If you do, then when the scene is reopened, those initialization events will fire again. With the libraries, you can write for i=1,8 do ScenEdit_GetUnit({name="UNIT NAME HERE #"..i,side="YOUR SIDE HERE"}).spawn = {{name="Recon Airdrop", dbid=714, num=2}} end Just run this in the script console before you save the scene, and those values will stick (be warned, the libraries need to run first, so add them first, then reopen the scene). You will also need the following line in the initialization event, along with the libraries: Units.init() Then, in the unit entered area drop script, you then have local function DropUnit(point, side, name, type, dbid, error, tries) for i=1,tries do local center = (Quaternion.fromEuler(math.random()*error,0,0)*Quaternion.fromEuler(0,0,math.random() * 2 * math.pi)) * Quaternion.new(point) rp = center:toPoint() if World_GetElevation(rp^{}) >= 0 then return ScenEdit_AddUnit(rp^{side=side, name=name, dbid=dbid, type=type}) end end end local unit = ScenEdit_UnitX() for _,u in ipairs(unit.spawn) do for i=1,u.num do DropUnit(Point.new(unit), "YOUR SIDE NAME HERE", u.name, "Facility", u.dbid, 1/6371, 10) end end This script shouldn't care if there's another ahead of it - though sadly, SetLoadout doesn't work for flying aircraft for some reason. I've attached a demo scene.
|
|
|
|