Download
(8 Kb)
Download
Updated: 05/06/23 06:29 PM
Compatibility:
Necrom (9.0.0)
Scribes of Fate (8.3.5)
Firesong (8.2.5)
Lost Depths (8.1.5)
High Isle (8.0.0)
Updated:05/06/23 06:29 PM
Created:02/02/22 03:01 PM
Monthly downloads:9,237
Total downloads:289,715
Favorites:108
MD5:
LibDataShare  Popular! (More than 5000 hits)
Version: 0.0.3
by: andy.s, m00nyONE
This library is primarily intended to be used by Hodor Reflexes, but addon authors can utilize its functionality to occasionally share small pieces of numeric data between players without worrying about conflicts with other addons.

The library's directory contains a simple example of an addon that can play sounds for group members. Obviously, all group members must have this library and the addon installed, just like with Hodor Reflexes.

When Hodor Reflexes is enabled, this library must not be used to share data at a high frequency, because Hodor does that (~every 2 seconds). You can share data based on some rare game event or every 10+ seconds (still it's not recommended, because other addons might also want to do that).

How to use

Lua Code:
  1. local function HandleData(tag, data)
  2.     d(string.format("Player: %s. Data: %d.", GetUnitDisplayName(tag), data))
  3. end
  4.  
  5. local share = LibDataShare:RegisterMap("MyAddon", 2, HandleData)

Line 5 registers a map with id "2" (which is Glenumbra map) to share data. Whenever the player receives data from another group member, "HandleData" is called. Note: the player doesn't receive his own data. The first parameter is just a string to know which addon has registered the map.

After this you can use "share" object to send data to group members:

Lua Code:
  1. share:QueueData(12345)
  2. -- ^This function queues data for sending.
  3. -- It'll be sent as soon as it's safe to send the next map ping
  4. -- (ideally there should a minimum time between two pings).
  5.  
  6. -- OR
  7. share:SendData(12345)
  8. -- ^This function sends data instantly without checking if it's safe to do so.
  9. -- Only use it for something really urgent (players shouldn't be kicked
  10. -- from server when sending 2 pings quickly, if it doesn't happen too often).
  11.  
  12. -- Alternatively you can manually check if it's safe to send data.
  13. -- If Hodor Reflexes is enabled, then this check probably will never succeed.
  14. if share:IsSendWindow() then
  15.     share:SendData(12345)
  16. end

Each map allows different maximum amount of data you can share (a number between 0 and X). Check Maps.lua for more details.
Important note: two addons can not register the same map! If they attempt to do so, then an error will occur. There is no workaround for it, so addon authors will have to communicate and decide who uses which map. Hopefully it won't be an issue, because it's a bad idea to have many data sharing addons active anyway.

You can also notice that there are only few maps available in Maps.lua. This is due to the fact that not all maps are "good" for this purpose and their coordinates can conflict (all map coordinates in the library are relative to Vvardenfell).

Finally it's time to define "data" (better later than never!):
Data is an integer number between 0 and (map size)^2. Map size is basically a number of unique points on its x or y axis, therefore a total amount of (x, y) points is map size squared. It can be a pretty big number like 100 billion, so you can "pack" multiple smaller numbers in it: 130,250,320. Here we have 3 numbers (130, 250 and 320) that easily fit in the range of a billion. I hope I don't need to explain how to "extract" 250 from a number 130250320

Final note: I haven't thoroughly tested all the available maps. Sometimes it's possible that some big random number might not be encoded/decoded properly, but all the maps should work fine for sharing small numbers. Let me know if you run into this issue!
## 0.0.3 - m00nyONE
- API bump to 101037 101038
- resolve more conflicts

## 0.0.2 - m00nyONE
- API bump to 101035 101034

## 0.0.1
- initial release
Optional Files (0)


Archived Files (2)
File Name
Version
Size
Uploader
Date
0.0.2
7kB
m00nyONE
10/29/22 02:20 PM
0.0.1
7kB
andy.s
02/02/22 03:01 PM


Post A Reply Comment Options
Unread 04/25/23, 05:35 PM  
m00nyONE
 
m00nyONE's Avatar
AddOn Author - Click to view AddOns

Forum posts: 0
File comments: 50
Uploads: 11
Originally Posted by Schlaefer
Your numbers for map 9 (Shadowfen) are slightly off.
When I send 2684354560 as data the receiver gets 2684354559.
Thanks for testing that out. I'll try fixing the issue after i found out how to calculate the step size more efficiently.
Report comment to moderator  
Reply With Quote
Unread 04/10/23, 04:59 PM  
Schlaefer

Forum posts: 0
File comments: 1
Uploads: 0
Your numbers for map 9 (Shadowfen) are slightly off.
When I send 2684354560 as data the receiver gets 2684354559.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: