Lua question involving ship

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: Lua question involving ship

Post by Whicker »

did you also add a target for it to fire at? that part is where I think the AI would take control, change course, and while it has the AI course if a lua action assigns it a mission then that is when I think it would change course to the mission area.

but that's just my hypothesis... based on very little.

no idea about the speed. I'd look at it but A) I don't really know what I am doing and B) I am knee deep in Typhoons SAR code... which is... complicated.

I wonder if the speed is like the manually plotted course? I wonder if there is a similar thing in the speed like "manuallysetspeed" and then the AI won't change it.
Ok just looked, there doesn't look to be anything on speed or throttle like the ManualPlottedCourseWaypoint. And I got the same thing as you - if the ship was on course with a set speed it kept that until it changed to one of the new AI courses for that mission. Might be something wrong there, I bet it is tied to the ManualPlottedCourseWaypoint on the course. I suppose if the AI respects one it should think of them as a pair and respect both.
DWReese
Posts: 2309
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

First, let me say that this is a test scenario, and not a scenario that I was trying to "win." With it, I am attempting to do various things with the program to see how "complicated" I can make my orders (as a scenario designer) and then be able to know the limitations. There have been tremendous advances made by some superior scenario designers (I'm not one of them) and it is nice to know what the limitations are. This was the purpose of this exercise.

I'm not sure that I understand what you are asking about the targets, so I will explain what I have: I set five enemy buildings within reach of the Tomahawks. All were auto-detectable. I set up the ship's mission for the ship to fire two Tomahawks in just one specific building, which it did. After that, the ship did have the other four hostile buildings to shoot at, but it was not assigned to a strike mission, only a plotted mission, and the "Target of Opportunity" option was set to "no." As far as a sub target, which I don't think that you were talking about, there was none.

I am positive that the Speed issue is tied to the plotted course issue, so that nothing will change until the ship reaches its next waypoint. I am also certain that ships could be issued orders as I have suggested, and accomplish what I said. I'm not certain whether this is a design flaw, or perhaps a simple workaround that allows this function to work. It would be interesting to see if there are any "official" scenarios that have ships (or subs) have a speed and direction but no actual plot is observable. If there are, then this was designed. If not, then this was likely some kind of error which wasn't ever addressed because doing what I have been attempting to do is so rare, and complex, that it was never really necessary to address it.

Doug

DWReese
Posts: 2309
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Wayne,

The manual Override is an interesting theory. I have never messed with that, so I thought that I would put it to the test.

First, since the ship was plotted before it is given the Land Strike Mission, it has to have a course plot and a speed. If you remove the plot at that point, as expected, the speed drops to zero. So, that can't happen before the launch.

After the ship has been given the land Strike Mission if you remove the Manual Override, then the ship races up to 30 kts and heads toward the target which is way far away. Any ships or subs around would hear it for sure, so I don't know if that is the best thing to do since the Tomahawks don't need any extra legs to reach the target.

If you do as I said and remove the course plot, and also remove the Manual Override button, then the sub stops moving, similar to the situation above where it had no course or direction. If you remove the course, and leave the Manual Override button on, then the ship will still proceed toward the target, but at the same speed that you set.

If the ASW Mission kicks in, and the Override button is on, then the sub will stay at 10 kts. (as designed before) until it reaches the patrol zone. If, however, there is a way to remove the manual Override button via programming (or set the speed to 20 kts.) then the sub will proceed to the patrol zone at 20 kts. Once there, with the speed issue already addressed, the ship automatically goes to 5 kts to begin searching.

So, I don't know that removing the Manual Override is the best method unless it can be done when the ship is assigned to the ASW Mission.

Doug
DWReese
Posts: 2309
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

So, I have another way of doing it without wiping out the plotted course.

Instead of making the plotted course so far away, I shortened the plotted course to end prematurely and timed it with roughly the same time that the Land Strike will hit the target. That way, when the ship hits the end point of its course, it will head to the patrol zone. It works perfect. In fact, it automatically speeds up to 20 kts, and drops to 5 kts once it's in the zone.

One point of interest is that a ship (or presumably a sub) will disregard its intended path if it is attacking something, and make a beeline toward the target,drawing a new path to the target from its current position. Once the attack is over, that path vanishes and it reverts back to its original path. When the original path comes to an end, then it will head to its new (ASW) mission. So, the trick is to manipulate the end of the path, and make it coincide with the new mission.

Problem resolved.

Thanks to both of you for getting me through the syntax error, the spelling error, and the path/speed error.

Doug

User avatar
stilesw
Posts: 1569
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Doug,

Re the manual override. Initially setting the speed that you want can be tricky. One way is to create the course and set the speed which will check the override box. Let the scenario run for a short time while the USS Jacksonville gets up to speed and then uncheck the box. It should continue at that speed from then on.

The second method, which I prefer, is to use Lua to do the same thing. Again, set up the mission - the box will be checked and the speed will start at 0. Then, at the start of the scenario (trigger when scenario is loaded or after a short time (1 minute) execute the following:

ScenEdit_SetUnit({side="Side A", unitname="USS Jacksonville", manualSpeed='OFF'})
ScenEdit_SetUnit({side="Side A", unitname="USS Jacksonville", manualSpeed=20})


This turns off the manual setting and sets desired speed. I've used this several times (after much experimentation) to overcome course start/stop and speed issues.

Give it a shot and see if it helps.

-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
User avatar
stilesw
Posts: 1569
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Hey Doug,

Just thought of another option which could obviate all the problems. Instead of having a plotted course for the USS Jacksonville you could change Land Strike to a ASuW patrol mission with the patrol area somewhere towards the end of the current plotted path. Set the speed/doctrine you want, and assign the Jacksonville to it. It will automatically start at the speed you want and continue towards the area until your trigger (time or some event) changes the Jacksonville to the Sub Search mission.

This will probably work much more smoothly to do what you want. Again, please let me know what happens.

-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
DWReese
Posts: 2309
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Wayne,

I did (obviously) receive your messages, but I have been a little tied up....errands, etc. I will look at it in a couple of hours. They look like great suggestions.

The thing that I have observed, which is what I wanted, is to learn various methods for being able to utilize these new concepts to create my scenarios. I believe that we have all learned the basics, but some people (not me as of yet) have managed to use methods to make the scenarios even more realistic. The Northern Fury scenarios, which I just started playing, utilizes helos to transport troops in the very first scenario. The helos drop off their troops and I think that that is so cool. When you compare the most current scenarios to those created just a few years ago you can see a huge difference. People are becoming quite creative. So, this is the reason that I wanted to try to tie two different missions to the same ship. I have done that with planes, so that's why I wanted to do this particular one. When I settle on the best method, then I will record that idea in my mind for future use.

These scenario creators today are really quite innovative.

Thanks, and I will report back to you in a few hours when I have an opportunity to do so.

Doug
DWReese
Posts: 2309
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Hi Wayne,

Thanks again for all of your suggestions.

The Manual Override for the Speed is tricky. Generally, it will work. Since this is not an actual scenario, just an experimental exploration of one, we don't have to decide to do select anything. Again, this was mt preferred way, but the Override seems to be a little too unpredictable for me. So, I think that I would use this as an alternative means of accomplishing the goal.

The Lua Script will definitely work, and will accomplish exactly what I want. The only thing about it is that it may be more cumbersome than I actually need. So, if I were unable to accomplish the mission any other (simpler) way, then I would use the Lua Script. The only downside, as you saw firsthand with me, is that a small syntax (or spelling) error will keep the whole thing from working. So, while this is the most certain means of accomplishing what I want, it also has the greatest chance of me spending way too much time trying to figure it out. In other words, it may be more complicated than I need.

Your final suggestion was, as you indicated, probably the easiest and the best. By sending the ship on a long-range ASuW Mission we know that it will never reach its area before it gets diverted to the new ASW Mission. I do have a concern (not with this scenario set up) that if other units are present I would have to make sure that Targets of Opportunity, and other extraneous factors don't come into play. But, this is likely the best method for doing what I wanted. Again, my original idea stemmed from wanting to know if I could interrupt a ship's mission by assigning it to another. Obviously, we have proved that you can. So, all of this was a success.

As the means that I settled upon as of last night (before these suggestions), I simply assigned the ship to the land Strike Mission, but set the course in the general direction of the later-to-be-assigned ASW Mission. While the Speed aspect wasn't perfect, it dd kind of accomplish some of what I wanted. Your suggestions, however, perfected the method.

Thanks again for your help. The spelling error, and the plotted course/speed issue were very interesting. This knowledge will go far in helping me (and possibly others) in knowing how to do this for the future.

Thanks again.

Doug

User avatar
michaelm75au
Posts: 12455
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Lua question involving ship

Post by michaelm75au »

ORIGINAL: stilesw

Doug,

Think I found it! The mission is named "Sub Seach" but the Lua event is ScenEdit_AssignUnitToMission("USS Jacksonville", "Sub Search"). Easy to miss the fact that Seach != Search. Much to my chagrin, I've likely done it hundreds times during my programming life.

Doug,
If the result of the command is checked, it should have returned an error as the mission did not exist. It is always useful to try running suspect Lua scripts in the console. It would have shown the error.
Michael
User avatar
stilesw
Posts: 1569
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Lua question involving ship

Post by stilesw »

Doug,

Michael is exactly correct and that's how I found the spelling problem. Executing the command in the Lua console immediately showed that the mission did not exist.

Very glad to have been able to help and feel free to ask other questions. I am not the Lua expert that Michael is but I do a fair job of researching programming syntax and creating scripts for my scenarios and the Gulf War DLC I am working on.

-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
DWReese
Posts: 2309
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Lua question involving ship

Post by DWReese »

Executing the command in the Lua console

Wayne (and Michael),

I'm sorry to say but I have absolutely no idea what that means. The best that I can manage thus far is to copying and existing script and then change the names to make it fit what I am attempting to do.

In any case, we got it working.

I assume, that since we have given successive Missions to planes and ships, that it can also be done in the same manner with subs. I do see that adding a third dimension might be another hurdle, but it can likely be accomplished.

Thanks again.

Doug
User avatar
michaelm75au
Posts: 12455
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Lua question involving ship

Post by michaelm75au »

Use the Lua Console from the Editor list (near bottom of it), and you can usually just paste in the Lua code to test.
Michael
Post Reply

Return to “Lua Legion”