User:Sulai7200/Ideas/Scripting/Examples

Examples for server side scripting and blocks, items and monsters.

server side scripting
This is what a server admin needs to type into console if he wants to create a 40x40 platform around the spawn point:

createBlockRect("sand stone", -20, -20, 20, 20);

This is what a server admin needs to type into console if he wants to restrict write access to the spawning area:

grantRights("admin", -20, -20, 20, 20)

The server admin may define a script that reacts on user chat messages. Example: make access rights hierarchically: If a player has rights to use an Area, he may grant rights for a sub-area to other players. That way you may rent a flat and do the furnishing yourself. However, this could be done by a global admin script reacting on user's chat message like "/grant somePlayer [box coordinates]".

function getType { return "global"; } function onReceiveMessage(player, msg) { if(msg.getCommand == "grant") { box = new Box(msg.getParameters(2,5)); if( box.isInside(player.getAccessBox) ) { grantRights(msg.getParameter(1), box); }   }  }

blocks, items, monsters
This is a NPC salesman who sells redstone for some coal and flees from foes.

getType { return "monster"; } getName { return "redstone salesman"; } // if hit, run away function onHit { message("ouch!"); setDestiny( rnd(40)-20, rnd(40)-20 ); } function onCollect(obj) { // if moving, stop setDestiny(0,0); // player throws coal at NPC: do the deal if( obj.getName=="coal" ) { message("thanks man!"); throw(createObject("redstone dust")); }   // player throws something else: give it back else { message("I only deal with coal"); throw(obj); } }

This is what a server admin needs to type into console if he wants to place the NPC:

createMonster("redstone salesman", 20, 10);

This is redstone written in script:

function getType { return "block"; } function getName { return "redstone"; } function getHardness { return 10000; } function init { setTexture("redstone.png") } function onHit { setEmitedLight(10); } function onBreak { spawn("redstone dust", 4); }

This is redstone dust written in script:

function getType{ return "object"; } function getName { return "redstone dust"; } function getRecipe { return null } function init { setTexture("redstone dust.png"); } function onPut(x,y,z) { put("redstone wire", x, y, z); removeObject(this); }