View Single Post
04-19-15, 12:59 AM   #1
Etul
A Murloc Raider
Join Date: Apr 2015
Posts: 4
Seeking help with first addon

Edit: Problem solved (sort of), might keep this thread handy in case any other issues pop up later. Thanks guys!

Hi! This is my first time trying to make an addon with Lua- the idea I am working towards is something that will keep track of the NPCs that are available in all of your alts' garrisons.

To start with I tried to check the character's level when they log in and only check other information such as their name/class/realm if they are level 100. Mostly just as an experiment I wanted to try and print this to the user's chat frame after collecting this information, however despite fiddling with my code for a few hours I can't seem to manage to get it to work.

My code is below- any advice would be greatly appreciated. Thanks!

---

GarrisonNPC.toc

Code:
## Interface: 60100
## Title: Garrison NPC
## Author: Etuliela
## Version: v1.0.0
## Notes: Tracks which NPCs are available in each of your characters' garrisons.
## SavedVariables: NpcData

garrisonnpc.lua
garrisonnpc.lua

Lua Code:
  1. -- Table for saved variables
  2. NpcData = {}
  3.  
  4. local EventFrame = CreateFrame("Frame")
  5.  
  6. -- Check player's level on login - if player is 100 it will record additional character information, otherwise it will not
  7. EventFrame:RegisterEvent("PLAYER_LOGIN")
  8. EventFrame.OnEvent = function(self,event,playerName,characterLevel)
  9.     playerName = UnitName("Player")
  10.     characterLevel = GetCharacterLevel(playerName)
  11.     if characterLevel == 100 then
  12.         NpcData.characterName = UnitName("Player")
  13.         NpcData.characterRealm = GetRealmName()
  14.         NpcData.characterAccount = THIS_ACCOUNT
  15.         ChatFrame1:AddMessage(NpcData.characterName, NpcData.characterRealm, NpcData.characterAccount)
  16.     end
  17.  
  18. end

Last edited by Etul : 04-19-15 at 06:38 AM. Reason: Problem solved
  Reply With Quote