ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Help with simple Addon (https://www.esoui.com/forums/showthread.php?t=5240)

faketales 10/31/15 07:13 AM

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

sirinsidiator 10/31/15 08:39 AM

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.

faketales 10/31/15 09:05 AM

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.

sirinsidiator 10/31/15 09:14 AM

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.

circonian 10/31/15 10:38 AM

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))

faketales 10/31/15 10:51 AM

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.

faketales 10/31/15 11:02 AM

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.

circonian 10/31/15 11:22 AM

Quote:

Originally Posted by faketales (Post 24015)
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.

faketales 10/31/15 11:40 AM

Oh thank you very much i will make sure i do this .

Thanks again :)


All times are GMT -6. The time now is 09:54 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI