Kanelbolle Posted June 1, 2021 Posted June 1, 2021 Hi, i have been looking and tying to figure out how i can get the name of the unit or group that runs a F10 menu radio item i created ? Only thing i can find is how to get all units or a unit in a zone, coalition etc., but nothing how to identify the unit that is starting the actual script. This to get the position of the player who ran the script. I know how to get the position of a unit to, but not the actual player. I'm not using any of the frameworks like MIST or MOOSE. (Not that i found any helpful functions there) Any ideas ? WARGAMES Servers: https://forum.dcs.world/topic/301046-wargames-server-pvp-and-pve-campaign-servers/ Scripts: RGC & SPGG https://github.com/AGluttonForPunishment/
Grimes Posted June 2, 2021 Posted June 2, 2021 https://wiki.hoggitworld.com/view/DCS_func_addCommandForGroup You have to add the command to the group, pass some identifier of that group to the function called, and then use that identifier to do with as you please. Sadly we don't have addCommandForUnit so either make an educated guess who sent it, have only one player per group, or make a specialized radio command for each member of the group via sub-menues and hope they choose the correct one. 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
Kanelbolle Posted June 2, 2021 Author Posted June 2, 2021 23 minutes ago, Grimes said: https://wiki.hoggitworld.com/view/DCS_func_addCommandForGroup You have to add the command to the group, pass some identifier of that group to the function called, and then use that identifier to do with as you please. Sadly we don't have addCommandForUnit so either make an educated guess who sent it, have only one player per group, or make a specialized radio command for each member of the group via sub-menues and hope they choose the correct one. Thx for the reply :) If i understand you correctly there is no real good way of identifying a group from a radio menu that is not custom to that specific group. So use flags per group to identify the group in my script. Something like this ?: if group in zone trigger runs a script Script check every group in zone if group1 in zone addCommandForGroup with flag 101 value 1 if group2 in zone addCommandForGroup with flag 102 value 1 etc for every group, since there is no parameter that passed the group name to the script. And a trigger for every group to check if flag 101 is 1 flag 101 is 2 then do script that check again if flag 101 value 1 them do this for group1 if flag 102 value 1 them do this for group2 Am i overthinking this or is DCS scripting this hard to pass identification of the unit/group to the script ? WARGAMES Servers: https://forum.dcs.world/topic/301046-wargames-server-pvp-and-pve-campaign-servers/ Scripts: RGC & SPGG https://github.com/AGluttonForPunishment/
Grimes Posted June 2, 2021 Posted June 2, 2021 The sample on that wiki page literally passes the groupName to the function that the command calls. local function imLost(gName) if Group.getByName(gName) then -- gotta be paranoid local units = Group.getByName(gName):getUnits() -- do whatever you want with that table of units because I cant think of a good example at the moment end end Another way to write it might be more like: missionCommands.addCommandForGroup(groupId, 'Halp', nil , imLost, "someGroupName") However I would try to do everything in the function itself because by having to check flag values by triggers kind of defeats the purpose. You could certainly check the flag value in the script if you made some list that associated a flag to a group with a list, but writing the whole action in the function will simplify things. 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
Kanelbolle Posted June 2, 2021 Author Posted June 2, 2021 (edited) 6 hours ago, Grimes said: The sample on that wiki page literally passes the groupName to the function that the command calls. local function imLost(gName) if Group.getByName(gName) then -- gotta be paranoid local units = Group.getByName(gName):getUnits() -- do whatever you want with that table of units because I cant think of a good example at the moment end end Another way to write it might be more like: missionCommands.addCommandForGroup(groupId, 'Halp', nil , imLost, "someGroupName") However I would try to do everything in the function itself because by having to check flag values by triggers kind of defeats the purpose. You could certainly check the flag value in the script if you made some list that associated a flag to a group with a list, but writing the whole action in the function will simplify things. I have 1 unit per player group. So if i am understanding this correct. I can run this function on the server at start (Init script?): local function imLost(gName) if Group.getByName(gName) then -- gotta be paranoid local units = Group.getByName(gName):getUnits() local groupleader = units[1]:getName() local msg = format.string("The unit %s is running the script", groupleader) trigger.action.outText(msg , 10 , false) end end And add a trigger to give the group in the zone a radio menu to call the function? Trigger: Switch Condition: InZone Action: Doscript DoScript: missionCommands.addCommandForGroup(groupId of The Group In TheZone, 'Who is running script?', nil , imLost, "the groupname who is in the zone") Alto the addCommandForGroup doesn't know who the group is ether... so i guess i need to create a trigger with a condition for every group.... Edited June 2, 2021 by Kanelbolle WARGAMES Servers: https://forum.dcs.world/topic/301046-wargames-server-pvp-and-pve-campaign-servers/ Scripts: RGC & SPGG https://github.com/AGluttonForPunishment/
Kanelbolle Posted June 2, 2021 Author Posted June 2, 2021 I think i finally understand the process of this. The way i wanted to do it wasn't possible. F10 menu to get added and the F10 menu passing on the group name as i was thinking it should. I was thinking it should come as a parameter even from the command of the F10 menu when a group runs it (Who ever runs it). But i have to add a menu to the correct group and define the group in the menu that i added it to... This was not obvious to me.. Thx Grimes WARGAMES Servers: https://forum.dcs.world/topic/301046-wargames-server-pvp-and-pve-campaign-servers/ Scripts: RGC & SPGG https://github.com/AGluttonForPunishment/
Kanelbolle Posted June 2, 2021 Author Posted June 2, 2021 The solution to my problem if anybody is interested.. Spoiler trigger.action.outText("script loaded" , 10 , false) local foundUnits = {} local sphere = trigger.misc.getZone('Trigger_Zone_AF_Incirlik') local volS = { id = world.VolumeType.SPHERE, params = { point = sphere.point, radius = sphere.radius } } local ifFound = function(foundItem, val) foundUnits[#foundUnits + 1] = foundItem:getName() return true end world.searchObjects(Object.Category.UNIT, volS, ifFound) local function imLost(gName) if Group.getByName(gName) then -- gotta be paranoid trigger.action.outText("Function imLost is running" , 10 , false) local msg = string.format("Function ImLost runned by : %s", gName) trigger.action.outText(msg , 20) end end local foundUnitsCount = table.getn(foundUnits) local msg = string.format("Found number of units in zone: %i", foundUnitsCount) trigger.action.outText(msg , 20) for i = 1, foundUnitsCount do local _unitname = foundUnits[i] local msg = string.format("Found unit : %s", _unitname) trigger.action.outText(msg , 20) if Unit.getByName(_unitname) then local _groupname = Unit.getByName(_unitname):getGroup():getName() local msg = string.format("Found group Name : %s", _groupname) trigger.action.outText(msg , 20) local groupId = Unit.getByName(_unitname):getGroup():getID() local msg = string.format("Found group ID : %i", groupId) trigger.action.outText(msg , 20) missionCommands.addCommandForGroup(groupId, 'Halp', nil , imLost, _groupname) trigger.action.outTextForGroup(groupId, "Message to Group ID " ..groupId.. " Gruppe Name: " .._groupname, 20) end end 1 WARGAMES Servers: https://forum.dcs.world/topic/301046-wargames-server-pvp-and-pve-campaign-servers/ Scripts: RGC & SPGG https://github.com/AGluttonForPunishment/
Recommended Posts