BenC Posted March 28, 2019 Posted March 28, 2019 Sorry Ive been banging my head against the wall for an entire day with this. I think the diagnosis is that I"m just stupid. I have spawned 2 A10s from a template. They spawn, they take off, they have 15 stored waypoints (of all my possible objectives). I would like to (based on variables within my lua script) to reprogram their route, either through switching waypoint, or frankly any other means reroute these guys to 1 specific way point. Ive read about switchway point, but with the object orientated nature of LUA, its doing my head in. This is the code I use to spawn my aircraft. local SpawnPlane = SPAWN:New( "aiCAS" ) local GroupPlane = SpawnPlane:Spawn() I tried this, but no worky --- This test demonstrates the use(s) of the SwitchWayPoint method of the GROUP class. HeliGroup = GROUP:FindByName( "aiCAS" ) --- Route the helicopter back to the FARP after 60 seconds. -- We use the SCHEDULER class to do this. SCHEDULER:New( nil, function( HeliGroup ) local CommandRTB = HeliGroup:CommandSwitchWayPoint( 0, 8 ) HeliGroup:SetCommand( CommandRTB ) end, { HeliGroup }, 9 ) Any help much appreciated thanks..
Grimes Posted March 28, 2019 Posted March 28, 2019 Donno how møøse does things, but the native scripting engine functionality that it uses will suffice. https://wiki.hoggitworld.com/view/DCS_command_switchWaypoint local gp = Group.getByName('aiCAS') if gp:getSize() > 0 then local switchWP = { id = 'SwitchWaypoint', params = { fromWaypointIndex = 1, -- waypoint you want them to fly from goToWaypointIndex = 8, -- desitnation waypoint } } gp:getController():setCommand(switchWP) end 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
BenC Posted March 28, 2019 Author Posted March 28, 2019 (edited) Thankyou so much. edit : This doesn't actually seem to work. Investigation says maybe its bugged? https://forums.eagle.ru/showthread.php?p=3473679 Edited March 28, 2019 by BenC
Habu_69 Posted March 28, 2019 Posted March 28, 2019 This works for me in Moose: SpawnGroup = GROUP:FindByName( "My ME Group" ) BanditWP = STATIC:FindByName( "RAILYARD BLDG Vec2" ) BanditWPVec2 = BanditWP:GetVec2() -- Map position for bandit WP SpawnGroup:TaskRouteToVec2( BanditWPVec2, 600 ) -- Speed km/hr. Default = 20
BenC Posted March 28, 2019 Author Posted March 28, 2019 Thanks. I got the routing sorted out! Last challenge for me is trying to figure out how to get a simple string return of the group name of the dynamically spawned group. Right now the first spawned group is aiCAS#001. From there it goes to 002 etc. For the life of me I cannot get anything to work. Been fiddling with onSpawnGroup but no joy. Without the group name I can't do a few other tasks I have lined up. I miss Qbasic.
Habu_69 Posted March 28, 2019 Posted March 28, 2019 Have you tried: GROUP:GetName() Inherited from Identifiable. Recently used this in a script: RedBandits = SPAWN:New( "Red Interceptors" ) :InitLimit( 8, 2 ) :InitRandomizePosition( true, 120000, 75000 ) :OnSpawnGroup(function (SpawnGroup) SpawnGroup:TaskRouteToVec2( BanditWPVec2, 600 ) end ) Sets WP for spawned group to BanditWPVec2 location.
Hardcard Posted March 28, 2019 Posted March 28, 2019 @BenC If you tell us what you want to accomplish, specifically, we'll show you the way (hopefully). [sIGPIC][/sIGPIC]
BenC Posted March 29, 2019 Author Posted March 29, 2019 (edited) Thankyou all for your help, its been tremendous. To expand on what im doing. I am recreating the Arma style 'invade and annex' MP mission. I have 5 primary objectives, which is to clear airbases in a 'push/pull' style battle with the AI, and I have around 15 side missions, which are smaller targets for variety. Only 1 of each mission is current at any one time. As you clear an objective, the next one spawns in. Sequentially for the primary objectives, random for the secondary. I wish to have an F10 request system to allow players when only a few people are on to request support aircraft. CAP, CAS, SEAD. I want the support aircraft to proceed directly from their spawn point, to either the primary or secondary objective, as requested by the player. So far, i'm 90% of the way there with the help I have received here. This is my current code. local function AICASSecondary() if (trigger.misc.getUserFlag(10) == 1) then BanditWP = ZONE:FindByName( "Side1" ) elseif (trigger.misc.getUserFlag(10) == 2) then BanditWP = ZONE:FindByName( "Side2" ) elseif (trigger.misc.getUserFlag(10) == 3) then BanditWP = ZONE:FindByName( "Side3" ) elseif (trigger.misc.getUserFlag(10) == 4) then BanditWP = ZONE:FindByName( "Side4" ) elseif (trigger.misc.getUserFlag(10) == 5) then BanditWP = ZONE:FindByName( "Side5" ) elseif (trigger.misc.getUserFlag(10) == 6) then BanditWP = ZONE:FindByName( "Side6" ) elseif (trigger.misc.getUserFlag(10) == 7) then BanditWP = ZONE:FindByName( "Side7" ) elseif (trigger.misc.getUserFlag(10) == 8) then BanditWP = ZONE:FindByName( "Side8" ) elseif (trigger.misc.getUserFlag(10) == 9) then BanditWP = ZONE:FindByName( "Side9" ) elseif (trigger.misc.getUserFlag(10) == 10) then BanditWP = ZONE:FindByName( "Side10" ) elseif (trigger.misc.getUserFlag(10) == 11) then BanditWP = ZONE:FindByName( "Side11" ) end BanditWPVec2 = BanditWP:GetVec2() -- Map position for bandit WP local SpawnObject = SPAWN :New( "aiCAS" ) :OnSpawnGroup(function( SpawnGroup ) SpawnGroup:TaskRouteToVec2( BanditWPVec2, 600 ) end ) local SAMSpawnCommand = SpawnObject:Spawn() end Thus far, it works perfectly in the sense that, the A10 spawns, and when I click on it, it routes perfectly to my chosen objective. The only thing left is to somehow tell it its task. As of now, it simply flies over the target with nav lights on without engaging. I tried to replace the onspawn function with this (after changing BanditWP to a specific unit, not a zone) :OnSpawnGroup(function( SpawnGroup ) SpawnGroup:TaskAttackUnit(BanditWP) GrpTask = SpawnGroup:TaskAttackUnit(BanditWP) SpawnGroup:PushTask(GrpTask) SpawnGroup:TaskRouteToVec2( BanditWPVec2, 600 ) end However that deletes their route so they get lost before the get to the target. Thats it! Thanks again for your help, making an old dude much less stressed. Edited March 29, 2019 by BenC
Recommended Posts