al531246 Posted December 28, 2016 Posted December 28, 2016 Some of the guys I play with can't get enough of infinite ammo / fuel, but me; I can't stand it. Muh immersion is ruined! Is there a way I can add toggle infinite X to client's aircraft as an F10 radio selection or another way? I can't seem to find a premade trigger for it so I'm guessing it'd have to be done via .lua scripting? Ideally the trigger could be activated by any aircraft occupied by a client...if such a thing is possible. Any ideas? Intel i5-8600k | EVGA RTX 3070 | Windows 10 | 32GB RAM @3600 MHz | 500 GB Samsung 850 SSD
gromit190 Posted December 29, 2016 Posted December 29, 2016 (edited) What you're suggesting is highly possible and not that hard to do (I think). Here's a function to add radio commands: http://wiki.hoggit.us/view/DCS_func_addOtherCommandForGroup I haven't really refilled/refueled with a script before, but I'm pretty confident it is possible. The only "problem" as I see it is that you can't distinguish between players in a group that calls the command to refill/refuel. So if you have a group of 4, and 1 of them calls the refill/refuel command then the whole group will be refilled/refueled. Another challenge is that the command will only be added for groups that are existing (have live players) in your mission. The way I've solved this before is I have a function that is scheduled at time intervals. The function removes the command for all groups (that has it), then re-adds it for all groups that exist (in-game players). Here's the code. EDIT: Here's one way to add the radio command (requires the autogft script, version 1.2 download here). Firstly, load the "autogft-standalone.lua" to your mission. Then load the following script: function enableRefillCommand() local enabledGroupCommands = {} local function cleanEnabledGroupCommands() local newEnabledGroupCommands = {} for i = 1, #enabledGroupCommands do if not Group.getByName(enabledGroupCommands[i].groupName) then enabledGroupCommands[i]:disable() else newEnabledGroupCommands[#newEnabledGroupCommands + 1] = enabledGroupCommands[i] end end enabledGroupCommands = newEnabledGroupCommands end --- -- @param #number groupId local function groupHasCommandEnabled(groupId) for i = 1, #enabledGroupCommands do if enabledGroupCommands[i].groupId == groupId then return true end end return false end --- -- @param DCSGroup#Group group local function groupHasPlayer(group) local units = group:getUnits() for i = 1, #units do if units[i]:getPlayerName() ~= nil then return true end end return false end --- -- @param #list<DCSGroup#Group> groups local function enableForGroups(groups) for i = 1, #groups do local group = groups[i] if groupHasPlayer(group) then if not groupHasCommandEnabled(group:getID()) then local function triggerCommand() -- -- DO THE REFILLING HERE, the "group" variable holds the target group -- end local groupCommand = autogft_GroupCommand:new("Refuel & refill", group:getName(), triggerCommand) groupCommand:enable() enabledGroupCommands[#enabledGroupCommands + 1] = groupCommand end end end end local function reEnablingLoop() cleanEnabledGroupCommands() enableForGroups(coalition.getGroups(coalition.side.RED)) enableForGroups(coalition.getGroups(coalition.side.BLUE)) autogft.scheduleFunction(reEnablingLoop, 5) -- <- Checks for new groups every 5 seconds end reEnablingLoop() end enableRefillCommand() EDIT2: I'm struggling a little to see how you can add fuel/ammo to units from a script :/ Edited December 29, 2016 by gromit190 Autonomous ground AI project
al531246 Posted December 29, 2016 Author Posted December 29, 2016 Many Thanks gromit190, it doesn't matter if an entire group is affected by a script because I can set each aircraft to be in it's own group. I've found a DCS Func to add fuel to a unit but not an ammo script as of yet. Fuel - http://wiki.hoggit.us/view/DCS_func_getFuel I am kinda new to .lua scripting so where would I insert these DCS func scripts? Do they go as a .lua file within the mission file or do I insert them via a trigger inside the mission editor? Intel i5-8600k | EVGA RTX 3070 | Windows 10 | 32GB RAM @3600 MHz | 500 GB Samsung 850 SSD
gromit190 Posted December 29, 2016 Posted December 29, 2016 Many Thanks gromit190, it doesn't matter if an entire group is affected by a script because I can set each aircraft to be in it's own group. I've found a DCS Func to add fuel to a unit but not an ammo script as of yet. Fuel - http://wiki.hoggit.us/view/DCS_func_getFuel I am kinda new to .lua scripting so where would I insert these DCS func scripts? Do they go as a .lua file within the mission file or do I insert them via a trigger inside the mission editor? Actually, this function only returns the fuel of a unit. You can't set it, only "get" it (for printing it to screen or whatever). Sorry :/ Maybe someone else knows how to set the fuel Autonomous ground AI project
MivwTaupos Posted April 30, 2020 Posted April 30, 2020 What you're suggesting is highly possible and not that hard to do (I think). Here's a function to add radio commands: http://wiki.hoggit.us/view/DCS_func_addOtherCommandForGroup I haven't really refilled/refueled with a script before, but I'm pretty confident it is possible. The only "problem" as I see it is that you can't distinguish between players in a group that calls the command to refill/refuel. So if you have a group of 4, and 1 of them calls the refill/refuel command then the whole group will be refilled/refueled. Another challenge is that the command will only be added for groups that are existing (have live players) in your mission. The way I've solved this before is I have a function that is scheduled at time intervals. The function removes the command for all groups (that has it), then re-adds it for all groups that exist (in-game players). Here's the code. EDIT: Here's one way to add the radio command (requires the autogft script, version 1.2 download here). Firstly, load the "autogft-standalone.lua" to your mission. Then load the following script: function enableRefillCommand() local enabledGroupCommands = {} local function cleanEnabledGroupCommands() local newEnabledGroupCommands = {} for i = 1, #enabledGroupCommands do if not Group.getByName(enabledGroupCommands[i].groupName) then enabledGroupCommands[i]:disable() else newEnabledGroupCommands[#newEnabledGroupCommands + 1] = enabledGroupCommands[i] end end enabledGroupCommands = newEnabledGroupCommands end --- -- @param #number groupId local function groupHasCommandEnabled(groupId) for i = 1, #enabledGroupCommands do if enabledGroupCommands[i].groupId == groupId then return true end end return false end --- -- @param DCSGroup#Group group local function groupHasPlayer(group) local units = group:getUnits() for i = 1, #units do if units[i]:getPlayerName() ~= nil then return true end end return false end --- -- @param #list<DCSGroup#Group> groups local function enableForGroups(groups) for i = 1, #groups do local group = groups[i] if groupHasPlayer(group) then if not groupHasCommandEnabled(group:getID()) then local function triggerCommand() -- -- DO THE REFILLING HERE, the "group" variable holds the target group -- end local groupCommand = autogft_GroupCommand:new("Refuel & refill", group:getName(), triggerCommand) groupCommand:enable() enabledGroupCommands[#enabledGroupCommands + 1] = groupCommand end end end end local function reEnablingLoop() cleanEnabledGroupCommands() enableForGroups(coalition.getGroups(coalition.side.RED)) enableForGroups(coalition.getGroups(coalition.side.BLUE)) autogft.scheduleFunction(reEnablingLoop, 5) -- <- Checks for new groups every 5 seconds end reEnablingLoop() end enableRefillCommand() EDIT2: I'm struggling a little to see how you can add fuel/ammo to units from a script :/ hello, so what is the code would be if my target group name is Tanker?
Recommended Posts