Shovel

Here’s a basic script for a shovel which also allows you to dig up items which you can define. I’ll be contributing more basic scripts for building a playerworld as time goes by.

// NPC made by tricxta
if (playerenters){
  this.digTiles = {0x7FF,0x3FF};//Tiles that can be dug
  this.replaceTiles = {0x72A,0x72B,0x73A,0x73B};//Tiles that will form the hole, pics1 default
  setshape 1,32,32;
}

if (playertouchsme && !isweapon)toweapons Shovel;

if (weaponfired){
  freezeplayer 0.7;
  this.checkC = {int(playerx+0.5)+vecx(playerdir)*2,int(playery+0.5)+1+vecy(playerdir)*2};
  this.canDig = 0;
  for (this.i = 0;this.i < 4;this.i++)
    this.canDig +=  (tiles[this.checkC[0] + (this.i%2),this.checkC[1] + int(this.i/2)] in this.digTiles);

  if (this.canDig == 4){
    for (this.i=0;this.i<4;this.i++)
      tiles[this.checkC[0]+(this.i%2),this.checkC[1]+int(this.i/2)] = this.replaceTiles[this.i];
    updateboard this.checkC[0],this.checkC[1],2,2;

    checkItems();

    setani cda_shovel2,;
  }
  else {
    setani cda_shovelno,;
  }
}

function checkItems(){
  if (!strequals(#I(client.digItems,0),#L))return;
  for (this.w = 0;this.w < sarraylen(client.digItems)/3-1;this.w++){
    if (hasweapon(#I(client.digItems,this.w*3+1)))continue;//if the player has already dug up this weapon or already has it skip
    if (this.checkC[0] == strtofloat(#I(client.digItems,this.w*3+2)) && this.checkC[1] == strtofloat(#I(client.digItems,this.w*3+3))){
      for (this.npc = 0;this.npc < npcscount;this.npc++)
        callnpc this.npc,add#I(client.digItems,this.w*3+1);
    }
  }
}

For this example I’ve set up a level to dig up a plant and add it to my weapons
This is the code that defines where the patch of grass is along with the weapon it’s looking out to add, you can add multiple item to be dug:

// NPC made by tricxta
if (playerenters){
  setstring client.digItems,#L,Plant,41,20;
}

Here’s the code for the weapon that will be added assuming the player digs in the correct spot although the placement of any npcs doesn’t matter:

// NPC made by tricxta
if (playerenters){
  hide;
}

if (addPlant){
  toweapons Plant;
  for (this.i = 0;this.i<3;this.i+=0.3){
    showimg 1,#f,x+0.5,y-2-this.i;
    changeimgmode 1,1;
    changeimgcolors 1,1,1,1,1-(this.i/3);
    sleep .05;
  }
}

if (weaponfired){
  setplayerprop #c,I'll plant you good!;
}

How do you determine the hexa number of a tile?

There’s a button in the editor that you can press and it gives you an array of all currently selected tiles.

lol duh! tnx