Motion_Blurz Posted July 3, 2021 Share Posted July 3, 2021 (edited) Firstly, any assistance is much appreciated. I am not much for coding and have to beg borrow steal what I can find when it comes to scripting to make missions feel more alive and dynamic. I have a script that generates random OPFOR spawns. It's nice but there isn't a conditional check to discriminate what type of surface it is spawning onto and thus you get guys with AKs and APCs out floating in the water shooting at you. So much for that surprise sea infiltration.... I would like to change that but uncertain how to properly do so with the Land.SurfaceType. I am at wits end with how to properly insert this check. local _aheadPointInf = AmbushZone.getPointAheadOfUnit(PlayerUnit:GetName(), math.random(3200,3700),"Infantry") local aheadPoint = POINT_VEC3:NewFromVec3( _aheadPointInf ) local aheadZone = ZONE_RADIUS:New( "AmbushZone_"..Function.RandomVariable(3), aheadPoint:GetVec2(), math.random(600,800) ) local group = AmbushZone.SpawnInfantry:SpawnInZone(aheadZone,true) SCHEDULER:New( nil, function() Function.DestroyGroup(group) end, {},AmbushZone.EnemyUnitsLifeTime) Edited July 3, 2021 by Motion_Blurz substance Link to comment Share on other sites More sharing options...
cfrag Posted July 3, 2021 Share Posted July 3, 2021 (edited) Well, you would first have to decide what to do depending on the terrain type that is returned. Once you have the point where you want to spawn, you would then invoke land.getSurfaceTye(), which returns a code 1..5, for each of which you will have to decide what to do, e.g. a small boat for shallow water, a ship for deep water (water), maybe a tank for roads. Also: when invoking getSurfaceType(), remember that it takes a two-value vector that contains x in the first, and a 3-vector's z in the second (y) attribute... Edited July 3, 2021 by cfrag Link to comment Share on other sites More sharing options...
Motion_Blurz Posted July 3, 2021 Author Share Posted July 3, 2021 (edited) Just seeking to have ground units not spawn in the sea. Edited July 3, 2021 by Motion_Blurz Link to comment Share on other sites More sharing options...
Motion_Blurz Posted July 3, 2021 Author Share Posted July 3, 2021 Perhaps I have been performing the wrong step or putting it in the incorrect place when I have made attempts at getSurfaceType and to then take an action. Simply put, what I would like to accomplish with the above is to have a SurfaceType check that occurs and then only spawn if the return is 1 or perhaps rather ~= 3 Link to comment Share on other sites More sharing options...
toutenglisse Posted July 3, 2021 Share Posted July 3, 2021 (edited) 1 hour ago, Motion_Blurz said: Perhaps I have been performing the wrong step or putting it in the incorrect place when I have made attempts at getSurfaceType and to then take an action. Simply put, what I would like to accomplish with the above is to have a SurfaceType check that occurs and then only spawn if the return is 1 or perhaps rather ~= 3 After first line, put : if land.getSurfaceType(_aheadPointInf) ~= 3 and land.getSurfaceType(_aheadPointInf) ~= 2 then then put all the rest, and add an "end" at the end to close the added "if". Edited July 3, 2021 by toutenglisse Link to comment Share on other sites More sharing options...
Motion_Blurz Posted July 3, 2021 Author Share Posted July 3, 2021 Thanks. I tried your suggestion and it results in no troops spawning. I have attached the lua and mission file for greater reference. Perhaps that will shed more light. Cyprus Sandbox.miz EnrouteAmbush.lua Link to comment Share on other sites More sharing options...
toutenglisse Posted July 3, 2021 Share Posted July 3, 2021 1 hour ago, Motion_Blurz said: Thanks. I tried your suggestion and it results in no troops spawning.... Ok, sorry I can't help - it is scripting with custom functions, hard to tell what would work. Link to comment Share on other sites More sharing options...
Motion_Blurz Posted July 4, 2021 Author Share Posted July 4, 2021 Nothing to apologize for. I appreciate the attempt. Link to comment Share on other sites More sharing options...
dark_wood Posted July 4, 2021 Share Posted July 4, 2021 (edited) You can try to use 'not' instead of '~=' if not land.getSurfaceType(_aheadPointInf) == 3 and not land.getSurfaceType(_aheadPointInf) == 2 then --do your LUA here end or better, check if is land, road or runway if land.getSurfaceType(_aheadPointInf) == 1 or land.getSurfaceType(_aheadPointInf) == 4 or land.getSurfaceType(_aheadPointInf) == 5 then --do your LUA here end Edited July 4, 2021 by dark_wood Link to comment Share on other sites More sharing options...
Recommended Posts