Author Topic: Elite Dangerous: code for fleet carrier jump countdown time  (Read 2168 times)

Landorin

  • Newbie
  • *
  • Posts: 2
Elite Dangerous: code for fleet carrier jump countdown time
« on: September 16, 2023, 03:16:23 PM »
Hi,

I used Voiceattack for years with those HCS voice packs for Elite. Yet I started to dive deeper into VA thanks to the EliteVA plugin. Amazing what VA can do... due to that I like to add more chatter or music to events happening in game.

I pulled my hair out (mostly due to formatting errors in VA) on calculating the exact fleet carrier jump countdown/remaining time to the second to script more chatter/music around the jump sequence. Given the fact how painful it was and how much time I spent on it I figured I should publish this to possibly save someone else the pain. After a few tests it seems to work fine. Note:
- the hour/min/sec of the carrier jump are pulled from the EliteAPI event (by using the EliteVA plugin, found at https://github.com/Somfic/EliteVA).
- the code assumes the total time till jump is under an hour (yet the code can easily be adapted from what you see here).
- for some reason the calculated result is the countdown shown ingame plus 1 minute. Looking at the control output it looks correct on the second, however. Still have to test an actual jump.

Here it goes:
Code: [Select]
Set integer [departureHour] value to the converted value of {TIMEHOUR24:EliteAPI.CarrierJumpRequest.DepartureTime}
Set integer [departureMinute] value to the converted value of {TIMEMINUTE:EliteAPI.CarrierJumpRequest.DepartureTime}
Set integer [departureSecond] value to the converted value of {TIMESECOND:EliteAPI.CarrierJumpRequest.DepartureTime}
Set integer [MinuteNow] value to the converted value of {EXP:{TIMEMINUTE}}
Set integer [SecondNow] value to the converted value of {EXP:{TIMESECOND}}
Begin Integer Compare : [departureMinute] Is Greater Than [MinuteNow]
    Set integer [minutesToDeparture] value to the converted value of {EXP:({INT:departureMinute} )  - {INT:MinuteNow}}
    Begin Integer Compare : [departureSecond] Is Greater Than [SecondNow]
        Set integer [secondToDeparture] value to the converted value of {EXP:({INT:departureSecond} )  - {INT:SecondNow}}
    Else
        Set integer [secondToDeparture] value to the converted value of {EXP:({INT:departureSecond} ) -  {INT:SecondNow} + 60}
    End Condition
Else
    Set integer [minutesToDeparture] value to the converted value of {EXP:({INT:departureMinute} )  +60 - {INT:MinuteNow}}
    Set integer [secondToDeparture] value to the converted value of {EXP:({INT:departureSecond} )  +60 - {INT:SecondNow}}
    Begin Integer Compare : [departureSecond] Is Greater Than [SecondNow]
        Set integer [secondToDeparture] value to the converted value of {EXP:({INT:departureSecond} )  - {INT:SecondNow}}
    Else
        Set integer [secondToDeparture] value to the converted value of {EXP:({INT:departureSecond} ) -  {INT:SecondNow} + 60}
    End Condition
End Condition
Say, 'Countdown {INT:minutesToDeparture} minutes {INT:secondToDeparture} seconds '
Write (overwrite), 'Time now is: {EXP:{TIMEHOUR24}} : {EXP:{TIMEMINUTE}} : {EXP:{TIMESECOND}}
Departure time: {INT:departureHour} : {INT:departureMinute} : {INT:departureSecond}
Countdown  {INT:minutesToDeparture} minutes {INT:secondToDeparture} seconds'

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4647
  • RTFM
Re: Elite Dangerous: code for fleet carrier jump countdown time
« Reply #1 on: September 17, 2023, 03:29:28 AM »
Good that you achieved a working command using native actions.


Personally, I tend to use inline functions to deal with math that involves time, as that allows the use of the .NET TimeSpan class (while DateTime, the underlying class for the VoiceAttack Date/Time variable type, represents a given point in time, TimeSpan represents a duration), E.G.
Code: [Select]
Inline C# Function: Calculate delta to departure, wait until execution finishes
Set text [~formatString] to 'HH : mm : ss'
Say, 'Countdown {INT:minutesToDeparture} minutes {INT:secondsToDeparture} seconds'
Write (overwrite), 'Time now is: {DATETIMEFORMAT:~dateTimeFormat}\r\nDeparture time: {DATETIMEFORMAT:EliteAPI.CarrierJumpRequest.DepartureTime:~dateTimeFormat}\r\nCountdown  {I...

where "Calculate delta to departure" contains
Code: [Select]
using System;

public class VAInline
{
public void main()
{
DateTime departureTime = VA.GetDate("EliteAPI.CarrierJumpRequest.DepartureTime") ?? DateTime.MinValue;
if (departureTime == DateTime.MinValue)
{
VA.WriteToLog("\"EliteAPI.CarrierJumpRequest.DepartureTime\" has not been set", "red");
return;
}
TimeSpan deltaToDeparture = departureTime - DateTime.Now;

VA.SetInt("minutesToDeparture", deltaToDeparture.Minutes);
VA.SetInt("secondsToDeparture", deltaToDeparture.Seconds);
}
}

And the "Write Text to a File" action at the end contains
Code: [Select]
Time now is: {DATETIMEFORMAT:~formatString}
Departure time: {DATETIMEFORMAT:EliteAPI.CarrierJumpRequest.DepartureTime:~formatString}
Countdown  {INT:minutesToDeparture} minutes {INT:secondsToDeparture} seconds

Note that the output will be zero-padded (E.G. "00 : 01 : 01"). If you'd prefer it as in your example (E.G. "0 : 1 : 1"), use "H : m : s" as the format string instead.
« Last Edit: September 17, 2023, 08:21:52 AM by Pfeil »

Landorin

  • Newbie
  • *
  • Posts: 2
Re: Elite Dangerous: code for fleet carrier jump countdown time
« Reply #2 on: September 17, 2023, 07:17:58 AM »
Hey,

thank you for that great example! Guess I have a new thing (inline functions) to look at next. Your example will definitely help me on that research! I agree, the maths part felt a bit painful in VA, especially getting the syntax always right.