Log in

View Full Version : [REQ] User script for regular sonar checks


Abd_von_Mumit
08-31-10, 10:20 AM
<EDIT>
The script is ready and works well, check the thread further.
</EDIT>



I can't script. I just can't. I would love to have this script though:

1. Every [period] if not submerged, dive to 20 m depth.
2. When at 18m depth, switch engines off.
3. Wait 2 minutes.
3a OPTIONAL, if possible: if sonar guy detects anything, do something (like 'play a sound', 'go to TC1')
4. Surface.
5. When on surface, switch engines on for speed of X.

What you think? Anybody capable and willing to make it?

KarlKoch
08-31-10, 10:51 AM
Just look at the automation feature in TheDarkWraith's UI mod. I think this will do just what you want.

Abd_von_Mumit
08-31-10, 02:15 PM
Just look at the automation feature in TheDarkWraith's UI mod. I think this will do just what you want.

Well, just looked. Now I'll repost what I said in my first post: "I can't script. I just can't." I see bunch of defs and other thingies and I don't know what do do with them. :nope: This is why I started this thread.

Trevally.
08-31-10, 02:28 PM
[AS]
No hassle Hydrophone check
[CATEGORY]
Search on patrol
[COMMANDS]
Set_Time_Compression,2,0,0,0,0,0,0
Ahead_standard,0,0,0,0,0,0,0
Activate_NavMap_Station,0,0,0,0,0,0,0
Set_new_depth,30,0,0,0,0,0,40
All_stop,0,0,0,0,0,0,5
Hydrophone_normal_sweep,0,0,0,0,0,0,20
Report_nearest_sound_contact,0,0,0,0,0,0,20
Ahead_standard,0,0,0,0,0,0,1
Surface,0,0,0,0,0,0,5
Set_Time_Compression,128,0,0,0,0,0,7200
Loop,12,0,0,0,0,0,0
Set_Time_Compression,0,0,0,0,0,0,5
[COMMANDS_END]

Copy and paste this into sh5\data\automation\?????.sha

remember to save:up:


Or install this http://www.filefront.com/17252061/Sonar Check Script.rar Check Script.rar

Abd_von_Mumit
08-31-10, 04:23 PM
Thank you VERY much. :salute:

Will try it as it is, but I already see I have some doubts, If you don't mind I'd like to understand it before I demand my men understand it as well. :)

Set_Time_Compression,2,0,0,0,0,0,0
Why set time compression? Couldn't it just run in any time compression user started it?

Ahead_standard,0,0,0,0,0,0,0
Could it be speed given in knots instead of steps? I travel at most fuel efficient speed of 7.5 and I want it to stay this way. How to specify it?

Activate_NavMap_Station,0,0,0,0,0,0,0
Why activate? Couldn't the script just run in any station I'm currently in? I hate when scripts move me. :D

Set_new_depth,30,0,0,0,0,0,40
Which values do I change to set it to 20 metres?

All_stop,0,0,0,0,0,0,5
Seems clear, but what is the 5 in the end?

Hydrophone_normal_sweep,0,0,0,0,0,0,20
Report_nearest_sound_contact,0,0,0,0,0,0,20
20? :D

Ahead_standard,0,0,0,0,0,0,1
1?

Surface,0,0,0,0,0,0,5
5?

Set_Time_Compression,128,0,0,0,0,0,7200
Seems I understand the 128 value. :D But what is 7200? Looks like 2 hours expressed in seconds.

Loop,12,0,0,0,0,0,0
12?

Set_Time_Compression,0,0,0,0,0,0,5

Also - can it be made to drop TC to 1 and/or play a sound when anything is heard in hydrophone?

I'd love to understand more of this, but I don't even know where to look for info. :06:


EDIT: I chose the easy way and installed your mod. Thanks again. :D Will probably corrupt it by trying to edit, hehe.

Abd_von_Mumit
08-31-10, 05:24 PM
Testing happily. Still don't understand it all. As for now I shortened it to this:

