Thread Tools Display Modes
10/31/15, 07:13 AM   #1
faketales
Join Date: Oct 2015
Posts: 5
Help with simple Addon

I need a little help with this first simple addon i am developing. Basically at the moment it will work outside of PvP but within pvp it does not work.

The basic premise of this addon is to get the current number of players in the group and output the number of spaces left in the group. This is just a simple base start for a more complicated addon i plan on developing in the future.

So basically i have my initialize function that contains

Code:
function TCC:Initialize()

self.inGroup = IsPlayerInGroup("group")

EVENT_MANAGER:RegisterForEvent(self.name, EVENT_GROUP_MEMBER_LEFT, OnGroupMemberLeft)
EVENT_MANAGER:RegisterForEvent(self.name, EVENT_GROUP_MEMBER_JOINED, OnGroupMemberJoined)

end
OnGroupMemberLeft

Code:
function OnGroupMemberLeft(eventCode, characterName, reason, wasLocalPlayer, amLeader)
   	groupMetrics()
end
OnGroupMemberJoined

Code:
function OnGroupMemberJoined(eventCode, characterName)
   	groupMetrics()
end
groupMetrics function
Code:
function groupMetrics()
	groupSize = GetGroupSize()
	
	TCC.spotsLeft = (TCC.maxGroupSize - groupSize)
    if groupSize <= 1 then
		TCC.LogMsg( "====Group Slots Free====")
		--TCC.Hide()
		return
	else
		TCC.LogMsg( "====Group Slots Free====")
		TCC.LogMsg(TCC.spotsLeft)
		--TCC.Show()
		return
    end
end
if someone could point me in the right direction of how to get this to work within PvP I would greatly appreciate it.

Thank you
  Reply With Quote
10/31/15, 08:39 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,579
You need to be a bit more specific.
What do you mean with "in PvP" and what does not work?
The code you showed seems fine to me.
  Reply With Quote
10/31/15, 09:05 AM   #3
faketales
Join Date: Oct 2015
Posts: 5
Thank you for replying, sorry for not being that specific.

In PvP i mean when in Cyrodiil, and when a player leaves or joins a group nothing is displayed in my textbuffer.

However once i am outside of Cyrodiil say in deshaan or any other zone it works as expected.
  Reply With Quote
10/31/15, 09:14 AM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,579
Ok, my first suspect would be your Log method. Try to use the provided api method d() instead and see if it makes a difference.
You should also put an output into your OnGroupMemberLeft and OnGroupMemberJoined handlers and at the beginning of groupMetrics to see if they get called.
  Reply With Quote
10/31/15, 10:38 AM   #5
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
As sirinsidiator said I don't see anything that would prevent output either. Again as sirinsidiator said try using d("some message") in each function to see if they are called. My guess would be either there is a problem with your TCC.LogMsg function or TCC:Initialize() is not being called to initialize the event registers. Do you unregister those events anywhere? If so I would check that. Where are you calling TCC:Initialize() from, can we see that code?

If you still can't figure it out paste the code somewhere, like on http://pastebin.com/ and give us a link for it.

Other things:

You should make groupMetrics local:
Lua Code:
  1. local function groupMetrics()
  2. ...
  3. end


IsPlayerInGroup(string name) takes a string name as its parameter, not the word "group", unless your characters name is group
Looking at the code I think you can use any form of the characters name: rawName, unitName, displayName, but I've not used the function so I would recommend testing these to check and see which ones work properly.
Lua Code:
  1. local unitName      = GetUnitName("player")
  2. local displayName   = GetDisplayName()
  3. local rawName       = GetRawUnitName("player")
  4.  
  5.    
  6. local isUnitNameInGroup     = IsPlayerInGroup(unitName)
  7. local isDisplayNameInGroup  = IsPlayerInGroup(displayName)
  8. local isRawNameInGroup  = IsPlayerInGroup(rawName)
  9.    
  10. d("isUnitNameInGroup: "..tostring(isUnitNameInGroup))
  11. d("isDisplayNameInGroup: "..tostring(isDisplayNameInGroup))
  12. d("isRawNameInGroup: "..tostring(isRawNameInGroup))

Last edited by circonian : 10/31/15 at 10:47 AM.
  Reply With Quote
10/31/15, 10:51 AM   #6
faketales
Join Date: Oct 2015
Posts: 5
Thank you for taking your time to reply to me.

I am going to look at putting in to d() messages now.

With regards to

Code:
self.inGroup = IsPlayerInGroup("group")
That chunk is redundant , i dont know why i still have that in there

I will update you all after i have done some more debugging.

Thanks again.
  Reply With Quote
10/31/15, 11:02 AM   #7
faketales
Join Date: Oct 2015
Posts: 5
Right I have figured out what I had done wrong, I had accidently commented out my TCC.Initialize()

When I convert the groupMetrics() to a local function I get an error message referring to function expected , something along those lines.

However my addon is working now if I keep it as it is.
  Reply With Quote
10/31/15, 11:22 AM   #8
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by faketales View Post
Right I have figured out what I had done wrong, I had accidently commented out my TCC.Initialize()

When I convert the groupMetrics() to a local function I get an error message referring to function expected , something along those lines.

However my addon is working now if I keep it as it is.
When you make it local it must be above any calls to it. By that I mean:

This wont work because groupMetrics is defined BELOW someplace that it is used in the code:
Lua Code:
  1. local function AnyFunctionCallingGroupMetrics()
  2.    groupMetrics()
  3. end
  4. local function groupMetrics()
  5.   ...
  6. end

It must be defined above any calls to it in the code file like this:
Lua Code:
  1. local function groupMetrics()
  2.   ...
  3. end
  4. local function AnyFunctionCallingGroupMetrics()
  5.    groupMetrics()
  6. end

Although it is working you should still change groupMetrics to local. The reason is if someone else, in some other addon does the same thing, uses the term groupMetrics in their addon and they don't make theirs local either the two will interfere with each other and it will causes problems in both addons.
  Reply With Quote
10/31/15, 11:40 AM   #9
faketales
Join Date: Oct 2015
Posts: 5
Oh thank you very much i will make sure i do this .

Thanks again
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Help with simple Addon


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off