HungryCoyote Posted September 11, 2022 Posted September 11, 2022 I would like to be able to fly over a zone, para-drop units that will then attack everything in the zone. I can do the drop from Hercules mod and have the dropped units spawned on the ground but then the just sit there unless they happen to be close enough to the enemy.
toutenglisse Posted September 11, 2022 Posted September 11, 2022 20 minutes ago, HungryCoyote said: I would like to be able to fly over a zone, para-drop units that will then attack everything in the zone. I can do the drop from Hercules mod and have the dropped units spawned on the ground but then the just sit there unless they happen to be close enough to the enemy. Yes this is what is needed for ground groups to engage others : "line of sight" and "in range". So you have to script this. If there is for example 1 enemy group, make your group move to unit(1) of enemy group (and eventually hold position when "line of sight" on it and distance < fire distance), and when destroyed and your group is still alive repeat move to unit(1) of enemy group until it is totallty destroyed.
HungryCoyote Posted September 11, 2022 Author Posted September 11, 2022 (edited) Yes that is what I need but I don't know how to write script. I just knew I had seen it working. Edited September 11, 2022 by HungryCoyote
toutenglisse Posted September 11, 2022 Posted September 11, 2022 (edited) 23 hours ago, HungryCoyote said: Yes that is what I need but I don't know how to write script. I just knew I had seen it working. Here is an example with a little function I wrote. (to use it, load MIST and my script with mission start trigger, and when you need use MoveTo('group 1 name','group 2 name') so group 1 moves to leader of group 2 until group 2 or group 1 is dead). In the example, the blue group of 4 soldiers use the function to attack Red1 group, then Red2 group. Red1 group has 2 soldiers hidden behind houses. You can watch it in F10 map view and accelerated time. (their feet is their only carriage...) Edit : removed example, an updated one is posted in a following post. Edited September 12, 2022 by toutenglisse in post 1
HungryCoyote Posted September 11, 2022 Author Posted September 11, 2022 Thank you for taking the time to make this. Unfortunately it does not work on spawned vehicles. I 'm guessing because at the time of script running, the vehicle to be spawned does not yet exist in game. I think it would need an If exist type statement.
toutenglisse Posted September 12, 2022 Posted September 12, 2022 13 hours ago, HungryCoyote said: Thank you for taking the time to make this. Unfortunately it does not work on spawned vehicles. I 'm guessing because at the time of script running, the vehicle to be spawned does not yet exist in game. I think it would need an If exist type statement. Yes the prerequisite when using MoveTo() is that you know the names of the 2 groups, and that the two groups exist (there is a check in function for group existence, and function does nothing if both groups don't exist). If you use a script for "para-drop group" and enemy groups creation, this function, or kind of function, must be integrated to the script so it is called at the right time and group names are passed using the correct "dynamic" names of created groups. It can't be wrote "by guess". Also this is just a little example quickly wrote, it could also use a little function to choose the closest enemy group, within a max distance, and repeat the mist.goRoute() function with updated positions toward leader of enemy group until dead for the case where enemy group is moving.
HungryCoyote Posted September 12, 2022 Author Posted September 12, 2022 (edited) Just off the top of my head, I wonder if rather than having the MoveTo trigger run at missing start, it could be on an F10 menu. Once the units are spawned, give them the command to attack. I will give that a try. . . Yes, that works very well. Since this will be on a dedicated server with lots of enemy groups spawning at random locations, I will defiantly need to figure out how to get the dropped units, as you said, to choose the closest enemy, within a max distance or in a zone. Edited September 12, 2022 by HungryCoyote 1
toutenglisse Posted September 12, 2022 Posted September 12, 2022 4 hours ago, HungryCoyote said: Just off the top of my head, I wonder if rather than having the MoveTo trigger run at missing start, it could be on an F10 menu. Once the units are spawned, give them the command to attack. I will give that a try. . . Yes, that works very well. Since this will be on a dedicated server with lots of enemy groups spawning at random locations, I will defiantly need to figure out how to get the dropped units, as you said, to choose the closest enemy, within a max distance or in a zone. Here is an updated example with a new version of script. Function to use is now : MoveToNearEn('group 1 name') You can use it with a F10 item the same way you did if it works (best would be to add function in the script you use, a second after "para-drop" group creation). The script automatically send your group to nearest enemy group, as long as there are enemy groups within 25km, and to the next one when dead. Also the route is updated every minute in case enemy group is moving. test-MoveToNearEn.miz 2
HungryCoyote Posted September 12, 2022 Author Posted September 12, 2022 That works great. Exactly what I wanted. Thank you. One question, instead of a lot of repeated lines, is it possible to use a variable for the dropped units? The number increases by one with each unit dropped. MoveToNearEn('Cargo Group 10001') MoveToNearEn('Cargo Group 10002') MoveToNearEn('Cargo Group 10003')
toutenglisse Posted September 12, 2022 Posted September 12, 2022 26 minutes ago, HungryCoyote said: ...One question, instead of a lot of repeated lines, is it possible to use a variable for the dropped units? The number increases by one with each unit dropped... Yes, and this is why it is better to schedule the function within the script that creates the group, because you will use the variable from group's creation (example if the groupData name is : ["name"] = CargoName, then you will just add to script : mist.scheduleFunction(MoveToNearEn,{CargoName},timer.getTime()+1). You will have nothing to do as the function will run 1 second after group's creation with correct data). I've added a function that increases the name if the group with such name exists, and that then launches the other functions with updated name (it will start with 'Cargo Group 10001'). You just have to copy/paste this new script, and use SetCargoName() in your F10 item : Spoiler local CargoNum = 10000 function SetCargoName() if Group.getByName('Cargo Group '..CargoNum+1) and mist.groupIsDead('Cargo Group '..CargoNum+1) == false then CargoNum = CargoNum + 1 GroupName1 = 'Cargo Group '..CargoNum MoveToNearEn(GroupName1) end end function MoveToNearEn(GroupName1) local nearestDistance = 25000 local nearestGroupName = nil local GroupsCoal = ((Group.getByName(GroupName1):getCoalition()==1 and 2) or 1) local EnemyGroups = coalition.getGroups(GroupsCoal, Group.Category.GROUND) if #EnemyGroups > 0 then for i = 1, #EnemyGroups do ActualGrDist = mist.utils.get2DDist(mist.getLeadPos(GroupName1), mist.getLeadPos(EnemyGroups[i])) if ActualGrDist <= nearestDistance then nearestDistance = ActualGrDist nearestGroupName = EnemyGroups[i]:getName() end end end if nearestGroupName ~= nil and mist.groupIsDead(GroupName1) == false and mist.groupIsDead(nearestGroupName) == false then Point1 = mist.getLeadPos(GroupName1) Point2 = mist.getLeadPos(nearestGroupName) EnemyLead = Group.getByName(nearestGroupName):getUnit(1) local path = {} path[#path + 1] = mist.ground.buildWP(Point1, 'Rank', 15) path[#path + 1] = mist.ground.buildWP(Point2, 'Rank', 15) mist.goRoute(GroupName1, path) mist.scheduleFunction(EnemyLeadDead,{EnemyLead,GroupName1,nearestGroupName}, timer.getTime() + 60) end end function EnemyLeadDead(EnemyLead,GroupName1,nearestGroupName) if EnemyLead:isExist() == true and mist.groupIsDead(GroupName1) == false then Point1 = mist.getLeadPos(GroupName1) Point2 = mist.getLeadPos(nearestGroupName) local path = {} path[#path + 1] = mist.ground.buildWP(Point1, 'Rank', 15) path[#path + 1] = mist.ground.buildWP(Point2, 'Rank', 15) mist.goRoute(GroupName1, path) mist.scheduleFunction(EnemyLeadDead,{EnemyLead,GroupName1,nearestGroupName}, timer.getTime() + 60) elseif EnemyLead:isExist() == false and mist.groupIsDead(GroupName1) == false then MoveToNearEn(GroupName1) end end
HungryCoyote Posted September 12, 2022 Author Posted September 12, 2022 Wow, that's some serious code there. We are getting close to the danger zone of "in over my head". lol I was a bit wary of editing the script that creates the group as it is not mine but came with the Hercules mod and I was not sure how to edit it. I will copy/paste this code to it. I thought the main reason of editing the drop.script file was to eliminate the need for the F10 menu.
toutenglisse Posted September 12, 2022 Posted September 12, 2022 12 minutes ago, HungryCoyote said: ...I will copy/paste this code to it. I thought the main reason of editing the drop.script file was to eliminate the need for the F10 menu. You don't need to edit the drop script, and yes editing the script avoid the need for F10 menu. The script in my previous post is just an update. Use it like in previous example, and instead of using several radio items with MoveToNearEn('Cargo Group 10001')etc... you use only 1 radio item with SetCargoName().
HungryCoyote Posted September 12, 2022 Author Posted September 12, 2022 Small problem. It works fine if you only load one vehicle at a time. If you do two or three, only one of them moves toward the enemy.
HungryCoyote Posted September 13, 2022 Author Posted September 13, 2022 (edited) Upon further testing, I realize that it is not moving one from each group of three but one at a time starting with the first group, then continuing with the second group. So users will have to use F10 command once for each vehicle dropped. This might actually be a good thing because the mod has the option to drop one at a time or all three at once. Again, I just want to say thank you for all you help and patience. It is very much appreciated. Edited September 13, 2022 by HungryCoyote
toutenglisse Posted September 13, 2022 Posted September 13, 2022 @HungryCoyote no problem ! Here is the script with a little update, so it can activate up to 3 groups at once : Spoiler local CargoNum = 10000 function SetCargoName() local tempNum = CargoNum for j = 1, 3 do if Group.getByName('Cargo Group '..tempNum+j) then CargoNum = tempNum+j GroupName1 = 'Cargo Group '..CargoNum if mist.groupIsDead(GroupName1) == false then MoveToNearEn(GroupName1) end end end end function MoveToNearEn(GroupName1) local nearestDistance = 25000 local nearestGroupName = nil local GroupsCoal = ((Group.getByName(GroupName1):getCoalition()==1 and 2) or 1) local EnemyGroups = coalition.getGroups(GroupsCoal, Group.Category.GROUND) if #EnemyGroups > 0 then for i = 1, #EnemyGroups do ActualGrDist = mist.utils.get2DDist(mist.getLeadPos(GroupName1), mist.getLeadPos(EnemyGroups[i])) if ActualGrDist <= nearestDistance then nearestDistance = ActualGrDist nearestGroupName = EnemyGroups[i]:getName() end end end if nearestGroupName ~= nil and mist.groupIsDead(nearestGroupName) == false then Point1 = mist.getLeadPos(GroupName1) Point2 = mist.getLeadPos(nearestGroupName) EnemyLead = Group.getByName(nearestGroupName):getUnit(1) local path = {} path[#path + 1] = mist.ground.buildWP(Point1, 'Rank', 15) path[#path + 1] = mist.ground.buildWP(Point2, 'Rank', 15) mist.goRoute(GroupName1, path) mist.scheduleFunction(EnemyLeadDead,{EnemyLead,GroupName1,nearestGroupName}, timer.getTime() + 60) end end function EnemyLeadDead(EnemyLead,GroupName1,nearestGroupName) if EnemyLead:isExist() == true and mist.groupIsDead(GroupName1) == false then Point1 = mist.getLeadPos(GroupName1) Point2 = mist.getLeadPos(nearestGroupName) local path = {} path[#path + 1] = mist.ground.buildWP(Point1, 'Rank', 15) path[#path + 1] = mist.ground.buildWP(Point2, 'Rank', 15) mist.goRoute(GroupName1, path) mist.scheduleFunction(EnemyLeadDead,{EnemyLead,GroupName1,nearestGroupName}, timer.getTime() + 60) elseif EnemyLead:isExist() == false and mist.groupIsDead(GroupName1) == false then MoveToNearEn(GroupName1) end end
HungryCoyote Posted September 13, 2022 Author Posted September 13, 2022 For anyone else interested in this but not sure how to do triggers,etc, here is a simple mission with everything setup. You can edit it to suit your needs and see how it is all put together. Basic Herc Cargo Attack.miz
HungryCoyote Posted September 15, 2022 Author Posted September 15, 2022 So now I am trying to get this to work for the spawned troops the way it does for vehicles. I edited the attack script but not working. I believe it is due to the way dcs names the troops. For vehicles, it is Cargo Group 10001, Cargo Group 10002, etc. For troops, it is Soldier_Group_12001. I have a feeling it is the underscore that is messing it up. Basic Herc Troops Attack not work.miz
Solution toutenglisse Posted September 15, 2022 Solution Posted September 15, 2022 (edited) 3 hours ago, HungryCoyote said: So now I am trying to get this to work for the spawned troops the way it does for vehicles. I edited the attack script but not working... I have modified the Hercules_Cargo script to include my script and the needed commands when groups spawn (soldiers and vehicles). So you can just replace the Cargo script and get ridd of the rest (F10 triggers and my script), everything should be automatic. (! not tested !) EDIT : in "mission start" trigger, load MIST first, and then the Hercules Cargo attack script. Hercules_Cargo_Attack.lua Edited September 15, 2022 by toutenglisse in post 1
HungryCoyote Posted September 15, 2022 Author Posted September 15, 2022 Tested and working in multiplayer. Again you have made my day. Thank you. 1
Chad Vader Posted February 8, 2024 Posted February 8, 2024 (edited) Hi, Not sure if author of this script is here, but I have tried running it and it works on single player but not on a dedicated server. The events dont fire! Any ideas how to get it working on a dedicated server? Edited February 16, 2024 by Chad Vader
Recommended Posts