Blockland Glass Developer's Guide

Author Topic: Blockland Glass Developer's Guide  (Read 5961 times)

Blockland Glass Developer's Guide
This documentation is way overdue, but late is better than never.

Preferences
Glass automatically brings in any old RTB preferences, already supporting nearly all RTB add-ons.

You can create a new preference category for your add-on with the registerPreferenceAddon function:

     registerPreferenceAddon(%addon, %name, %icon);
     registerPreferenceAddon("System_BlocklandGlass", "Glass Prefs", "gear");

The preference itself is registered objectively, similar to Datablocks. An example is below:

Code: [Select]
//Object-based preference initialization

registerPreferenceAddon("System_BlocklandGlass", "Glass Server Prefs", "gear");

new ScriptObject(Preference) {
  className      = "MyCoolPref"; //namespace

  addon          = "System_BlocklandGlass"; //add-on filename
  category       = "General";
  title          = "Can use";

  type           = "dropdown";
  params         = "Host 3 Super_Admin 2 Admin 1"; //list based parameters

  variable       = "$Pref::BLPrefs::AllowedRank"; //global variable (optional)

  defaultValue   = "Super_Admin 2"; //two words due to dropdown

  updateCallback = "myRealUpdateCallback"; //to call after ::onUpdate (optional)
  loadCallback   = "myRealUpdateCallback"; //to call after ::onLoad (optional)

  hostOnly       = true; //default false (optional)
  secret         = false; //whether to tell clients the value was updated (optional)

  loadNow        = false; // load value on creation instead of with pool (optional)
  noSave         = false; // do not save (optional)
  requireRestart = false; // denotes a restart is required (optional)
};

function MyCoolPref::onUpdate(%this, %val) {
  //myRealUpdateCallback should have already been called by now,
  // handled by the Preference generic
  echo("MyCoolPref::onUpdate");

  if($Test::Pref $= %val) {
    echo("Passed update callback test");
  } else {
    echo("Failed update callback test");
  }
}

function MyCoolPref::onLoad(%this, %val) {
  echo("Loaded \"" @ %this.title @ "\"");
}

function myRealUpdateCallback(%this, %val) {
  $Test::Pref = %val;
}

The following preference types and parameters have been defined by Support_Preferences:
  • bool
  • num <min> <max> <precision>
  • playercount <min> <max>
  • string <len> <strip ml>
  • slider <min> <max> <snapTo> <stepValue>
  • dropdown <name1> <value1> <name2> <value2> ...
  • wordlist <delimiter> <maxWords>
  • color
  • datablock <type> <canBeNone>
  • datablocklist <max words>
  • button
  • colorset
  • rgb <has alpha>

However, only types used by RTB have been implemented along with RGB. The rest can be implemented at request (probably all of them in a single update).

Required Clients
Glass allows servers to set required or optional client sided add-ons to use while playing. Once it's setup Glass will automatically handle the downloads and prompting of downloads for the client. This is the function to register a required client:

     registerRequiredClient(%name, %glassId, %optional);

%name - This appears to the client when connecting, you can name your add-on whatever you like. It does not have to be the same as it is on Glass.
%glassId - The Glass ID of your add-on, this can be found in the url of the add-on. (Example: add-on.php/id=398 your ID would be 398).
%optional - Set this to 1 if you want the client to be an optional download.

Example:

     registerRequiredClient("Jailbreak Client", 135, 0);


Loading Screens
Glass allows gamemode creators to set custom loading backgrounds for users loading their gamemode. Setup is quite simple:

     registerLoadingScreen(%url, %fileType[, %crc]);

Calling this method inside your gamemode makes clients (who have loading backgrounds enabled) download the specified image URL. Any jpeg, png, or jpg image is supported. Note that Glass has to be running on the server.

%crc is an optional field allowing the client to cache your server's preview image. If a client already has the loading image with the given CRC downloaded, the image will load automatically without needing to be downloaded.

Example:

     registerLoadingScreen("http://mysite.com/image.png", "png");

The background must be below 2MB in file size, or else it won't load!


