So I threw this together this evening. If you know a specific blueprint that you want to add to a player then you can add this script to the mods/scripts or scripts directory and it will add it to any players that don't already have it.
I'm not making this an official example because the API will be improved to make this simpler in the future... and may slightly break this one. But it works now.
It is still helpful to have read and tried the other examples:
http://mythruna.com/forum/index.php?topic=505.0http://mythruna.com/forum/index.php?topic=506.0If nothing else, the second example will let you easily be able to figure out which blueprint and object is and then you can manually copy it out of your mythruna.db/blueprints directory to give to someone else along with this script.
/**
* This script illustrates creating a blueprint
* entity on a player if it doesn't already exist.
* This is not a great learning example because much
* of this will be done differently soon but I wanted
* to show players how to manually add a blueprint.
*/
import mythruna.es.*;
import mythruna.script.*;
on( [playerJoined] ) {
type, event ->
// First we need to get the blueprints that
// the player may already have
// This requires a lot of manualy entity system interaction
// that will be streamlined later.
def items = entities.getEntities( new FieldFilter( InContainer.class, "parentId", player ),
InContainer.class, BlueprintReference.class );
// This is the blueprint we want to make sure that the player
// has in their inventory
long blueprintId = 1323480647086L;
// Go through all of the ones they have to see if they
// already have this one or not.
boolean hasBlueprint = false;
for( Entity e : items ) {
if( blueprintId == e.get(BlueprintReference.class).blueprintId ) {
hasBlueprint = true;
break;
}
}
// MUST ALWAYS RELEASE... bad things will happen otherwise
// and this is why this API will be changed for scripts so
// that they don't have to release.
items.release();
if( hasBlueprint )
return; // nothing else to do
// Create the new entity and set it up
def bp = entities.createEntity();
bp << new BlueprintReference(blueprintId);
bp << new InContainer(player, (byte)0);
console.echo( "Added blueprint:" + blueprintId );
}
For blueprints, the name of the file is also the ID. So if you need to rename the file then just make sure it's still a number and then use that number in the script above.
It's not very elegant but it works... and like I said in another thread, there will be official support for this someday anyway.