if (!$Pref::Server::MaxOwnedBrickgroups) {
$Pref::Server::MaxOwnedBrickgroups = 2;
$Pref::Server::MaxOwnedBrickgroupsAdmin = 5;
}
if (!$OBG::Index) {
$OBG::Index = 1;
}
function padZeros(%i) {
while (strLen(%i) < 3) {
%i = "0" @ %i;
}
return %i;
}
function serverCmdListCustomBrickgroups(%this) {
for (%i = 0; %i < (%mb = mainBrickgroup).getCount(); %i++) {
%group = %mb.getObject(%i);
if (%group.isCustomBrickgroup) {
messageClient(%this, '', "\c6[\c3" @ %i @ "\c6]: " @ %group.name @ " owned by " @ %group.ownedClient);
}
}
}
function serverCmdCreateBrickgroup(%this, %name) {
%name = expandEscape(stripTrailingSpaces(StripMLControlChars(%name)));
if (%name $= "") {
return;
}
%ownedGroups = -1;
for (%i = 0; %i < (%mb = mainBrickgroup).getCount(); %i++) {
%group = %mb.getObject(%i);
if (%group.ownedClient == %this.getBLID()) {
%ownedGroups++;
}
if (%group.name $= %name) {
messageClient(%this, '', "\c6There is already a brickgroup with the name of \"\c3" @ %name @ "\c6\"!");
return;
}
}
if (%ownedGroups > ((%this.isAdmin | %this.isSuperAdmin) ? $Pref::Server::MaxOwnedBrickgroupsAdmin:$Pref::Server::MaxOwnedBrickgroups)) {
messageClient(%this, '', "\c6You already have/exceed the limit in owned brickgroups!");
return;
}
%id = "889" @ padZeros($OBG::Index);
$OBG::Index++;
%group = new SimGroup(("BrickGroup_" @ %id)) {
BL_ID = %id;
client = %this;
isPlublicDomain = 0;
isCustomBrickgroup = true;
abandonedTime = 0;
ownedClient = %this.getBLID();
name = %name;
};
%this.brickGroup = %group;
%mb.add(%group);
messageClient(%this, '', "\c6Brickgroup \"\c3" @ %name @ "\c6\" created.");
echo(%this.getPlayerName() @ " created a new brickgroup called " @ %name @ ".");
echo("------------\r\nBrickGroup_" @ %id @ "\r\n client = " @ %this @ "\r\n name = " @ %name @ "\r\n ownedClient = " @ %this.getBLID() @ "\r\n------------");
}
function serverCmdJoinBrickgroup(%this, %id) {
%mb = mainBrickgroup;
if($Sim::Time-%this.pendingBrickgroupTime < 15) {
messageClient(%this, '', "\c6You've just recently requested to join a brickgroup.");
messageClient(%this, '', "\c6Please wait a little while before requesting again.");
%this.pendingBrickgroupTime = $Sim::Time;
}
if (%id >= %mb.getCount() || !(%group = %mb.getObject(%id)).isCustomBrickgroup) {
return;
}
if (%group == %this.brickGroup) {
messageClient(%this, '', "\c6You're already a part of that brickgroup!");
return;
} else if (!isObject(%targetClient = findClientByBL_ID(%group.ownedClient))) {
messageClient(%this, '', "\c6Was unable to find the client that owns the group.");
return;
}
%this.pendingBrickgroup = %group;
%this.pendingBrickgroupTime = $Sim::Time;
messageClient(%targetClient, '', "\c3" @ %this.getPlayerName() @ "\c6 wishes to be a part of your brickgroup, " @ %group.name @ ".");
messageClient(%targetClient, '', "\c6Type /addToBrickgroup " @ %this.getBLID() @ " to let them join.");
}
function serverCmdaddToBrickgroup(%this, %id) {
if (!isObject(%targetClient = findClientbyBL_ID(%id))) {
messageClient(%this, '', "\c6Was unable to find a client with the BL_ID of " @ %id);
return;
}
if ($Sim::Time-%targetClient.pendingBrickgroupTime >= 30) {
messageClient(%this, '', "\c6It doesn't appear that " @ %targetClient.getPlayerName() @ " has recently requested to join your brickgroup.");
return;
}
%group = %targetClient.pendingBrickgroup;
messageClient(%this, '', "\c6Added \c3" @ %targetClient.getPlayerName() @ "\c6 to your brickgroup, " @ %group.name @ ".");
messageClient(%targetClient, '', "\c6You've been added to the \c3" @ %group.name @ "\c6 brickgroup.");
%targetClient.brickGroup = %group;
}
Unsure how this will work when used, I can't test it out since I can't play online at the moment.
Would be helpful if someone can test it out and tell me how it works.
/createBrickgroup name - Creates a brickgroup with the name "name".
/listCustomBrickgroups - Lists all of the custom brickgroups in the server
The format is [<idx>]: <name> owned by <owned client id>
/joinBrickgroup idx - Requests to join the brickgroup
Edit: I've realized I forgot to make trust checks, working on that now.
Edit 2: Amazingly enough, it still works for me without any modifications to the trust functions. Weird.
Edit 3: Fixed some mispelled variables in serverCmdjoinBrickgroup