ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   GetFriendInfo help (https://www.esoui.com/forums/showthread.php?t=10472)

sinnereso 03/04/23 01:33 AM

GetFriendInfo help
 
im working on additional feature for my addon and having issues with the "GetFriendInfo()". Im looking to find a specific friend in friends list and check if they're online before executing code. im currently messing with this sort of thing.

Code:

local savedPlayer = xxx.savedVariables.savedPlayer
if not IsPlayerInGroup(savedPlayer) and IsFriend(savedPlayer) then
        for iD = 1, GetNumFriends() do
                if GetFriendInfo(iD) == (savedPlayer, nil, PLAYER_STATUS_ONLINE, nil) then

the formatting of these keeps messing me up.. ive tried in brackets etc. Any suggestions for something I've missed?

FlatBadger 03/04/23 02:09 AM

I use the FRIENDS_LIST_MANAGER for this, e.g.

Code:

local masterList = FRIENDS_LIST_MANAGER:GetMasterList()

for _, friend in ipairs(masterList) do
  if (friend.online) then
      -- do something
  elseif (friend.status == _G.PLAYER_STATUS_OFFLINE) then
      -- do something else
  else
      -- might be afk, eg.
  end
end

If you just need a single player you could instead use:

Code:

local friendData = FRIENDS_LIST_MANAGER:FindDataByDisplayName(displayName)
That will give you all kinds of info like zone, alliance, level, online status ...

sirinsidiator 03/04/23 02:38 AM

Quote:

Originally Posted by sinnereso (Post 47321)
im working on additional feature for my addon and having issues with the "GetFriendInfo()". Im looking to find a specific friend in friends list and check if they're online before executing code. im currently messing with this sort of thing.

Code:

local savedPlayer = xxx.savedVariables.savedPlayer
if not IsPlayerInGroup(savedPlayer) and IsFriend(savedPlayer) then
        for iD = 1, GetNumFriends() do
                if GetFriendInfo(iD) == (savedPlayer, nil, PLAYER_STATUS_ONLINE, nil) then

the formatting of these keeps messing me up.. ive tried in brackets etc. Any suggestions for something I've missed?

That's not valid Lua syntax.
You need to store each return value you want to compare into a local variable and then compare each of them separately:
Lua Code:
  1. local savedPlayer = xxx.savedVariables.savedPlayer
  2. if not IsPlayerInGroup(savedPlayer) and IsFriend(savedPlayer) then
  3.     for iD = 1, GetNumFriends() do
  4.         local friendName, _, status = GetFriendInfo(iD)
  5.         if friendName == savedPlayer and status == PLAYER_STATUS_ONLINE then

sinnereso 03/04/23 02:58 AM

oh cool ty.. but my issue is retriving that data...i can getinfo(somebody) but the specific info like which friend and online status etc from it is confusing me.

Oh i think i get it... and for the info i dont want put _?

*EDIT*

OK got it ty.. its just for a single saved player and your corrections there worked perfectly ty so much! :)

FlatBadger 03/04/23 10:57 AM

No need to loop through anything at all or make additional API calls if you just use the FRIENDS_LIST_MANAGER:FindDataByDisplayName(displayName) - all the info you could ever need is just there for takin. :banana:

sirinsidiator 03/04/23 12:25 PM

Quote:

Originally Posted by sinnereso (Post 47324)
oh cool ty.. but my issue is retriving that data...i can getinfo(somebody) but the specific info like which friend and online status etc from it is confusing me.

Oh i think i get it... and for the info i dont want put _?

*EDIT*

OK got it ty.. its just for a single saved player and your corrections there worked perfectly ty so much! :)

You could use any variable name, but in Lua the general consent is to name the variables you don't plan to use "_", to make the code more readable.

And as others have mentioned, you do not actually need to loop over the friend data yourself, since ZOS already has a method that does it for you.
You can check the code on github.


All times are GMT -6. The time now is 08:52 PM.

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