Author Topic: 2011/10/24 - Blockland r1395 features  (Read 48178 times)

Badspot

  • Administrator
As of Blockland build 1395 there are some new features:

Brick_Treasure_Chest



A treasure chest brick that acts as a findable item.  Click on chest to open it.  It keeps track of how many chests there are and how many you have found.  The onActivate events on the brick are only triggered the first time a player opens the chest, so this can also be repurposed for "once per player" events.


Script_Player_Persistence

A simple player saving mod.  When a player disconnects, it saves their position, datablock, health and items, then restores that information when the player reconnects.  The treasure chest and checkpoint bricks will use this system (if enabled) to save and restore the client's current checkpoint brick and which chests they have found.  


Other changes may affect old add-ons

FxDTSBrick::onPlant() and FxDTSBrick::onLoadPlant() are now correctly distinguished from each other.  onPlant is called when a player plants a brick in the game, onLoadPlant is called when a brick is planted via loading a save file.  This should fix issues like duplicate events showing up on checkpoint bricks when loading a save.  However this bug has been around so long that many add-ons have been programmed around it and this fix may cause them to stop working.  The solution is to update the effected add-ons.  
« Last Edit: November 13, 2011, 10:39:17 AM by Badspot »

Badspot

  • Administrator
Add-On developers:  You can use player persistence to save any tagged field on the client or player object by using the RegisterPersistenceVar() function.  Here is some example code:
Code: [Select]
//load the persistence add-on now, if they have it enabled.
//you can also use ForceRequiredAddOn if your add-on doesn't work without persistence
LoadRequiredAddOn("Script_Player_Persistence");

if(isFunction(RegisterPersistenceVar))  //quick way to check if the persistence add-on loaded
{
   //usage: RegisterPersistenceVar(string <tagged field to match>, bool <match all>, string <datablock classname>);

   RegisterPersistenceVar("myVariable", false, "");             // save %client.myVariable and %player.myVariable to persistence file (if those values are set)

   RegisterPersistenceVar("myPrefix", true, "");                // save any tagged field on %client/%player starting with "myPrefix",
                                                                // eg %client.myPrefixFoo %client.myPrefix_24, etc.
                                                                // This is more expensive than a straight match and can have unintended consequences, so be careful

   RegisterPersistenceVar("myDatablockRef", false, "ItemData"); // save %client/%player.myDatablockRef to persistence but verifies that it is of class "ItemData"
                                                                // and translates the id number into a datablock name before saving. 
                                                                // Datablock id numbers will vary depending on the order and number of add-ons loaded,
                                                                // so use this if you need to save a datablock reference.
}

//optionally, you can package into the apply persistence function if you need to do custom stuff to fully restore the player's state
package <MyAddOn>PersistencePackage
{
   function GameConnection::applyPersistence(%client, %gotPlayer, %gotCamera)
   {
      Parent::applyPersistence(%client, %gotPlayer, %gotCamera);
     
      //Do custom stuff here...
   }
};
activatePackage(<MyAddOn>PersistencePackage);
Player Persistence files are saved as config/server/persistence/<blid>.txt


Nice

inb4someonesaysripoffofminecr aft

Looks really run.

I can sense a Blockland story mode.  :cookieMonster:


Great, the player persistence will be really useful for modding.



Little error with the treasure chest brick. I don't think it causes problems though.
Code: [Select]
ERROR: Brick datablock "brickTreasureChestOpenData" has no uiname
BackTrace: ->[TreasureChestPackage]onStart->[TreasureChestPackage]serverPart2->[
TreasureChestPackage]dedicatedKeyCheck->[TreasureChestPackage]initDedicated->[Tr
easureChestPackage]createServer->[TreasureChestPackage]onServerCreated->verifyBr
ickUINames



Also, will FxDTSBrick::onPlant() be called whenever a brick is planted, regardless of whether it's planted in a save file load?

Amesome!

You could use events to spawn items from the treasure chest, too.

Badspot

  • Administrator
Also, will FxDTSBrick::onPlant() be called whenever a brick is planted, regardless of whether it's planted in a save file load?

No, they are exclusive.  Regular building => onPlant, loading a save => onLoadPlant


Cool updates.

Will this level of content be regular for the new launcher updates? Or is it more than usual since its the first one?

No, they are exclusive.  Regular building => onPlant, loading a save => onLoadPlant
Is there a function that's called no matter how it's loaded?

Now watch as we get a dozen complaints about the new script from people who inadvertently turned it on and are unaware that they can turn it back off.

Is there a function that's called no matter how it's loaded?
Nevermind, I can use ::onAdd().

It doesn't look like the persistence script saves scale.