Zachc12385 Posted January 11, 2024 Posted January 11, 2024 (edited) Hey guys I recently made a mission that uses radio commands to spawn air units infinitely and it works great. The only thing i want to learn is how to add radio commands using scripts as opposed to triggers in the mission editor. I tried messing around with some of the scripts on the mist website like... local requestM = missionCommands.addSubMenu('Request Asset') local rSead = missionCommands.addCommand('SEAD', requestM, doRequestFunction, {type = 'SEAD"}) local rCAS = missionCommands.addCommand('CAS', requestM, doRequestFunction, {type = 'CAS"}) local rCAP= missionCommands.addCommand('CAP', requestM, doRequestFunction, {type = 'CAP"}) ...but for the life of me i cant figure it out. can someone help this make sense to me? I can add the sub menu however the commands always return an error. I attached my miz file to show you what im working with. Its a great mission i just want to get to that next level and do some more complex scripting. Thank you Syria dynamic AA.miz Edited January 11, 2024 by Zachc12385
Grimes Posted January 11, 2024 Posted January 11, 2024 Those functions are native DCS scripting functions and have nothing to do with mist. I don't actually have any functions built into mist to create menu items for people. To answer your question the doRequestFunction has to be a function that is declared somewhere. Otherwise when you select the command it won't know what the execute. local function doRequestFunction(vars) if vars.type == "SEAD" then elseif vars.type == "CAS" then elseif vars.type == "CAP" then end end local requestM = missionCommands.addSubMenu('Request Asset') local rSead = missionCommands.addCommand('SEAD', requestM, doRequestFunction, {type = "SEAD"}) local rCAS = missionCommands.addCommand('CAS', requestM, doRequestFunction, {type = "CAS"}) local rCAP= missionCommands.addCommand('CAP', requestM, doRequestFunction, {type = "CAP"}) Also that sample on the wiki had some typos with mixing " and ' to define strings which would have also caused an error. 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
Zachc12385 Posted January 19, 2024 Author Posted January 19, 2024 @Grimes Thank you for responding im still however having issues. heres my script im not sure what is wrong local function doRequestFunction(vars) if vars.type == "SEAD" then if not Group.getByName('Aerial-21') then mist.respawnGroup('Aerial-21', true) if not Group.getByName('Aerial-22') then mist.respawnGroup('Aerial-22', true) end elseif vars.type == "CAS" then if not Group.getByName('Aerial-23') then mist.respawnGroup('Aerial-23', true) if not Group.getByName('Aerial-24') then mist.respawnGroup('Aerial-24', true) end end end local requestM = missionCommands.addSubMenu('Request Asset') local rSead = missionCommands.addCommand('SEAD', requestM, doRequestFunction, {type = "SEAD"}) local rCAS = missionCommands.addCommand('CAS', requestM, doRequestFunction, {type = "CAS"}) I'm pretty new to lua. all i want to do is spawn 2 groups when the radio command is selected.
Grimes Posted January 19, 2024 Posted January 19, 2024 mist.groupIsDead("Aerial-21") == true as the condition instead of if not Group.getByName() Could also try adding logging to see where it gets to. For example local function doRequestFunction(vars) trigger.action.outText(mist.utils.tableShow(vars), 10) if vars.type == "SEAD" then if not Group.getByName('Aerial-21') then trigger.action.outText("RESPWN Aeiral 21", 10) mist.respawnGroup('Aerial-21', true) end -- you forgot to close is by the way. if not Group.getByName('Aerial-22') then mist.respawnGroup('Aerial-22', true) end Could also use a program like notepad++ to write the code in. Use the lua visualizer and it can help spot bugs like failing to close if statements. 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
Zachc12385 Posted January 22, 2024 Author Posted January 22, 2024 (edited) @Grimes i got the radio item to pop up but i doesnt spawn the gorups that i want any ideas here? p.s i use notepad++ but i dont know how you get it to show up like that local function request(vars) if vars.type == sead then mist.respawnGroup('Aerial-21') end mist.respawnGroup('Aerial-22') end local requestAsset = missionCommands.addSubMenu('Request Asset') local seadAsset = missionCommands.addCommand( 'SEAD' , requestAsset , mist.respawnGroup, {type = sead} ) Edited January 22, 2024 by Zachc12385
Grimes Posted January 22, 2024 Posted January 22, 2024 One of the icons on the toolbar opens a UI that you can select the code used for the syntax highlighting. Its the icon that looks like <>. local seadAsset = missionCommands.addCommand( 'SEAD' , requestAsset , request, {type = sead} ) The 3rd input for that function is the function to run. You had it as mist.respawnGroup, which can work, but not with what you sent to it. However you want it to run the request function. Which will then in turn run the mist function with the correct inputs. 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
Zachc12385 Posted January 22, 2024 Author Posted January 22, 2024 (edited) local function requestSEAD(vars) if vars.type == SEAD then mist.respawnGroup('SEAD-1', true) end mist.respawnGroup('SEAD-2', true) end local function requestCAS(vars) if vars.type == CAS then mist.respawnGroup('CAS-1', true) end mist.respawnGroup('CAS-2', true) end local function requestCAP(vars) if vars.type == CAP then mist.respawnInZone('CAP-1', 'BLUE') end mist.respawnInZone('CAP-2', 'BLUE') end local requestAsset = missionCommands.addSubMenu('Request Asset') local seadAsset = missionCommands.addCommand( 'SEAD' , requestAsset , requestSEAD, {type = SEAD} ) local seadAsset = missionCommands.addCommand( 'CAS' , requestAsset , requestCAS, {type = CAS} ) local seadAsset = missionCommands.addCommand( 'CAP' , requestAsset , requestCAP, {type = CAP} ) I got the code to work now i just need to figure out how to add a message whenever a group spawns in. I also want to figure out how to do a while loop as well. thanks for your help its finally all starting to make sense. @Grimes any luck figuring out how to use witchcraft? i feel like it would help a ton. for some reason I cant get function whatever(vars) to work with flags or anything else for that matter Edited January 22, 2024 by Zachc12385
Recommended Posts