Player List
A lot of servers have more than just the normal admin and super admin ranks so Glass allows server hosts to set their client's rank on the server list. This can be done by calling a client command to update the letter.

     clientCmdGlass_setPlayerlistS tatus(%blid, %char, %color);

%blid - The BL_ID of the client you would like to change.
%char - The desired character. This has a limit of one letter.
%color - The color you would like the line to be.

Color code:
1 = Black
2 = Grey
3 = Light Grey
4 = Pinkish Red
5 = Blue
6 = Red
7 = Green
8 = Orange
9 = Teal

Example:

     commandToAll('Glass_setPlayerlistStatus', 2143, "J", 7);

ddo i need to install glass now

I think you forgot the float datatype. I used that in Brick Tessellation.

Require client is probably one of the worst supports ever to be made and I'm glad it was normalized so late because if it we're sooner like 5 years ago it would've reduced the quality of most servers. Client sided add-ons are very bad for a number of reasons but the one I can think of off the top of my head is poor input hooking and glitchy authentication loops as well as interference with other client sided mods. No server actually requires a client unless they really have to hook things like movement control keys for special functionality. Inventories and menus which make up 90% of the stuff people arbitrarily require you to download to play their server can easily be made using bottom and center print

Also this goes without saying but forcing people to download files just to play your server is a huge security risk especially when it has internet functionality
« Last Edit: August 25, 2018, 06:57:14 PM by thegoodperry »

Is there a list of icons that can be used for the preferences?

Require client is probably one of the worst supports ever to be made and I'm glad it was normalized so late because if it we're sooner like 5 years ago it would've reduced the quality of most servers. Client sided add-ons are very bad for a number of reasons but the one I can think of off the top of my head is poor input hooking and glitchy authentication loops as well as interference with other client sided mods. No server actually requires a client unless they really have to hook things like movement control keys for special functionality. Inventories and menus which make up 90% of the stuff people arbitrarily require you to download to play their server can easily be made using bottom and center print

Also this goes without saying but forcing people to download files just to play your server is a huge security risk especially when it has internet functionality

I strongly disagree, I think the lack of servers' ability to customize themselves and provide gamemodes that actually feel fleshed out was the lack of any client interaction. Client mods made correctly don't have any compatibility issues or authentication loops. Most buggy things surrounding client mods were because of the lack of support of them in general, a self-feeding problem. Doing everything purely through text commands and bottom prints is incredibly clunky and limiting, I'm not sure why that's ever the better solution other than laziness and the difficulty of getting users to install a client mod, the second of which we tried to remedy by making this system.

The biggest "security risk" is having your key stolen, anything in torque is pretty isolated. All required client add-ons have to be on the mod manager meaning they've been reviewed and approved.

Is there a list of icons that can be used for the preferences?

Everything in the Add-Ons/System_BlocklandGlass/image/icon folder.

I think you forgot the float datatype. I used that in Brick Tessellation.

A bounded num type with decimal points offers the same functionality.

Hey looks like you forgot to include disabling the loading screen server preview list when setting a loadingscreen

Thank you! When I started using Glass Preferences, I couldn't find anyone who was using them since RTB preferences were backwards compatible. Hopefully this helps with adoption.

Also, does colorset work now? I recall it not working a few months back.
« Last Edit: September 25, 2018, 07:18:06 PM by Platypi »

Also, does colorset work now? I recall it not working a few months back.

It doesn't appear to be, but I can try to work on it this weekend.

I hope you can get a blockland glass bot on this forum like RTB mod bot.

Is it possible for me to run glass and rtb at the same time?

Is glass now compatible for rtb?

No. There's a few giant reasons why those 2 cannot be perfectly together. Why do you want to have both enabled anyway?

Why do you want to have both enabled anyway?

Because I still have stuffloads of add-ons that use RTB prefs so I can't exactly switch over.

Because I still have stuffloads of add-ons that use RTB prefs so I can't exactly switch over.
I've personally never had any issue with RTB-based add-ons working with BLG, as it tries to support RTB prefs. Have you attempted a transition and ran into issues?

Because I still have stuffloads of add-ons that use RTB prefs so I can't exactly switch over.
BLG rewrites the RTB pref functions so you should be fine