Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Multiplayer Avatar Interaction

From FiguraMC

Avatars can share values with one another to allow for interactions between them. An example of this would be the various petting scripts you can find in the community.

The basic princible works like this: One avatar can store a value. Another avatar can get this stored value and do something based on it.

To store a value that other avatars can read you use avatar:store(key, value)

For example

avatar:store("amount", 1)

Note: It is recommended to never store any UserData objects as this could lead to security issues! Best to only store primitives like numbers, strings, or regular tables!

Someone else can then read this value in their script by checking the avatarVars for each player.

for uuid, vars in pairs(world.avatarVars()) do
    print(uuid)
    printTable(vars)
end

So for our example you could read the "amount" which we set to 1 and show the player name as well:

for uuid, vars in pairs(world.avatarVars()) do
    if vars["amount"] then
        local playerName = uuid
        for name, plr in pairs(world.getPlayers()) do
            if plr:getUUID() == uuid then
                playerName = name
            end
        end
        print(playerName, "has amount of", vars[key])
    end
end