Set_new_depth,30,0,0,0,0,0,50
All_stop,0,0,0,0,0,0,5
Hydrophone_normal_sweep,0,0,0,0,0,0,20
Report_nearest_sound_contact,0,0,0,0,0,0,20
Surface,0,0,0,0,0,0,50
Ahead_standard,0,0,0,0,0,0,1
Loop,12,0,0,0,0,0,0
Set_Time_Compression,1,0,0,0,0,0,5

EDIT: And it simply doesn't work at all. :D I must have messed it up too much.

TheDarkWraith
08-31-10, 05:26 PM
look in the file \data\Automation\TDW_Automation.SHA (you can open it with Notepad). It will explain every command, the syntax of the commands, and tell you how to make your own scripts.

Abd_von_Mumit
08-31-10, 05:38 PM
look in the file \data\Automation\TDW_Automation.SHA (you can open it with Notepad). It will explain every command, the syntax of the commands, and tell you how to make your own scripts.

Kha! I was checking wrong file before to find tips on scripting. Thanks.

Abd_von_Mumit
08-31-10, 05:54 PM
As for now I got this:

[AS]
Quick hydrophone check
[CATEGORY]
Search on patrol
[COMMANDS]
Activate_NavMap_Station,0,0,0,0,0,0,1
Set_Time_Compression,128,0,0,0,0,0,1
Set_new_speed,7.5,0,0,0,0,0,1
Set_new_depth,20,0,0,0,0,0,60
All_stop,0,0,0,0,0,0,5
Hydrophone_normal_sweep,0,0,0,0,0,0,120
Report_nearest_sound_contact,0,0,0,0,0,0,1
Surface,0,0,0,0,0,0,60
Set_new_speed,7.5,0,0,0,0,0,1
Loop,-1,0,0,0,0,0,0
Wait,0,0,0,0,0,0,3240
Set_Time_Compression,128,0,0,0,0,0,1
[COMMANDS_END]

Is there any way to add IFs?

Trevally.
08-31-10, 06:26 PM
Looks good:up:

You need to swap the "loop" with the "wait".

Or you could add your wait time to the end of the second "set_speed" and remove the "wait" and last "set_time"

TheDarkWraith
08-31-10, 06:28 PM
As for now I got this:

[AS]
Quick hydrophone check
[CATEGORY]
Search on patrol
[COMMANDS]
Activate_NavMap_Station,0,0,0,0,0,0,1
Set_Time_Compression,128,0,0,0,0,0,1
Set_new_speed,7.5,0,0,0,0,0,1
Set_new_depth,20,0,0,0,0,0,60
All_stop,0,0,0,0,0,0,5
Hydrophone_normal_sweep,0,0,0,0,0,0,120
Report_nearest_sound_contact,0,0,0,0,0,0,1
Surface,0,0,0,0,0,0,60
Set_new_speed,7.5,0,0,0,0,0,1
Loop,-1,0,0,0,0,0,0
Wait,0,0,0,0,0,0,3240
Set_Time_Compression,128,0,0,0,0,0,1
[COMMANDS_END]

Is there any way to add IFs?

The Loop,-1,.... command will cause everything above it to loop indefinitely - the commands below it will never get executed.

I'm adding the ability to declare globals and some conditional testing but it isn't finished yet :yep:

What kind of conditional test were you wanting to perform?

Abd_von_Mumit
08-31-10, 06:38 PM
Thanks guys - just found out that the loop is ill placed. :D

The condition would be: if [any sound contact detected] then [drop TC to 1] and [report nearest contact] and [generally make a lot of noise so that I hear even when washing dishes] and [terminate the script].

TheDarkWraith
08-31-10, 06:55 PM
Thanks guys - just found out that the loop is ill placed. :D

The condition would be: if [any sound contact detected] then [drop TC to 1] and [report nearest contact] and [generally make a lot of noise so that I hear even when washing dishes] and [terminate the script].

ah, that functionality of dropping to TCx would best be put into the command....let me see if I have a parameter available or not......ah, param 5 is open.....what I'll do is add another bit to the sweep hydrophone command (bit 12) that will be set TC to 1 on contact detected

Abd_von_Mumit
08-31-10, 07:05 PM
ah, that functionality of dropping to TCx would best be put into the command....let me see if I have a parameter available or not......ah, param 5 is open.....what I'll do is add another bit to the sweep hydrophone command (bit 12) that will be set TC to 1 on contact detected

Wouldn't it be better and more consistent to set it to TCxOnMessageBoxTextDesiredTCLevel value?


As to the script I came to this so far:
[COMMANDS]
Activate_NavMap_Station,0,0,0,0,0,0,1
Set_Time_Compression,128,0,0,0,0,0,1
Set_new_depth,20,0,0,0,0,0,60
All_stop,0,0,0,0,0,0,5
Report_nearest_sound_contact,0,0,0,0,0,0,10
Surface,0,0,0,0,0,0,60
Set_new_speed,7.5,0,0,0,0,0,3240
Loop,-1,0,0,0,0,0,0
[COMMANDS_END]

If Trevally. doesn't mind I'd publish it after some more testing as a mod. :D


EDIT: Also if you put it into a command, it won't give user ability to terminate the script on an event. Also it won't let them to terminate the script on other contacts (like a plane). You would also need to modify number of options for some commands only, which would be inconsistent, wouldn't you?


EDIT 2: I found a bug: script doesn't recognize that game TC level changed and its [internal?] clock is still set to x128 when the game is for example in TC1.

TheDarkWraith
08-31-10, 07:15 PM
Wouldn't it be better and more consistent to set it to TCxOnMessageBoxTextDesiredTCLevel value?


As to the script I came to this so far:
[COMMANDS]
Activate_NavMap_Station,0,0,0,0,0,0,1
Set_Time_Compression,128,0,0,0,0,0,1
Set_new_depth,20,0,0,0,0,0,60
All_stop,0,0,0,0,0,0,5
Report_nearest_sound_contact,0,0,0,0,0,0,10
Surface,0,0,0,0,0,0,60
Set_new_speed,7.5,0,0,0,0,0,3240
Loop,-1,0,0,0,0,0,0
[COMMANDS_END]

If Trevally. doesn't mind I'd publish it after some more testing as a mod. :D


EDIT: Also if you put it into a command, it won't give user ability to terminate the script on an event. Also it won't let them to terminate the script on other contacts (like a plane). You would also need to modify number of options for some commands only, which would be inconsistent, wouldn't you?


EDIT 2: I found a bug: script doesn't recognize that game TC level changed and its [internal?] clock is still set to x128 when the game is for example in TC1.

change these commands:

Activate_NavMap_Station,0,0,0,0,0,0,1
Set_Time_Compression,128,0,0,0,0,0,1

to:

Activate_NavMap_Station,0,0,0,0,0,1,1
Set_Time_Compression,128,0,0,0,0,1,1

what the second to last 1 says is execute this command only once. This is used in loops where there's no need to be executing the command more than once.

Script will terminate just fine if I add bit 12. All it will do it set TC to 1 if bet 12 is set.

Explain your edit 2 more. I'm not following you.

I won't use parameter 5 for the TC level. I like your suggestion of using TCxOnMessageBoxTextDesiredTCLevel value

Abd_von_Mumit
08-31-10, 07:21 PM
change these commands:

Activate_NavMap_Station,0,0,0,0,0,0,1
Set_Time_Compression,128,0,0,0,0,0,1

to:

Activate_NavMap_Station,0,0,0,0,0,1,1
Set_Time_Compression,128,0,0,0,0,1,1

what the second to last 1 says is execute this command only once. This is used in loops where there's no need to be executing the command more than once.

Copy that, changing.


Explain your edit 2 more. I'm not following you.

When the script is running I press Esc, which drops TC to 1 and switches to first person view. According to game's clock script loop should end/start in, say, 30 more minutes, so I have 30 more minutes to run all around my sub before script switches me back to the map. But the script still runs as if TC was still x128, and interrupts my merry running after 15 seconds instead of 30 minutes.

TheDarkWraith
08-31-10, 07:25 PM
When the script is running I press Esc, which drops TC to 1 and switches to first person view. According to game's clock script loop should end/start in, say, 30 more minutes, so I have 30 more minutes to run all around my sub before script switches me back to the map. But the script still runs as if TC was still x128, and interrupts my merry running after 15 seconds instead of 30 minutes.

