Thread Tools Display Modes
03/04/23, 01:33 AM   #1
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Question 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?

Last edited by sinnereso : 03/04/23 at 01:52 AM.
  Reply With Quote
03/04/23, 02:09 AM   #2
FlatBadger
 
FlatBadger's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2021
Posts: 17
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 ...

Last edited by FlatBadger : 03/04/23 at 02:19 AM.
  Reply With Quote
03/04/23, 02:38 AM   #3
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Originally Posted by sinnereso View Post
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
  Reply With Quote
03/04/23, 02:58 AM   #4
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
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!

Last edited by sinnereso : 03/04/23 at 03:04 AM.
  Reply With Quote
03/04/23, 10:57 AM   #5
FlatBadger
 
FlatBadger's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2021
Posts: 17
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.
  Reply With Quote
03/04/23, 12:25 PM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Originally Posted by sinnereso View Post
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.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » GetFriendInfo help


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