using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Collections.Generic;
namespace Scripts
{
public class FastLapTracker : IScript
{
private Dictionary<byte, ILap> _fastlaps = new Dictionary<byte, ILap>();
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Loop over every entity session result and check for fastest lap in class
foreach (var result in sim.Session.Current.Results)
{
// Get the class ID of this driver
var classId = result.Entity.Car.Class.Id;
// Get the currently recorded fastest lap for this driver's class
// Note: the lap may not exist yet, in that case we add an entry for this class but keep the lap as null.
ILap currentFastLap = null;
if (_fastlaps.ContainsKey(classId))
currentFastLap = _fastlaps[classId];
else
_fastlaps.Add(classId, null);
// Get fastest lap of this driver
var lap = result.FastestLap;
// Check if the driver fastlap is faster than the currently stored fast lap
// if there is no lap stored, this is a new lap and we consider it the fastest lap so far
if (currentFastLap == null || currentFastLap.Time > lap.Time)
{
// "lap" is the newest fast lap of this class
// Replace it as the latest fast lap
_fastlaps[classId] = lap;
// Now trigger whatever you want to do, e.g. show a widget.
TriggerFastLap(item.Theme, result, lap);
}
}
}
private void TriggerFastLap(ITheme theme, IEntitySessionResult result, ILap lap)
{
// Just an example: find a widget named after the class ID
var classId = result.Entity.Car.Class.Id;
var widgetName = "Wigdet_Fastlap_Class" + classId;
var widget = theme.Widgets.Find(widgetName);
if (widget != null)
{
widget.Show();
// Maybe start a timer that hides all fastlap widgets after few seconds
var timer = theme.Timers.Find("FastLapHideTimer");
timer.Start();
}
else
{
// Log that this widget doesnt exist
Console.WriteLine("Failed to find widget " + widgetName);
}
}
}
}
widget.AnimateShow("0");
widget.AnimateShow("1000");
CarIdx: 13
UserName: Ian Barron
...
TeamID: 0
TeamName: Ian Barron
CarNumber: "38"
....
// If you bind to 'entity_object':
var entity = (IEntity)value;
// If you bind to 'entitysessionresult_object':
var result = (IEntitySessionResult)value;
var entity = result.Entity;
var id = entity.Id;
var name = entity.Name;
// If it's a team session:
// - id will be Team ID, name will be Team name
// If it's a single driver session:
// - id will be driver customer ID, name will be driver name
// Check if it's a team
if (entity is ITeam)
{
// Team object
var driver = entity.CurrentDriver;
var otherDrivers = entity.Drivers;
}
else
{
// Single driver
var driver = entity.CurrentDriver;
// or this is probably the same:
var driver = (IDriver)entity;
}
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Entity;
using System.Collections.Generic;
using ATVO.ThemesSDK.Data.Results;
namespace Scripts
{
public class Sc_Pilot_Team : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
if (value == null)
{
return null;
}
IEntitySessionResult result = (IEntitySessionResult) value;
var entity = result.Entity;
var theme = item.Theme;
//find widget I want to show
var widget = theme.Widgets.Find("W_Pilote_Team");
//find widget to check VISIBLE for showing widget
var widget0 = theme.Widgets.Find("W_Pilote_Complet");
// Check if it's a team //I test if widget0.IsVisible == true but it is not OK
if (entity is ITeam)
{
widget.AnimateShow("0");
return null;
}
else
return null;
}
}}
Nick Thissen wrote:
// If you bind to 'entitysessionresult_object':
var result = (IEntitySessionResult)value;
var entity = result.Entity;
var id = entity.Id;
var name = entity.Name;
Emmanuel Suter wrote:Yes.
If I understand, if I use this part of code, "var name" will return TeamName if it is a Team Session and Driver Name in other case ?
Emmanuel Suter wrote:entity.Drivers keeps a list of drivers that ATVO observed to get in the car. Unfortunately iRacing does not output a list of the drivers registered in a team, we can only know about a driver currently in the car. So if someone never got in the car yet, he will not make it into the Drivers list.
And if I return otherDrivers in a ticker when this is use : var otherDrivers = entity.Drivers; does it show a driver list ?
Nick Thissen wrote:Sorry, my english an C# are so bad ....
Sorry I'm a bit lost on your earlier (longer) question, I don't know what you're trying to ask.
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Entity;
using System.Collections.Generic;
using ATVO.ThemesSDK.Data.Results;
namespace Scripts
{
public class Sc_Pilot_Team : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
if (value == null)
{
return null;
}
IEntitySessionResult result = (IEntitySessionResult) value;
var entity = result.Entity;
var theme = item.Theme;
//find widget I want to show
var widget = theme.Widgets.Find("W_Pilote_Team");
//find widget to check VISIBLE for showing widget
var widget0 = theme.Widgets.Find("W_Pilote_Complet");
if (widget0.IsVisible == true);
{
if (entity is ITeam)
{widget.AnimateShow("0");
return null;}
else
widget.AnimateHide("0");
return null;
}
}}}
Nick Thissen wrote:
We currently only track the overall session fastest lap, not per class. I am pretty sure also the iRacing data only tracks it globally, not per class. We do log every fastest lap of each driver (actually we log every lap, period) so in theory you could use a script to grab the fastest class lap manually.
I cooked this up quickly with no testing, but something similar should work I think?using System;
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Collections.Generic;
namespace Scripts
{
public class FastLapTracker : IScript
{
private Dictionary<byte, ILap> _fastlaps = new Dictionary<byte, ILap>();
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Loop over every entity session result and check for fastest lap in class
foreach (var result in sim.Session.Current.Results)
{
// Get the class ID of this driver
var classId = result.Entity.Car.Class.Id;
// Get the currently recorded fastest lap for this driver's class
// Note: the lap may not exist yet, in that case we add an entry for this class but keep the lap as null.
ILap currentFastLap = null;
if (_fastlaps.ContainsKey(classId))
currentFastLap = _fastlaps[classId];
else
_fastlaps.Add(classId, null);
// Get fastest lap of this driver
var lap = result.FastestLap;
// Check if the driver fastlap is faster than the currently stored fast lap
// if there is no lap stored, this is a new lap and we consider it the fastest lap so far
if (currentFastLap == null || currentFastLap.Time > lap.Time)
{
// "lap" is the newest fast lap of this class
// Replace it as the latest fast lap
_fastlaps[classId] = lap;
// Now trigger whatever you want to do, e.g. show a widget.
TriggerFastLap(item.Theme, result, lap);
}
}
}
private void TriggerFastLap(ITheme theme, IEntitySessionResult result, ILap lap)
{
// Just an example: find a widget named after the class ID
var classId = result.Entity.Car.Class.Id;
var widgetName = "Wigdet_Fastlap_Class" + classId;
var widget = theme.Widgets.Find(widgetName);
if (widget != null)
{
widget.Show();
// Maybe start a timer that hides all fastlap widgets after few seconds
var timer = theme.Timers.Find("FastLapHideTimer");
timer.Start();
}
else
{
// Log that this widget doesnt exist
Console.WriteLine("Failed to find widget " + widgetName);
}
}
}
}