Let's Build a Elder Scrolls Online Mod - Part 3

Picture shows Jason A. Martin - Software Engineer, Indie Game Developer, Tech Evangelist, Entrepreneur.

In case you missed it, this series begins here: Let's Build a Elder Scrolls Online Mod - Part 1

At this point we have a basic mod that has a working core and now listens to the chat window when commanded to do so. From here, let's get into the meat of the add-on: inviting people into a party.

The Repo

I've setup a GitHub repo for the complete code here: This One Invites.

Branch: inviting


Before we jump to the main piece of code, we need to fix something important.

Back in part one we hooked into an event in order to echo out debug text that our add-on was loaded.

EVENT_MANAGER:RegisterForEvent(ThisOneInvites.name, EVENT_PLAYER_ACTIVATED, ThisOneInvites.OnAddOnLoaded)

The problem with this event is that it's fired at the end of each load screen (so game start, portal jump, entering dungeon, etc).

In this particular case, this isn't what's desired.

We have two options as I see it:

  1. Just remove this code as it's not really needed in the end anyway.
  2. Use a different event and setup.

You can't just use d() here because when the add-on is loaded on game load the chat window isn't initialized.

Since we don't need this, I'm just going to remove the debug message and event handler. Instead, we will hook into EVENT_ADD_ON_LOADED.

There are a few add-ons that drop a message on load, but it can become annoying fast. If your add-on isn't loading/processing things, such as Master Merchant, perhaps it's best to just load up and be ready.

Addtionally, we're going to change the :Initialize() function to setup the toonName.

function ThisOneInvites:Initialize()
  ThisOneInvites.toonName = GetUnitName("player"):gsub("%^.+", "")

And replace the event handler like this:

EVENT_MANAGER:RegisterForEvent(ThisOneInvites.name, EVENT_ADD_ON_LOADED, ThisOneInvites.OnAddOnLoaded)

Inviting Players

Now comes the moment of truth. We want to actually invite players to join our group automatically.

First, let's setup a global variable (global only to this add-on, not ESO) that will track the current player's character name. We'll use this to make sure we don't send ourself and invite.

ThisOneInvites.toonName = ""

Next, let's modify the callback function so that if the message it reads is the same as our activator text, it will call the invitePlayer function.

We will also make the add-on echo out debug text in the case that it reads text but that text doesn't match the activatorText. This just lets us know it's working.

The updated version looks like this:

ThisOneInvites.callback = function(_, messageType, from, message)
  name = from:gsub("%^.+", "")
  d("Checking message " .. string.lower(message) .. " from: " .. name .. " msg type " .. messageType )
  if ThisOneInvites.activatorText == message then
    -- send invite
    d("no match")

And now the big moment. It's time to make the invitePlayer function that will take a name argument and if that name isn't the player's toon name, it will send out an invite. If you're following along, you can remove the conditional to test it out (so that it sends you the invite).

function ThisOneInvites.invitePlayer(name)
  if name ~= ThisOneInvites.toonName then

Working But Not Done

At this point, our add-on is working just fine but there's so many more things that could be done.

Here are some ideas (perhaps we'll tackle them as future parts of this series):

  1. Ability to /kick players out of group.
  2. Ability to automatically kick players out of group who are offline for more than X time/cycles/etc.
  3. Create a "tick" event that runs every X second(s) and polls data to see who is in the group and who is online (can be then used for #2).
  4. Develop a que system to account for network issues.
  5. Create a gui that saves variables, such as activatorText so that players can just turn on the addon and go.
  6. Create ban list so players can automatically keep invites from going to bad elements.

If you think I've left something out, please contact me!