chromium Posted December 23, 2013 Posted December 23, 2013 Hi all, I need help with this script: RedGroundAIsimulator = true --- Exec text part local group_tag = "IFV" -- cambia usando il groupType, o meglio il vehicle. local group_radius = 300 local group_roadDisable = nil local groupName = "" local groupData = "" local pointObj = "" local Point_ObjTag = "AA" local Point_groupName = "" if RedGroundAIsimulator = true then for groupName, groupData in pairs(mist.DBs.groupsByName) do --List of groups by name if string.find(groupName,group_tag) then --searches for prefix within group names local groupToMove = groupName if string.find(groupName,Point_ObjTag) then --searches for prefix within group names Point_groupName = groupName pointObj = Unit.getByName(Point_groupName):getPosition().p --HELP NEEDED HERE, HOW TO CHOOSE THE NEAREST "Point_groupName" for any groupToMove one? end mist.groupToRandomPoint({group = Group.getByName(groupToMove), point = pointObj, radius = group_radius, disableRoads = group_roadDisable,}) end end end this should be a structure that make the MIST groupToRandomPoint function to work with any group that have the "IFV" tag in its name. The objective is to make any groups with the tag to move to the nearest unit that have the tag "AA" in its name (those units will be simple infantry man placed in cities or area objective... they simply act as scenario objective for ground troops.) but I miss how to choose the nearest group with "AA" tag for every "IFV" group. Can somebody help me? thanks and merry christmas ;) Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
SNAFU Posted December 23, 2013 Posted December 23, 2013 I am pretty sure there are thousend better ways of getting what you need, but I usually use the iterative loop approach simply constructed with for-do-if comparisons, f.e.: This function returns the closest trigger zone with the name actualzonename1,2,...,n like "combatzone1" for the unitsposition defined with actualhelipos. closestzonetable = {} for i = 1, numberofzones do actualzone = trigger.misc.getZone(actualzonename..string.format(i)) if actualzone == nil then trigger.action.outText("ERROR: actualzone == nil ", 4000) return end actualzonepos = {} actualzoneposx = actualzone.point.x actualzoneposz = actualzone.point.z actualoffset = math.sqrt((actualzoneposx - actualhelipos.x)*(actualzoneposx - actualhelipos.x) + (actualzoneposz - actualhelipos.z)*(actualzoneposz - actualhelipos.z)) if i == 1 then minimumoffset = actualoffset closestzone = actualzonename..string.format(i) zoneradius = actualzone.radius elseif i > 1 and minimumoffset > actualoffset then minimumoffset = actualoffset closestzone = actualzonename..string.format(i) zoneradius = actualzone.radius end end closestzonetable = { name = closestzone, distance = minimumoffset, radius = zoneradius } local closestzonetableprintout = mist.utils.tableShow(closestzonetable) --trigger.action.outText("closest zone: " ..closestzonetableprintout, 5)--ok Since I didn´t totally understand the CTTS script, I wrote my own transport script for helis and the part above was taken from that script you see in the attachement.un_loadingheli_v31m2.lua [sIGPIC][/sIGPIC] Unsere Facebook-Seite
chromium Posted December 23, 2013 Author Posted December 23, 2013 thanks, I'll take a look asap :). Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
Grimes Posted December 23, 2013 Posted December 23, 2013 One way is to brute force it, iterate through all known groups and see which is closest. The other way is to use world.searchObjects() to narrow the total number of groups to search down and then brute force it. 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
chromium Posted December 24, 2013 Author Posted December 24, 2013 Can you give me an example? (even if simplified or already included in something else)? thanks in advance :) Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
Zayets Posted December 27, 2013 Posted December 27, 2013 What Grimes says is to use function getGroups from coalition coalition.getGroups(enum coalition.side coalition, enum Group.Category groupCategory or nil) so that you have the list of all groups known from a coalition. Then you loop through all of these in a for - do loop and assign WITHIN the loop a variable called (say) minimumDistance. You will override this one ONLY if the currently read distance to the currently read group is lower than previously stored value. You will have to initialize this variable with a fairly large number. Hope that helps. [sIGPIC]OK[/sIGPIC]
pappavis Posted December 27, 2013 Posted December 27, 2013 I want to determine the bearing from my Player tyo another unit. Does such function exist? met vriendelijke groet, Михель "умный, спортсмен, комсомолетс" [sIGPIC][/sIGPIC] [TABLE]SPECS: i9-9900K 32gigs RAM, Geforce 2070RTX, Creative XFi Fata1ity, TIR5, Valve Index & HP Reverb, HOTAS Warthog, Logitech G933 Headset, 10Tb storage.[/TABLE]
Zayets Posted December 27, 2013 Posted December 27, 2013 Not directly but there's a couple of neat functions in MIST. First, you must get the position of the unit the player is controlling. That's easily done with : Vec3 function Object.getPoint(Object self) Once you identified that you can call one of these functions to display (you can also control to whom you may show this message) the BR/BRA message : mist.msgBR or mist.msgBRA Hope that helps. [sIGPIC]OK[/sIGPIC]
pappavis Posted December 27, 2013 Posted December 27, 2013 Not directly but there's a couple of neat functions in MIST. First, you must get the position of the unit the player is controlling. That's easily done with : Vec3 function Object.getPoint(Object self) Once you identified that you can call one of these functions to display (you can also control to whom you may show this message) the BR/BRA message : mist.msgBR or mist.msgBRA Hope that helps. I'm a bit inexperienced. What I have; * My own unit's poistion X Y coordinates * The target unit X Y coordinates How do i apply Vec3 function Object.getPoint(Object self) on the above knowns? Sum code would be very appreciated. met vriendelijke groet, Михель "умный, спортсмен, комсомолетс" [sIGPIC][/sIGPIC] [TABLE]SPECS: i9-9900K 32gigs RAM, Geforce 2070RTX, Creative XFi Fata1ity, TIR5, Valve Index & HP Reverb, HOTAS Warthog, Logitech G933 Headset, 10Tb storage.[/TABLE]
Zayets Posted December 27, 2013 Posted December 27, 2013 Should be something like that (I am not at home now so I can't check working so you may have to fiddle a bit with it) : myUnit = Unit.getByName('My Unit Name') otherUnit = Unit.getByName('The Other Unit Name') unitPosn = myUnit:getPoint() mist.msgBR({otherUnit},{unitPosn}, true, true, 'BR message: ', 10, {coa = {'all'}}) [sIGPIC]OK[/sIGPIC]
pappavis Posted December 27, 2013 Posted December 27, 2013 (edited) Should be something like that (I am not at home now so I can't check working so you may have to fiddle a bit with it) : mist.msgBR({otherUnit},{unitPosn}, true, true, 'BR message: ', 10, {coa = {'all'}})[/i] Thanx, I do something wrong. The mist.msgBR doesnt execute. The line Here is my code. Could be becos 'unitpos' isnt a vec3? local units = group:getUnits() local comp = {} local groupMin = maxDistance for j=1,#units do local unit = units[j] if unit ~= nil then local unitpos = unit:getPoint() local typename = unit:getTypeName() table.insert(comp, typename) local dist = GetDistance(unitpos.x, unitpos.z, playerpos.x, playerpos.z) local altitude1 = unitpos.y if dist < groupMin then groupMin = dist end if (dist > 0) then -- get coordinates, and display ingame local tableBR1 = {units = units, ref = unitpos, alt = true, metric = true, text = ' BR message: ', displayTime = 10, msgFor = {coa = {'all'}} } if tableBR1 ~= nil then trigger.action.outText("DEBUG: tableBR1 ~= nil", 2) local sXYcoords1 = mist.msgBR(tableBR1) trigger.action.outText("DEBUG: sXYcoords1=" .. sXYcoords1, 5) end end end end Edited December 27, 2013 by pappavis met vriendelijke groet, Михель "умный, спортсмен, комсомолетс" [sIGPIC][/sIGPIC] [TABLE]SPECS: i9-9900K 32gigs RAM, Geforce 2070RTX, Creative XFi Fata1ity, TIR5, Valve Index & HP Reverb, HOTAS Warthog, Logitech G933 Headset, 10Tb storage.[/TABLE]
Zayets Posted December 27, 2013 Posted December 27, 2013 getPoint returns a Vec3. You can actually outtext its values (x,y,z) because it's a simple table. Also, you can get the BR string with mist.getBRString . If function does not fire at all but does not give any error then all types are correct. [sIGPIC]OK[/sIGPIC]
pappavis Posted December 27, 2013 Posted December 27, 2013 (edited) getPoint returns a Vec3. You can actually outtext its values (x,y,z) because it's a simple table. Also, you can get the BR string with mist.getBRString . If function does not fire at all but does not give any error then all types are correct. Indeed, no error. However, the debug output text doesnt proceed beyond this so something is wrong. local sPos4 = mist.getBRString( {units = units, ref = unitpos, alt = true, metric = true} ) Assuming unitpos is a vec3, could the problem be in my way of defining a table? Edited December 27, 2013 by pappavis met vriendelijke groet, Михель "умный, спортсмен, комсомолетс" [sIGPIC][/sIGPIC] [TABLE]SPECS: i9-9900K 32gigs RAM, Geforce 2070RTX, Creative XFi Fata1ity, TIR5, Valve Index & HP Reverb, HOTAS Warthog, Logitech G933 Headset, 10Tb storage.[/TABLE]
chromium Posted January 11, 2014 Author Posted January 11, 2014 Ok, after some test and time I found a way to get the script working, but it doesen't work exactly as intende. The code is attached, the problem IMHO is between line 52 and 74. But I can't solve it :( The script, once loaded, choose any ground group which has the tag "IFV" in its name and (should) move it to the nearest unit of any group which has "OBJ" in its name (for testing "OBJ" group is only one, made of units, dispersed in the map). Well, the script load and start to move "IFV" group to one units of the group "OBJ", but not the nearest: the latest one. Any suggestion to rectify those lines, that was a copy and paste of SNAFU suggestion, is really appreciated. I also thanks Grimes and Zayets, but I'm not expertize enought to write the code you suggested, any try I made was not succesful :).AutoAdvance_rev04.lua Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
chromium Posted January 13, 2014 Author Posted January 13, 2014 I found a fix and I optimized the above script a lot making it a function, I have to add another working logic and then if someone could find it useful I'll post it here :) Author of DSMC, mod to enable scenario persistency and save updated miz file Stable version & site: https://dsmcfordcs.wordpress.com/ Openbeta: https://github.com/Chromium18/DSMC The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.
Recommended Posts