ColonelMolerat
Posts: 479
Joined: 9/23/2015 Status: offline
|
Right! I've realised, there's no point making the destroyed unit report 'nil' immediately - if it's activating the 'unit is killed' trigger, then it must have been destroyed, so the action only needs to check that the other units are destroyed anyway. As for the rest of my code, my friend's taught me how to simplify it as such: ***** --This bit checks if each radar is alive or not - if dead, they report as 'nil' and 'true' is returned. local function Cond1() unit=ScenEdit_GetUnit({side="Pitiful Capitalist Pigs", name="Primary Radar 1"});print(unit) if unit==nil then return true else return false end end local function Cond2() unit=ScenEdit_GetUnit({side="Pitiful Capitalist Pigs", name="Primary Radar 2"});print(unit) if unit==nil then return true else return false end end ***** --This bit creates an array containing all of my secondary radars. Basically, a single entity containing a list of all the secondary radars I want. Easy enough to add more to. radars = {'Secondary Radar 1','Secondary Radar 2','Secondary Radar 3','Secondary Radar 4','Secondary Radar 5','Secondary Radar 6'} ***** --This bit sets 'answer1' and 'answer2' to whatever Cond1 and Cond2 returned earlier ('true' or 'false' depending on if their Primary Radar is destroyed). The 'print' command isn't needed, but displays the response - useful when bugchecking. answer1=Cond1(); print(answer1) answer2=Cond2(); print(answer2) ***** -- This is the fun bit. 'if (answer1 and answer2)' checks to see if both answer1 and answer2 are TRUE - earlier in the script, you can see they are set to TRUE if the primary radars are destroyed. -- The next bit's a little more complicated - the "1, 6, 1" means that the script will run from the first to the sixth item in the list that will follow, going up by one each time - ie, 1-2-3-4-5-6. -- Finally, the three parts of SetEmcon are what it applies to - in this case 'Unit' (so a single unit), the name of the unit (normally eg "Secondary Radar 1"), and what sensor to set (in this case radar becomes active). The 'name' part in this case is a bit different - by writing 'radars[variable]', we are telling it to choose an item from the array 'radars' (mentioned earlier, containing Secondary Radar 1-6). The [variable] then tells it to run through from the first to the sixth item in that array, increasing by one each time - so first the code will apply to Secondary Radar One, then to Secondary Radar 2, then 3, 4, 5 up to Secondary Radar 6 - as set by the earlier 'for variable=1,6,1' part of code. if (answer1 and answer2) then for variable=1,6,1 do ScenEdit_SetEMCON('Unit',radars[variable],'Radar=Active') end ***** I hope that explanation is clear enough, let me know if anyone wants anything clarifying. To add more radars to turn on, add them to the 'radars' array (the one containing 'Secondary Radars 1-6') then increase the 'for variable=1,6,1 do' to list how many radars you now have - eg 'for variable=1,9,1 do' if you have nine radars. I have that code set as an action (Lua Script type) that is triggered in the mission editor when one of my two 'Primary Radars' are destroyed. All together it's: local function Cond1() unit=ScenEdit_GetUnit({side="Pitiful Capitalist Pigs", name="Primary Radar 1"});print(unit) if unit==nil then return true else return false end end local function Cond2() unit=ScenEdit_GetUnit({side="Pitiful Capitalist Pigs", name="Primary Radar 2"});print(unit) if unit==nil then return true else return false end end radars = {'Secondary Radar 1','Secondary Radar 2','Secondary Radar 3','Secondary Radar 4','Secondary Radar 5','Secondary Radar 6'} answer1=Cond1(); print(answer1) answer2=Cond2(); print(answer2) if (answer1 and answer2) then for variable=1,6,1 do ScenEdit_SetEMCON('Unit',radars[variable],'Radar=Active') end end
< Message edited by ColonelMolerat -- 12/12/2016 7:26:09 PM >
|