WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   How to determine if im in group or not (https://www.wowinterface.com/forums/showthread.php?t=40355)

Clarkey 05-31-11 06:05 PM

How to determine if im in group or not
 
Hi, I've recently created an addon but I only want it to work if the user is in a party because it sends message to /p.

I need something to the effect of..

Code:

if(playerisinparty) then
 - do stuff
end

because at the moment, if you aren't in a party then i get spammed 'You aren't in a party'.

Torhal 05-31-11 06:07 PM

Code:

if GetNumPartyMembers() > 0 then
    -- do stuff
end


Clarkey 05-31-11 06:15 PM

Thanks, I tried that but doesn't work.

This is what I tried.

Code:

local noParty = GetNumPartyMembers()
if noParty > 0 then
-- do stuff
end

If im solo, it still tries to do it, returning the 'You aren't in a party.'

Seerah 05-31-11 06:18 PM

When are you calling the above segment of code?

Clarkey 05-31-11 06:22 PM

Code:

local enabled = "YES";
local channel = "PARTY";
local CControl = CreateFrame("Frame")

if GetNumPartyMembers() > 0 then

    if(enabled == "YES") then
        CControl:SetScript("OnEvent",function(...)
            local args = {...}

-- do stuff

        end)
    end
end
CControl:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
DEFAULT_CHAT_FRAME:AddMessage("## CControl is ready.",1,1,1)

EDIT: fixed with...

Code:

local enabled = "YES";
local channel = "PARTY";
local CControl = CreateFrame("Frame")

    if(enabled == "YES") then
        CControl:SetScript("OnEvent",function(...)
            local args = {...}
if GetNumPartyMembers() > 0 then

-- do stuff

        end
        end)
end
CControl:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
DEFAULT_CHAT_FRAME:AddMessage("## CControl is ready.",1,1,1)


Vlad 05-31-11 06:41 PM

The code is ran only once, hence at login (unless you are in a group at that point) will not set the script thus it will never run later on. Instead you should do this: ...

*Edit*

I noticed you noticed, hehe. ;)


All times are GMT -6. The time now is 01:18 PM.

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