Are you sure you want to report the post shown below? This will send an email to the ATVO administrators. Please include a short reason for reporting.
Users reporting for no reason may be locked out.
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;
using System.Collections.Generic;
using ATVO.ThemesSDK.Data.Enums;
namespace Scripts
{
public class Offtrack : IScript
{
// The time to display the text
private TimeSpan OfftrackShowTime = TimeSpan.FromSeconds(3);
// Store the time when the last offtrack was detected
// Store it separately for each car index
private Dictionary<int, DateTime> _offtrackStartTimes = new Dictionary<int, DateTime>();
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
var result = (IEntitySessionResult)value;
var carIndex = result.Entity.CarIdx;
if (result.Entity.Car.Movement.TrackLocation == TrackLocation.OffTrack)
{
// Update the last detected offtrack time for this car index
_offtrackStartTimes[carIndex] = DateTime.Now;
}
// Check if there is a stored time
if (_offtrackStartTimes.ContainsKey(carIndex))
{
// If the stored time is shorter than the desired OfftrackShowTime, display offtrack
var elapsedTime = DateTime.Now - _offtrackStartTimes[carIndex];
if (elapsedTime < OfftrackShowTime)
{
return "OFFTRACK";
}
}
return "";
}
}
}