that's interesting. I've hooked into the game's TC level function to 'trap' that command so anytime TC level is changed I should get notified of it and take appropriate action (high precision timer gets changed - has nothing to do with the script). I'll have to test your script you posted to see what's going on by pressing the ESC key :hmmm:

It's also ok to have an ending 0 for the command instead of 1. That's just the delay before executing the next command. If 0 then it's sets the minimum time for you (is like 0.1 seconds)

EDIT:

valid bug. Bug is not because of me but because game doesn't follow it's own rules.....nice....ok I'll have to figure out why and how to fix it.......

EDIT 2:

found a solution. Luckily I know this game and it's files pretty well......bug fixed. Fix will appear in v4.2.0 which is ready for release but I'm working on the options migrater now so you don't have to manually redo your options file everytime I release a new version.

Abd_von_Mumit
08-31-10, 08:20 PM
found a solution. Luckily I know this game and it's files pretty well......bug fixed. Fix will appear in v4.2.0 which is ready for release but I'm working on the options migrater now so you don't have to manually redo your options file everytime I release a new version.

That's some good news.


Would these nested loops work?:

[COMMANDS]
Set_new_depth,10,0,0,0,0,0,30
Surface,0,0,0,0,0,0,30
Loop,4,0,0,0,0,0,0
Sing_a_dolphin_song
Loop,-1,0,0,0,0,0,0
[COMMANDS_END]

TheDarkWraith
08-31-10, 08:30 PM
That's some good news.


Would these nested loops work?:

[COMMANDS]
Set_new_depth,10,0,0,0,0,0,30
Surface,0,0,0,0,0,0,30
Loop,4,0,0,0,0,0,0
Sing_a_dolphin_song
Loop,-1,0,0,0,0,0,0
[COMMANDS_END]

in theory yes....but I think I forgot to reset the loop command's counter when it's looped it's x times....checking.....I coded it correctly :D It updates the loop's counter once it has done it's required loops. So yes, the above will work fine :up:

Excellent bug finding also :yeah: Please don't ever hesitate to inform me of any bugs you find :up: Your bug report also exposed another bug that was related to the one you posted :DL It has also been fixed now.

Abd_von_Mumit
08-31-10, 09:03 PM
Glad to be helpful. :)

An issue: Despite the
AutomaticallyOrderRechargeModeUponSurfacing = False
it _sometimes_ recharges upon surfacing, which I very much don't want it to. When I manually surface (non-script), it works properly, recharging doesn't kick in.

Can't track the cause of it. It may be caused by sub not fully surfaced when the script speed command kicks in. I notice it in bad weather, winds of 15 kts

TheDarkWraith
08-31-10, 09:09 PM
An issue: Despite the
AutomaticallyOrderRechargeModeUponSurfacing = False
it _sometimes_ recharges upon surfacing, which I very much don't want it to. When I manually surface (non-script), it works properly, recharging doesn't kick in.

I'll look for cause also :up: Is there a particular script you're using when this happens? What are the weather conditions?

Abd_von_Mumit
08-31-10, 09:58 PM
I'll look for cause also :up: Is there a particular script you're using when this happens? What are the weather conditions?

The last version I posted in this thread.

Weather rough, winds of 15 (you missed an earlier update in the post above).


EDIT: Time to have some sleep. This is the best working version of the script I've found so far (this one doesn't have the recharging issue):

[AS]
Quick hydrophone check
[CATEGORY]
Search on patrol
[COMMANDS]
Activate_NavMap_Station,0,0,0,0,0,1,0
Set_Time_Compression,128,0,0,0,0,1,0
Set_new_depth,20,0,0,0,0,0,60
All_stop,0,0,0,0,0,0,120
Report_nearest_sound_contact,0,0,0,0,0,0,60
Surface,0,0,0,0,0,0,0
Ahead_slow,0,0,0,0,0,0,120
Set_new_speed,7.4,0,0,0,0,0,3240
Loop,-1,0,0,0,0,0,0
[COMMANDS_END]