johnv2pt0 Posted April 5, 2018 Posted April 5, 2018 Can anyone help me with this? I made a simple script to check a client's agl and output a message to them. Set on a continuous action trigger. It seems to work well, however I'd like to adapt it to check a table of units instead of just looking for a specific one. As a bonus, I'd love to figure out how to schedule it in the script so that it only sends the message once every 20 seconds or so. I should be able to make that happen via triggers, but having it neatly wrapped up in the script would be nice. --MSG TO CLIENT IF ALTITUDE > 1000' AGL local _SHARK1 = Unit.getByName("SHARK 1") ALT = _SHARK1:getPoint().y GROUND = land.getHeight({ x = _SHARK1:getPoint().x, y = _SHARK1:getPoint().z }) if (ALT - GROUND) > 304.8 then trigger.action.outTextForCoalition( 2, "" .. _SHARK1:getPlayerName() .." , YOU'RE ALTITUDE IS TOO GREAT. PLEASE REMAIN BELOW 1000' AGL FOR DECONFLICTION.", 10 ) end env.info(ALT) env.info(GROUND) Any help would be greatly appreciated!
Grimes Posted April 5, 2018 Posted April 5, 2018 Put this on a once condition. timer.scheduleFunction will set that function to run again in 20 seconds. The unitTbl is a table of unit names which gets iterated via for i = 1, #unitTbl do It then checks to make sure the unit is alive. Then stores that unit as _u Changed alt to pos because there isnt really a need to recheck the position. Also made it local. local function altCheck() timer.scheduleFunction(altCheck(), {}, timer.getTime() + 20) local unitTbl = {"SHARK 1", "SHARK 2", "SHARK 3", "Hornet 1"} for i = 1, #unitTbl do if Unit.getByName(unitTbl[i]) and Unit.getByName(unitTbl[i]):getLife() > 0 then local _u = Unit.getByName(unitTbl[i]) local pos = _u:getPoint() local GROUND = land.getHeight({ x = pos.x, y = pos.z }) if (pos.y - GROUND) > 304.8 then trigger.action.outTextForCoalition( 2, "" .. _u:getPlayerName() .." , YOU'RE ALTITUDE IS TOO GREAT. PLEASE REMAIN BELOW 1000' AGL FOR DECONFLICTION.", 10 ) end env.info(pos.y) env.info(GROUND) end end end altCheck() 1 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
johnv2pt0 Posted April 6, 2018 Author Posted April 6, 2018 Thanks Grimes! I think this will really help me understand some things better.
johnv2pt0 Posted April 6, 2018 Author Posted April 6, 2018 This works without the scheduler, but with it in I get a stack overflow. Any ideas? error msg references this line: timer.scheduleFunction(altCheck(), {}, timer.getTime() + 20)
Grimes Posted April 6, 2018 Posted April 6, 2018 Oops. remove the () next to the alt check in that call. timer.scheduleFunction(altCheck, {}, timer.getTime() + 20) 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
Recommended Posts