Miner Script - Identifying NPC by Name/Type

Hi there!

I’m looking to modify the miner script. If during mining, an NPC fraction/hauler/dread/carrier/etc. spawn appears, I would like to have my miner audibly ping me so that I can bring in combat ships. The only part I’m having issues with is identifying the NPCs by Type or by Name (I’ve been testing the script on regular NPCs to no success).

So far I’ve been attempting to modify the script of various forum posts utilizing ‘RegexMatchSuccessIgnoreCase’. Currently I am testing my methods with a common asteroid belt npc (Sansha’s Servant) with the following as my current (not working) result:

var Measurement = Sanderling?.MemoryMeasurementParsed?.Value;

var ListOverviewSpecialNPC =
Measurement?.WindowOverview?.FirstOrDefault()
?.ListView?.Entry?.Where(entry => entry.Name.RegexMatchSuccessIgnoreCase(“sansha’s servant”))?.ToArray();

In which I attempt to populate a list of overview entries with the name of “sansha’s servant”, and later I check if ListOverviewSpecialNPC.Length > 0 and if so, play an audio file (I have confirmed that the audio file is working). Also, apologies if the code I provided is bad, as I have limited coding experience.

I don’t mean to ask you all to write the code for me, but someone could point me in the right direction I would be very grateful!

Thanks in advance!

Welcome @Scouter!

The overall approach seems reasonable to me.

Looks like there is just a detail missing:
To implement this you can use an if statement.

I took the code you posted and completed it.
I also simplified the code a bit so it can be used as a general example for people.

Following is the complete code to play a sound if a matching entry is in the overview:

// To adapt this to your use case, adapt the string literal in the code below to the values which you see in the `Name` property for the overview entries you want to react to.

var alarmingOverviewEntries =
	Sanderling?.MemoryMeasurementParsed?.Value?.WindowOverview?.FirstOrDefault()
	?.ListView?.Entry?.Where(entry => entry.Name.RegexMatchSuccessIgnoreCase("pith"))
	?.ToList();

if(0 < alarmingOverviewEntries?.Count())
{
	//	Play one of the standard sounds. To play custom sounds, you can use System.Media.SoundPlayer.
      System.Media.SystemSounds.Beep.Play();
}

Pro tip: If you want to have the bot check this again repeatedly, put the whole thing in a loop.

Hi @Viir ! Thank you very much, this is exactly what I was looking for! I really appreciate the help, the code works beautifully now!