Amarok_73 Posted February 28, 2016 Posted February 28, 2016 (edited) Hello, Since I still feel pretty lame in Lua scripting, I'd like to ask other - more knowlegeable colleagues if this simple script executed after MIST initialization should in effect cause that group "Agressors" will be checked for being alive every 30 seconds, and if not, then will be respawned? EDIT: After some testing, and tweaking the script, now it is what at least seems not to cause any errors. But still I am not sure if this should provide expected effect. pipok = {} function pipok.respawnGroup(groupName) if not Group.getByName(groupName) then mist.respawnGroup(groupName, true) end mist.scheduleFunction(pipok.respawnGroup, {groupName}, timer.getTime() + 30) end pipok.respawnGroup('Agressors') EDIT2: Well, it works. :-) Edited February 28, 2016 by Pipok Natural Born Kamikaze ------------------------- AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Virpil Constellation Alpha Prime on Moza AB9 base, Virpil MongoosT-50CM3 Throttle, Turtle Beach VelocityOne Rudder.
Amarok_73 Posted February 28, 2016 Author Posted February 28, 2016 (edited) Then here comes another one (pretty obvious for expected learning path): how to iterate through all groups and execute this script on groups that's name contains specific string? Edited February 29, 2016 by Pipok Natural Born Kamikaze ------------------------- AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Virpil Constellation Alpha Prime on Moza AB9 base, Virpil MongoosT-50CM3 Throttle, Turtle Beach VelocityOne Rudder.
Steggles Posted February 29, 2016 Posted February 29, 2016 (edited) Top one looks alright to me. If it were me I would add an isActive() check on the group too, but I don't think its really necessary. The easiest way will be to create a table with all the group names in it (either hard coded in the script, or using the mist utils), then the 2 common iterations for LUA are: This one you can access numerically indexed table using i. eg. for i = 1, maxCount do local myGroup = Group.getByName(myGroups[i]) -- do something with myGroup end and this one using a table's key and value pairs. for key, value in pairs(table_to_iterate) do local myGroup = Group.getByName(value) local tableIndex = key -- do stuff with myGroup and tableIndex if needed endThe value in key will be the table index. This one is most useful when you have tables that are indexed with strings rather then numbers. To find a particular string inside of a group name, take a look at the string.find LUA function http://lua-users.org/wiki/StringLibraryTutorial local tag = "respawn_" local groupName = --get group name as you please if string.find(groupName, tag) then --group name contains the tag in it end Hope I've been able to help. Edited February 29, 2016 by Steggles -16AGR- 16th Air Guards Regiment is always looking for pilots - http://www.16agr.com EWRS - Early Warning Radar Script Specs: Gigabyte Sniper Z5-S Intel i5-4670k 3.4GHz OC'd 3.9GHz w/ Thermaltake 120mm Water 3.0 Pro Liquid CPU Cooler 16GB RAM Gigabyte GTX 1080 TM Hotas Warthog: SN: 06976 Saitek Pro Flight Combat Rudder Pedals TrackIR5 with TrackClipPro & Oculus Rift 2x 28" 4k UHD Monitors (3840x2160 each) + 1280x1024
Amarok_73 Posted February 29, 2016 Author Posted February 29, 2016 Steggles, I couldn't wish more adequate person to get into my humble person's troubles. :-) Thank You for that answer - for sure I'll work out based on that, what I want in this specific case. Just one more question - what is the hash sign loops I've noticed in some scripts? Isn't it the method to define number of elements in table that have to be traversed by loop? Natural Born Kamikaze ------------------------- AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Virpil Constellation Alpha Prime on Moza AB9 base, Virpil MongoosT-50CM3 Throttle, Turtle Beach VelocityOne Rudder.
Steggles Posted February 29, 2016 Posted February 29, 2016 The hash sign counts the entries in a table. So #myTable returns the number of entries in the table called myTable. 1 -16AGR- 16th Air Guards Regiment is always looking for pilots - http://www.16agr.com EWRS - Early Warning Radar Script Specs: Gigabyte Sniper Z5-S Intel i5-4670k 3.4GHz OC'd 3.9GHz w/ Thermaltake 120mm Water 3.0 Pro Liquid CPU Cooler 16GB RAM Gigabyte GTX 1080 TM Hotas Warthog: SN: 06976 Saitek Pro Flight Combat Rudder Pedals TrackIR5 with TrackClipPro & Oculus Rift 2x 28" 4k UHD Monitors (3840x2160 each) + 1280x1024
Amarok_73 Posted February 29, 2016 Author Posted February 29, 2016 Then what I do wrong with below? I've lost 3 hours of evening so far to find why this returns zero, and I am now totaly out of ideas... pipok = {} function pipok.respawnGroup() local GroupList = mist.DBs.unitsByName trigger.action.outText('#GroupList: ' .. string.format("%i", #GroupList), 5) for i=1, #GroupList do trigger.action.outText(GroupList[i]:getName(),5) end mist.scheduleFunction(pipok.respawnGroup, nil, timer.getTime() + 10) end trigger.action.outText("Executing RespawnPrefix script 8",10) pipok.respawnGroup() The same effect is if in place of "mist.DBs.aliveUnits" I'll use "mist.DBs.groupsByName", and only message I am repetitively receiving is "#GroupList: 0". Natural Born Kamikaze ------------------------- AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Virpil Constellation Alpha Prime on Moza AB9 base, Virpil MongoosT-50CM3 Throttle, Turtle Beach VelocityOne Rudder.
Steggles Posted February 29, 2016 Posted February 29, 2016 (edited) mist.DBs.unitsByName is a table of units, not groups. Also, unitsByName is a table that uses strings as it's keys, so trying to access it with a numeric index will not work. Using mist.DBs.groupsByName and iterate it in pairs. The keys on that table will be the group names. EDIT: I've never tried the # on a table that isn't numerically indexed, so I'm not sure if that has anything to do with it. Try this: pipok = {} function pipok.respawnGroup() local GroupList = mist.DBs.groupsByName --trigger.action.outText('#GroupList: ' .. string.format("%i", #GroupList), 5) --for i=1, #GroupList do for groupName, group in pairs(GroupList) do trigger.action.outText(groupName,5) end mist.scheduleFunction(pipok.respawnGroup, nil, timer.getTime() + 10) end trigger.action.outText("Executing RespawnPrefix script 8",10) pipok.respawnGroup() Edited February 29, 2016 by Steggles -16AGR- 16th Air Guards Regiment is always looking for pilots - http://www.16agr.com EWRS - Early Warning Radar Script Specs: Gigabyte Sniper Z5-S Intel i5-4670k 3.4GHz OC'd 3.9GHz w/ Thermaltake 120mm Water 3.0 Pro Liquid CPU Cooler 16GB RAM Gigabyte GTX 1080 TM Hotas Warthog: SN: 06976 Saitek Pro Flight Combat Rudder Pedals TrackIR5 with TrackClipPro & Oculus Rift 2x 28" 4k UHD Monitors (3840x2160 each) + 1280x1024
Amarok_73 Posted February 29, 2016 Author Posted February 29, 2016 Yes, this gonna work. In meanwhile I've eventually come to the similar in the script as below. Future seems brighter then. :-) pipok = {} function pipok.respawnGroup() for key, value in pairs(mist.DBs.groupsByName) do trigger.action.outText(string.format("%s", key), 2) end mist.scheduleFunction(pipok.respawnGroup, nil, timer.getTime() + 10) end trigger.action.outText("Executing RespawnPrefix script 17",10) pipok.respawnGroup() Thank You for Your effort, Steggles. Natural Born Kamikaze ------------------------- AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Virpil Constellation Alpha Prime on Moza AB9 base, Virpil MongoosT-50CM3 Throttle, Turtle Beach VelocityOne Rudder.
Steggles Posted February 29, 2016 Posted February 29, 2016 Good stuff mate, exactly the same thing represented in a different way. Glad I could help -16AGR- 16th Air Guards Regiment is always looking for pilots - http://www.16agr.com EWRS - Early Warning Radar Script Specs: Gigabyte Sniper Z5-S Intel i5-4670k 3.4GHz OC'd 3.9GHz w/ Thermaltake 120mm Water 3.0 Pro Liquid CPU Cooler 16GB RAM Gigabyte GTX 1080 TM Hotas Warthog: SN: 06976 Saitek Pro Flight Combat Rudder Pedals TrackIR5 with TrackClipPro & Oculus Rift 2x 28" 4k UHD Monitors (3840x2160 each) + 1280x1024
Amarok_73 Posted February 29, 2016 Author Posted February 29, 2016 (edited) So, eventually here's version that have to satisfy me for a while (knowing myself not for long). In the case that anyone should find it usefull, here's the code: pipok = {} function pipok.respawnGroup() local prefix = "RESP_" local refreshRate = 30 for grpName, value in pairs(mist.DBs.groupsByName) do if string.find(grpName, prefix) then --trigger.action.outText(grpName, 2) if not Group.getByName(grpName) then trigger.action.outText("Respawning " .. grpName, 10) mist.respawnGroup(grpName, true) end end end mist.scheduleFunction(pipok.respawnGroup, nil, timer.getTime() + refreshRate) end trigger.action.outText("Executing Respawn by Prefix script, v.20",10) pipok.respawnGroup()It has to be put in some .lua file, then loaded once by trigger, following MIST initialization. Groups to be re spawned should be named with string from variable "prefix", however it doesn't have to be in fact prefix of the group name, but string contained anywhere in the group name. And... that's it. :thumbup: Edited February 29, 2016 by Pipok Natural Born Kamikaze ------------------------- AMD Ryzen 5 3600, AMD Fatal1ty B450 Gaming K4, AMD Radeon RX 5700 XT, 32 GB RAM Corsair Vengeance LPX, PSU Modecom Volcano 750W, Virpil Constellation Alpha Prime on Moza AB9 base, Virpil MongoosT-50CM3 Throttle, Turtle Beach VelocityOne Rudder.
Recommended Posts