Let's Build a Elder Scrolls Online Mod - Part 3
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.
I’ve setup a GitHub repo for the complete code here: This One Invites.
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.
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:
- Just remove this code as it’s not really needed in the end anyway.
- 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.
And replace the event handler like this:
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.
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:
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).
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):
- Ability to /kick players out of group.
- Ability to automatically kick players out of group who are offline for more than X time/cycles/etc.
- 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).
- Develop a que system to account for network issues.
- Create a gui that saves variables, such as activatorText so that players can just turn on the addon and go.
- 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!