Skip to content
Download all docs .md

Groups (JS)

A group is a named set of players: a clan, a guild, a team or a party. A group has members, admins, its own chat and its own saved data.

The player must be signed in. signIn downloads the groups the player is in and the invites waiting for them.

Make a group

GameFuseGroup.create({
    name: 'Red Team',
    maxGroupSize: 4,
    canAutoJoin: false,    // true: anyone can join without asking
    isInviteOnly: true,    // true: players can only get in by invite
}, function (message, hasError) {
    if (hasError) {
        console.error('Could not make the group: ' + message);
        return;
    }
    const team = GameFuseUser.CurrentUser.getGroups()[0];   // the new group is first
    console.log(team.getName() + ' has ' + team.getMemberCount() + ' member');
});

All four values are needed. The player who makes the group is its first member and its admin. You can also pass groupType (any text of yours, such as 'clan') to tell kinds of group apart.

Find groups

GameFuseGroup.downloadAvailableGroups(function (message, hasError) {
    if (hasError) return;
    for (const group of GameFuseUser.CurrentUser.getDownloadedAvailableGroups()) {
        console.log(group.getName(), group.getMemberCount() + '/' + group.getMaxGroupSize());
    }
});

Join a group

// A group with canAutoJoin = true: the player is in at once
group.join(function (message, hasError) { /* ... */ });

// Otherwise ask. An admin then accepts or declines.
group.requestToJoin(function (message, hasError) {
    if (!hasError) {
        console.log(GameFuseUser.CurrentUser.getGroupJoinRequests().length + ' requests waiting');
    }
});

The groups the player is in are in GameFuseUser.CurrentUser.getGroups().

Invite a player

Invite a player by username, or with a GameFuseUser.

team.invite('ava', function (message, hasError) {
    if (!hasError) {
        console.log(team.getInvites().length + ' invites waiting');
    }
});

The invited player sees it after their next sign-in or refreshUserData:

const invite = GameFuseUser.CurrentUser.getGroupInvites()[0];
console.log(invite.getInviter().getUsername() + ' invited you to ' + invite.getGroup().getName());

invite.accept(function (message, hasError) {
    if (!hasError) {
        console.log('In ' + GameFuseUser.CurrentUser.getGroups().length + ' groups now');
    }
});

// or: invite.decline(callback);
// The player who sent it can take it back: invite.cancel(callback);

Members, admins and join requests

A group from a list has its name and counts. Call downloadFullData to get its members, admins, invites and join requests.

team.downloadFullData(function (message, hasError) {
    if (hasError) return;

    for (const member of team.getMembers()) {
        console.log(member.getUsername());
    }
    console.log(team.getAdmins().length + ' admins');

    // Admins answer join requests
    for (const request of team.getJoinRequests()) {
        console.log(request.getUser().getUsername() + ' wants to join');
        request.accept(function (message, hasError) { /* ... */ });   // or request.decline(callback)
    }
});

A player can take back their own join request with request.cancel(callback), from GameFuseUser.CurrentUser.getGroupJoinRequests().

Admin calls

Only a group's admins can do these. For anyone else they fail with hasError = true.

team.update({ name: 'Blue Team', maxGroupSize: 8 }, callback);   // also canAutoJoin, isInviteOnly
team.makeMemberAdmin(member, callback);    // member is a GameFuseUser from team.getMembers()
team.removeMember(member, callback);
team.destroy(callback);                    // deletes the group for everyone

Leave a group

team.leave(function (message, hasError) {
    if (!hasError) {
        console.log('Left ' + team.getName());
    }
});

Group chat

team.sendMessage('gg everyone', function (message, hasError) {
    if (!hasError) {
        const chat = GameFuseUser.CurrentUser.getGroupChats()[0];
        console.log(chat.getMessages()[0].getText());   // "gg everyone"
    }
});

Every member gets it. Reading and replying work as on the Chat page.

Group data

Save small pieces of data on the group as keys and values, such as its motto or its points this season.

team.createAttribute({ key: 'motto', value: 'never tilt', others_can_edit: true }, function (message, hasError) {
    if (hasError) {
        console.error('Could not save: ' + message);
    }
});

team.modifyAttribute('motto', 'sometimes tilt', callback);

team.getAttributes(function (message, hasError) {
    if (hasError) return;
    for (const item of team.getLoadedAttributes()) {
        console.log(item.key + ' = ' + item.value);   // also item.id, item.creatorId, item.canEdit
    }
});

Any member can add group data. To let only admins add and change it, pass admins_only_can_create_attributes: true to GameFuseGroup.create. A value added with others_can_edit: false (or without it) can only be changed by the player who added it.

Reference

Call What it does
GameFuseGroup.create({ name, maxGroupSize, canAutoJoin, isInviteOnly }, callback) Makes a group
GameFuseGroup.downloadAvailableGroups(callback) Loads the game's groups into getDownloadedAvailableGroups()
GameFuseUser.CurrentUser.getGroups() The groups the player is in
GameFuseUser.CurrentUser.getGroupInvites(), getGroupJoinRequests() The player's waiting invites and join requests
group.getID(), getName(), getGroupType(), getMemberCount(), getMaxGroupSize(), getCanAutoJoin(), getIsInviteOnly() One group's details
group.downloadFullData(callback) Loads members, admins, invites and join requests
group.getMembers(), getAdmins(), getInvites(), getJoinRequests() Filled by downloadFullData
group.join(callback), group.requestToJoin(callback), group.leave(callback) Joining and leaving
group.invite(userOrUsername, callback) Invites a player
invite.accept(callback), invite.decline(callback), invite.cancel(callback) A GameFuseGroupInvite. Also getGroup(), getUser(), getInviter()
request.accept(callback), request.decline(callback), request.cancel(callback) A GameFuseGroupJoinRequest. Also getGroup(), getUser()
group.update(changes, callback), group.destroy(callback) Admins: change or delete the group
group.makeMemberAdmin(user, callback), group.removeMember(user, callback) Admins: manage members
group.sendMessage(text, callback) Sends a message to the group's chat
group.createAttribute({ key, value, others_can_edit }, callback), group.modifyAttribute(key, value, callback) Saves group data
group.getAttributes(callback), group.getLoadedAttributes() Loads and reads group data