• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

EN AddToServerGroup

DrWarpMan

Well-Known Member
Contributor
Insider
So, I am making a script, but.. how can I add server group to client, via name? And not a number? Or it is possible to add it via name, but I am writing it wrongly?

"addToServerGroup(group: (ServerGroup | string | number))"

It says string or number, so.. idk

ev.client.addToServerGroup('test');

?
 

mxschmitt

Moderator
Staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
You can use a ServerGroup object, or the ID of the server group.
 

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
You either pass a servergroup object or the ID as a string or number, passing the name is not supported.
If you want to add it via name you first have to find it in engine.getServerGroups().

For example like this (not tested, might have typos):
JavaScript:
var backend = require("backend")
var group = getServerGroupByName("foobar")

// in some event:
ev.client.addToServerGroup(group)
// ...

function getServerGroupByName(name) {
    var groups = backend.getServerGroups()
  
    for (i in groups) {
        var sg = groups[i]
        if (sg.name() == name) {
            return sg
        }
    }
    return null
}
 
Last edited:

DrWarpMan

Well-Known Member
Contributor
Insider
Is something wrong with this?

Code:
    var engine = require('engine');
    var backend = require('backend');
    var event = require('event');
   
    // listen for chat event
    event.on('chat', function (ev) {
       
        if(ev.text == "Hulk")
        {
            var skupina = getServerGroupByName(ev.text);
            ev.client.addToServerGroup(skupina);
            return;
        }
       
    });
   
    function getServerGroupByName(name) {
        var groups = engine.getServerGroups()
       
        for (i in groups) {
            var sg = groups[i]
            if (sg.name() == name) {
                return sg
            }
        }
        return null
    }
 

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Yeah I made a typo
engine => backend
 

DrWarpMan

Well-Known Member
Contributor
Insider
THANKS, WORKS <3
Btw. in the function, is there already a function that checks if that group does even exists? I mean, what happens if it doesnt exist? No error?
 

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Btw. in the function, is there already a function that checks if that group does even exists? I mean, what happens if it doesnt exist? No error?
If it doesn't exist the function returns null.

JavaScript:
var group = getServerGroupByName("somethingthatdoesnotexist")

if (!group) {
    // does not exist
} else {
    // does exist
}
 
Top