Lua Help--Weapons depletion and withdrawal
Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command
Lua Help--Weapons depletion and withdrawal
I'd like some help with Lua, please. I know very little about it.
In a scenario that I am working on, the US CSG has just fended off an extensive airstrike from its enemy. The enemy has RTB, obviously to re-arm. That should take some time, but there is nothing to say that the enemy doesn't have another wave coming. Therefore, the CSG is now essentially naked, having expended all of it RIM-174 missiles. While they could still fulfill their offensive mission, any attack on them will have dire consequences.
My questions: Is is possible to create a Lua script that gauges the entire arsenal of the CSG? In other words, if the RIM-174 missiles within the CSG falls below X-amount, then the CSG is assigned a new mission (which is to retreat and return to another spot on the globe)? I believe that this could be done, but I don't know how.
Is there someone who could show me (heck, do it for me)? Use any scenario that you like, I have them all. I am interested in seeing an example that I can use and apply to my scenario. I can adopt it to mine after I see what the script should look like.
Thanks in advance.
Doug
In a scenario that I am working on, the US CSG has just fended off an extensive airstrike from its enemy. The enemy has RTB, obviously to re-arm. That should take some time, but there is nothing to say that the enemy doesn't have another wave coming. Therefore, the CSG is now essentially naked, having expended all of it RIM-174 missiles. While they could still fulfill their offensive mission, any attack on them will have dire consequences.
My questions: Is is possible to create a Lua script that gauges the entire arsenal of the CSG? In other words, if the RIM-174 missiles within the CSG falls below X-amount, then the CSG is assigned a new mission (which is to retreat and return to another spot on the globe)? I believe that this could be done, but I don't know how.
Is there someone who could show me (heck, do it for me)? Use any scenario that you like, I have them all. I am interested in seeing an example that I can use and apply to my scenario. I can adopt it to mine after I see what the script should look like.
Thanks in advance.
Doug
-
boogabooga
- Posts: 1021
- Joined: Wed Jul 18, 2018 12:05 am
RE: Lua Help--Weapons depletion and withdrawal
Should be do-able.
Please post a scenario and I will give it a try.
Please post a scenario and I will give it a try.
The boogabooga doctrine for CMO: Any intentional human intervention needs to be able to completely and reliably over-ride anything that the AI is doing at any time.
RE: Lua Help--Weapons depletion and withdrawal
The scenario is the Fiery Cross scenario by BeruitDade, which is located in the new scenarios section. The US CSG will get attacked with LOTS of ASM weapons, but should withstand the various attacks. It will leave them drained, but still able to fulfill their offensive mission. As I indicated, I'm not sure that a commander would leave the CSG in Harm's Way, knowing that most of its defensive weapons have been exhausted. So,....
what I would like to see is something that says that if certain DEFENSIVE weapons, such as the RIM-174 are depleted, or hit a certain low level, that the CSG aborts its mission and heads out of the area (any spot far away will do.)
Additionally, if that isn't enough fun, I wouldn't mind seeing some kind of randomizer (which I could probably handle) that doesn't make the above happen IMMEDIATELY. Instead, the CSG continues on, but every hour, the likelihood of the withdrawal increases. It could be when it first occurs, you have a 25 percent chance of withdrawing. One hour later, you have a 35 percent chance, etc. It might make it interesting because the group could essentially be recalled. It would be like Washington pulling the rug out from underneath the commander. It would make for an interesting game, and it would be challenging.
Thanks for your offer.
If you can get to it fine, if you are busy, then you can just disregard. I won't be upset about it.
Doug
what I would like to see is something that says that if certain DEFENSIVE weapons, such as the RIM-174 are depleted, or hit a certain low level, that the CSG aborts its mission and heads out of the area (any spot far away will do.)
Additionally, if that isn't enough fun, I wouldn't mind seeing some kind of randomizer (which I could probably handle) that doesn't make the above happen IMMEDIATELY. Instead, the CSG continues on, but every hour, the likelihood of the withdrawal increases. It could be when it first occurs, you have a 25 percent chance of withdrawing. One hour later, you have a 35 percent chance, etc. It might make it interesting because the group could essentially be recalled. It would be like Washington pulling the rug out from underneath the commander. It would make for an interesting game, and it would be challenging.
Thanks for your offer.
If you can get to it fine, if you are busy, then you can just disregard. I won't be upset about it.
Doug
-
boogabooga
- Posts: 1021
- Joined: Wed Jul 18, 2018 12:05 am
RE: Lua Help--Weapons depletion and withdrawal
I've looked at the scenario and I'm confused as to what you want.
Do you want to play from the 'US-Allies' side? It seems that the CSG is already on the that side. Usually, that kind of specific LUA scripting is done for the computer-controlled sides, since the player can do that themselves. But, I could try to automate something anyway...
Do you want to play from the 'US-Allies' side? It seems that the CSG is already on the that side. Usually, that kind of specific LUA scripting is done for the computer-controlled sides, since the player can do that themselves. But, I could try to automate something anyway...
The boogabooga doctrine for CMO: Any intentional human intervention needs to be able to completely and reliably over-ride anything that the AI is doing at any time.
RE: Lua Help--Weapons depletion and withdrawal
I would like to set this up for the computer to make this happen. It could be for either side. If the Event occurs, then the CSG is sent home (out of the area). So, regardless of which side the game player is playing, the CSG gets recalled after its weapons have been depleted AND the random timer event occurs.
As the game player, you will get a message that, per orders from Washington, the CSG must withdraw from the area and proceed to "Area X." The CSG could continue to launch its Tomahawks and planes, but it must head in the opposite direction and "get out of Dodge City" to protect itself.
I hope that I expressed this well enough. It's just a method to FORCE the CSG to retreat rather than die.
Doug
As the game player, you will get a message that, per orders from Washington, the CSG must withdraw from the area and proceed to "Area X." The CSG could continue to launch its Tomahawks and planes, but it must head in the opposite direction and "get out of Dodge City" to protect itself.
I hope that I expressed this well enough. It's just a method to FORCE the CSG to retreat rather than die.
Doug
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Lua Help--Weapons depletion and withdrawal
My questions: Is is possible to create a Lua script that gauges the entire arsenal of the CSG? In other words, if the RIM-174 missiles within the CSG falls below X-amount, then the CSG is assigned a new mission (which is to retreat and return to another spot on the globe)? I believe that this could be done, but I don't know how.
Is there someone who could show me (heck, do it for me)? Use any scenario that you like, I have them all. I am interested in seeing an example that I can use and apply to my scenario. I can adopt it to mine after I see what the script should look like.
Example Scene demo'ing this attached, it's not F.C.Reef, but it should do to show you how it's done.
Scene Description:
Scenario to demo counting munition totals on a group of units and taking an action based on the count.
Blue is player
Red is AI
Upon group SAG_1 munition count of weapon #3714 (RIM 174A-IB) 's falling below a certain level (150) not counting mag stores, it will change it's mission from Blue_SAG_1 to Blue_SAG_2, and the enemy missions will also be flagged inactive, they're wra to hold and their bombers rtb'd. Additionally the event used to count every few seconds is then disabled.
So if you want to start over either manually re-mark it active again, and undo the wra changes for red mission_1 and reassign blue sag back to blue_sag_1 mission, or save yourself the trouble ... just reload scene. [:)]
The meat of the code is contained in the global function startup scripts, two of which come from my quasi library api so it's why things are named the way they are, can change'em up if you like, but if your very new to lua then I advise just leaving it. 3 functions are there, 1 does the raw counting on a unit, 1 wraps that for use while counting a group as a whole, and the 3rd one is specific to the scene and just handles the 'what to do when something falls below the given threshold'.
There is 1 other event that triggers every 5 seconds, it makes calls those and if necessary the one for reacting to the limit being breached.
Play the scene in editor and just watch for about ~10-15min (x2 should be fine), i've Jerry-rigged all settings for units and wra such that neither side should lose any units in the missile exchanges. Basically Red will send out a lrasm attack on the Blue SAG group and when the 174\IB's get to 150 or below you should receive a popup message box letting you know it's been reached. That's just there for debugging so you know when it happens so you can note the changes that get made after pressing 'ok', you can comment out the code that generates it.
-KH
Requires: CMO build 1147.11+ DB3k487
Zip Contains:
TestRig_CountUnitMunitionsTest_v1_db487.scen --The scene file.
TestRig_CountUnitMunitionsTestv1_StartupAction.txt -- The code for the startup action\event containing global functions.
TestRig_CountUnitMunitionsTestv1_Every5SecondsAction.txt --simple lua action code that goes in a run-every-5-seconds event.
The later two are not needed, they're included because sometimes people have pro or an older version and end up asking because they just want to look at the script code without loading the scen file.
- Attachments
-
- TestRig_Co..v1_db487.zip
- (111.69 KiB) Downloaded 16 times
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Lua Help--Weapons depletion and withdrawal
ORIGINAL: DWReese
I would like to set this up for the computer to make this happen. It could be for either side. If the Event occurs, then the CSG is sent home (out of the area). So, regardless of which side the game player is playing, the CSG gets recalled after its weapons have been depleted AND the random timer event occurs.
As the game player, you will get a message that, per orders from Washington, the CSG must withdraw from the area and proceed to "Area X." The CSG could continue to launch its Tomahawks and planes, but it must head in the opposite direction and "get out of Dodge City" to protect itself.
I hope that I expressed this well enough. It's just a method to FORCE the CSG to retreat rather than die.
Doug
I think I understand what you want. But anyone who doesn't want to listen to these orders will just undo them anyway, so it seems maybe a pointless exercise\effort to force it. I mean one could script something that could constantly over-ride the players desires and constantly reset it's course toward some point, but why bother when you could just incentivize them with points or some other reward (free unit or free reloads or something) for obeying orders to get their ship to the new out-of-the-way location. I know if I came across that the first thing I would do is pop in the editor and disable it, even if I was going to obey, but maybe I'm just p_rickly like that [;)].
But putting aside the why, what you want can definitely be accomplished.
pseudo code:
EveryXYZTimeInterval:
if getSomeCSGCountofWeaponX() < Y then
dicerollresult = diceroll()
if dicerollresult >= Z then
--Show special message to user.
--doStuff-ChangeToOutOfWayMissionAndForceNewCourse()
--enableSomeOtherEventThatThenConstantlyForcesCourseAndSpeedEveryXXSeconds.
--disableSelf
else
--doNotDoStuffRunAgainNextInterval
end
end
It's really no different then what's in the sample only you're just throwing a diceroll before deciding to do the action function that's already there, and changing what the actions are.
One downside in trying to do this when trying to monitor groups (and it's true for the sample as well) is if a player renames the group things will break, and even if it's re-coded to use group guids where possible instead it will still break if the player dissolves the group\csg and reconstitutes it as it'll get a new guid. Now there are ways around by using your own tables to track what unit guids belong to a 'group' you want tracked and all acted on as such, then you just pray the user listens when in the briefing you tell them to not delete\re-create units.
RE: Lua Help--Weapons depletion and withdrawal
KH,
Thanks again for providing your incredible insight.
What first prompted me to think along these lines was when I was playing the LIVE: Spratly Spat scenario (which I really like) and each side trades most of their missiles, and all that they have left are some SAMs and guns. I believe that each side would turn and head for home. Why? Because whichever side "wins" doesn't really matter because none of the ships are going to stay there. They ALL will have to go back to their own bases at some point. And, given the weapons spent, they are toothless and potential victims to any reinforcements that arrive. Would the sides risk losing the assets to trade shells with other ships? Personally, I don't think so.
I realize that this makes the battles sort of bloodless, but ships are expensive, and merely putting some holes into the sides of some of them with guns seems pointless when they all have to leave. It's not like climbing to the top of a hill and proclaiming that this hill will forever be this side's possession, and then having reinforcements come to make that happen. That doesn't happen in this scenario.
In any case, that's when I thought that it would be more realistic if ships would withdraw when a set of circumstances occur.
I do know that the game has a WITHDRAW function in the WRA, but I've never actually seen it work as I expected it to. That isn't connected to specified weapon. It only states when the PRIMARY weapon is exhausted. Well, I have it be exhaused, and nothing happens. That's why I believed that the Lua scrip could make this happen.
I have downloaded your file, and I will be playing around with it.
Thanks again.
Doug
Thanks again for providing your incredible insight.
What first prompted me to think along these lines was when I was playing the LIVE: Spratly Spat scenario (which I really like) and each side trades most of their missiles, and all that they have left are some SAMs and guns. I believe that each side would turn and head for home. Why? Because whichever side "wins" doesn't really matter because none of the ships are going to stay there. They ALL will have to go back to their own bases at some point. And, given the weapons spent, they are toothless and potential victims to any reinforcements that arrive. Would the sides risk losing the assets to trade shells with other ships? Personally, I don't think so.
I realize that this makes the battles sort of bloodless, but ships are expensive, and merely putting some holes into the sides of some of them with guns seems pointless when they all have to leave. It's not like climbing to the top of a hill and proclaiming that this hill will forever be this side's possession, and then having reinforcements come to make that happen. That doesn't happen in this scenario.
In any case, that's when I thought that it would be more realistic if ships would withdraw when a set of circumstances occur.
I do know that the game has a WITHDRAW function in the WRA, but I've never actually seen it work as I expected it to. That isn't connected to specified weapon. It only states when the PRIMARY weapon is exhausted. Well, I have it be exhaused, and nothing happens. That's why I believed that the Lua scrip could make this happen.
I have downloaded your file, and I will be playing around with it.
Thanks again.
Doug
RE: Lua Help--Weapons depletion and withdrawal
The scenario works perfectly. It did exactly what you indicated. About halfway through the attack the message popped up, and the mission changed.
I would like to add a +1 hour timer to the event. By that, I mean that I would like the first check to occur 1 hour AFTER the threshold has been exceeded. So, if the CSG runs out of ammo at 2:25, then I would like the first check for the new mission to possibly occur at 3:25. Is that possible? Of course, the actual times would be dependent upon the moment when the CSG ACTUALLY runs out (well, depletes) its ammo below the threshold.
Doug
I would like to add a +1 hour timer to the event. By that, I mean that I would like the first check to occur 1 hour AFTER the threshold has been exceeded. So, if the CSG runs out of ammo at 2:25, then I would like the first check for the new mission to possibly occur at 3:25. Is that possible? Of course, the actual times would be dependent upon the moment when the CSG ACTUALLY runs out (well, depletes) its ammo below the threshold.
Doug
-
boogabooga
- Posts: 1021
- Joined: Wed Jul 18, 2018 12:05 am
RE: Lua Help--Weapons depletion and withdrawal
Here is my try at code (beta) specifically for the F.C. mission. This is searching each member of the CSG for all weapons with "RIM-" in the name. 'thresholdRIMS' will determine how many RIMs would be left in the group before retreat is triggered; I have it manually set to 10% of the starting value.
The CMO Event system has triggers, conditions, and actions. The code below is the action. In dealing with the question of the probability that this action will be triggered, I would suggest having that in a separate lua-based condition, rather than dealing with that in the action code itself. Alternately, you can specify the probability of an event occurring directly in the definition of the event.
I'll try to incorporate everything into the scenario and post later.
The CMO Event system has triggers, conditions, and actions. The code below is the action. In dealing with the question of the probability that this action will be triggered, I would suggest having that in a separate lua-based condition, rather than dealing with that in the action code itself. Alternately, you can specify the probability of an event occurring directly in the definition of the event.
I'll try to incorporate everything into the scenario and post later.
x = VP_GetSide({Side ="US-Allies"})
unitsInCSG = {}
thresholdRIMS = 64
totalRIMS = 0
for key, value in pairs(x.units) do
local y = ScenEdit_GetUnit({guid= value.guid})
if y.group ~= nill then
if y.group.name == "CSG 9" then
unitsInCSG[key] = y
print(y.name)
for key_1, value_1 in pairs(y.mounts) do
for key_2, value_2 in pairs(value_1.mount_weapons) do
a,b = string.find(value_2.wpn_name, "RIM-")
--print(a)
--print(b)
if a ~= nill and b ~= nill then
print(value_2.wpn_name.." "..value_2.wpn_current)
totalRIMS = totalRIMS + value_2.wpn_current
end
end
end
print(" ")
end
end
end
print("totalRIMS = "..totalRIMS)
print(unitsInCSG)
if totalRIMS < thresholdRIMS then
if refNew == nil then
refNew = ScenEdit_AddReferencePoint( {side="US-Allies", name="CSG 9 Retreat Point", lat= -5.0, lon= 110.0, highlighted=false})
end
if misNew == nil then
misNew = ScenEdit_AddMission ("US-Allies", "CSG 9 Retreat", "Support", {zone= {refNew.guid} } )
end
ScenEdit_SetMission ("US-Allies", "CSG 9 Retreat", {transitThrottleShip = "flank"})
for key_3, value_3 in pairs(unitsInCSG) do
ScenEdit_AssignUnitToMission(value_3.guid, misNew.name)
end
ScenEdit_SpecialMessage('US-Allies','Less than'..thresholdRIMS..' RIM missiles remain. The CSG will now retreat to the Java Sea')
end
The boogabooga doctrine for CMO: Any intentional human intervention needs to be able to completely and reliably over-ride anything that the AI is doing at any time.
-
boogabooga
- Posts: 1021
- Joined: Wed Jul 18, 2018 12:05 am
RE: Lua Help--Weapons depletion and withdrawal
Okay, for some reason the "code" forum tag makes the code not all fit in the message, but the "quote" tag does not preserve tabs...?
The boogabooga doctrine for CMO: Any intentional human intervention needs to be able to completely and reliably over-ride anything that the AI is doing at any time.
-
KnightHawk75
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Lua Help--Weapons depletion and withdrawal
ORIGINAL: boogabooga
Okay, for some reason the "code" forum tag makes the code not all fit in the message, but the "quote" tag does not preserve tabs...?
The trick there is for about every 12-15 lines of code...separate it and add a new code tag for each 10-15 line chunks, it kinda sucks cause it adds tons of extra white space to the post but it also preserves everything.
Yup that can totally be done, either with a pre-made event that starts disabled gets it's time changed and then enabled - or is just dynamically generated, sounds like boogabooga is working on incorporating a working example for one or the other for you.ORIGINAL: DWReese
The scenario works perfectly. It did exactly what you indicated. About halfway through the attack the message popped up, and the mission changed.
I would like to add a +1 hour timer to the event. By that, I mean that I would like the first check to occur 1 hour AFTER the threshold has been exceeded. So, if the CSG runs out of ammo at 2:25, then I would like the first check for the new mission to possibly occur at 3:25. Is that possible? Of course, the actual times would be dependent upon the moment when the CSG ACTUALLY runs out (well, depletes) its ammo below the threshold.
Doug
Also agree with him containing the probability check inside an event 'condition' is a good idea, I almost used that method myself for the example (where instead the action was just the msgbox+call to missionchange etc, and the if x<=y part was in an event 'condition') but figured I'd keep it as straight forward as possible for the example.
[:)]
On WRA withdrawl stuff...yeah um I try to avoid relying on that too much, I've seen it work ok some times (fuel+damage) and other times not so much, particularly so with the primary\secondary weapons stuff which either I don't understand fully well enough yet or is just very touchy depending on unit and the mission assignment.
RE: Lua Help--Weapons depletion and withdrawal
Boogabooga and KH,
Thank you so much for your efforts. I really look forward to seeing the final product.
B, I sincerely appreciate that you were able to apply it to the scenario itself. That was very helpful.
KH, I've saved yours and I have examined it closely, and I will use it for other scenarios.
Yes, the Withdraw aspect contained in the WRA could be refined to actually deal with this, but right now it is really lacking.
The randomness of the Withdraw is consistent with real life. I like it because it doesn't allow the game player to have TOTAL control of the "battlefield." Obviously, in real life, the actions of generals/admirals/captains are often circumvented by "higher ups." I think that this could make for an interesting concept in scenarios. It sort of pulls the rug out from underneath the player. KH, I agree with you that the player could enter the Editor and change things, but that is is kind of true for every scenario. I would like to add a "point penalty" to ensure that the CSG DOES begin to withdraw. I have an idea about how to do that, but I'm not sure.
I have to mention that this scenario is NOT mine. It was created by Al (BeirutDude), so he deserves the credit. I have only been helping him. He may, or may not include it with his final scenario. In any case, I fully plan to take this information that you guys have provided and apply it to many of the scenarios that I have created. I absolutely believe that having ships withdraw is very realistic. Fighting to the death while slugging it out with guns is a little bizarre to me. I really think that most recognize that it's best to survive to fight another day.
KH, since I am saving your effort as a guide for my group of examples, feel free to revise yours to include as many of these as possible.
B, I plan on really playing Al's scenario with your changes. If it works as I believe that it will, I will encourage Al to keep them. If not, I'm sure that I will keep it for myself for the reasons cited above.
Thanks again to both of you.
Doug
Thank you so much for your efforts. I really look forward to seeing the final product.
B, I sincerely appreciate that you were able to apply it to the scenario itself. That was very helpful.
KH, I've saved yours and I have examined it closely, and I will use it for other scenarios.
Yes, the Withdraw aspect contained in the WRA could be refined to actually deal with this, but right now it is really lacking.
The randomness of the Withdraw is consistent with real life. I like it because it doesn't allow the game player to have TOTAL control of the "battlefield." Obviously, in real life, the actions of generals/admirals/captains are often circumvented by "higher ups." I think that this could make for an interesting concept in scenarios. It sort of pulls the rug out from underneath the player. KH, I agree with you that the player could enter the Editor and change things, but that is is kind of true for every scenario. I would like to add a "point penalty" to ensure that the CSG DOES begin to withdraw. I have an idea about how to do that, but I'm not sure.
I have to mention that this scenario is NOT mine. It was created by Al (BeirutDude), so he deserves the credit. I have only been helping him. He may, or may not include it with his final scenario. In any case, I fully plan to take this information that you guys have provided and apply it to many of the scenarios that I have created. I absolutely believe that having ships withdraw is very realistic. Fighting to the death while slugging it out with guns is a little bizarre to me. I really think that most recognize that it's best to survive to fight another day.
KH, since I am saving your effort as a guide for my group of examples, feel free to revise yours to include as many of these as possible.
B, I plan on really playing Al's scenario with your changes. If it works as I believe that it will, I will encourage Al to keep them. If not, I'm sure that I will keep it for myself for the reasons cited above.
Thanks again to both of you.
Doug