Shovel script

Because everyone likes shovels. :smiley:

[CODE]//Shovel Script
//#CLIENTSIDE
if(created){
setimg wspade0.gif;
toweapons Shovel lvl2;
}
if(weaponfired){
//init
this.digtiles = {icetiles,1497,2034,2041}
this.digtilesgrass = {grasstiles,511,1,112,114,130,146,143,907,1023,2047,2752,2753,16,2101,2102,2103}
this.dugtiles = {1386,1387,1402,1403}
this.dugtilesgrass = {1834,1835,1850,1851}
freezeplayer .3;

//up
if(playerdir=0){
this.targettiles = {lowerleft,playerx+1,playery+1,lowerright,playerx+2,playery+1,upperleft,playerx+1,playery,upperright,playerx+2,playery}
this.diggingtiles = {tiles[this.targettiles[1],this.targettiles[2]],tiles[this.targettiles[4],this.targettiles[5]],tiles[this.targettiles[7],this.targettiles[8]],tiles[this.targettiles[10],this.targettiles[11]]}
callnpc testnpc(this.targettiles[1],this.targettiles[2]),actiondug,;
if (this.diggingtiles[0] in this.digtiles&&this.diggingtiles[1] in this.digtiles&&this.diggingtiles[2] in this.digtiles&&this.diggingtiles[3] in this.digtiles){
setani shovel,;
tiles[this.targettiles[1],this.targettiles[2]] = this.dugtiles[2];
tiles[this.targettiles[4],this.targettiles[5]] = this.dugtiles[3];
tiles[this.targettiles[7],this.targettiles[8]] = this.dugtiles[0];
tiles[this.targettiles[10],this.targettiles[11]] = this.dugtiles[1];
updateboard this.targettiles[7],this.targettiles[8],32,32;
}
else if (this.diggingtiles[0] in this.digtilesgrass&&this.diggingtiles[1] in this.digtilesgrass&&this.diggingtiles[2] in this.digtilesgrass&&this.diggingtiles[3] in this.digtilesgrass){
setani shovel,;
tiles[this.targettiles[1],this.targettiles[2]] = this.dugtilesgrass[2];
tiles[this.targettiles[4],this.targettiles[5]] = this.dugtilesgrass[3];
tiles[this.targettiles[7],this.targettiles[8]] = this.dugtilesgrass[0];
tiles[this.targettiles[10],this.targettiles[11]] = this.dugtilesgrass[1];
updateboard this.targettiles[7],this.targettiles[8],32,32;
}
else {setani shovel2,; return;}}

//down
if(playerdir=2){
this.targettiles = {lowerleft,playerx+1,playery+4,lowerright,playerx+2,playery+4,upperleft,playerx+1,playery+3,upperright,playerx+2,playery+3}
this.diggingtiles = {tiles[this.targettiles[1],this.targettiles[2]],tiles[this.targettiles[4],this.targettiles[5]],tiles[this.targettiles[7],this.targettiles[8]],tiles[this.targettiles[10],this.targettiles[11]]}
callnpc testnpc(this.targettiles[1],this.targettiles[2]),actiondug,;
if (this.diggingtiles[0] in this.digtiles&&this.diggingtiles[1] in this.digtiles&&this.diggingtiles[2] in this.digtiles&&this.diggingtiles[3] in this.digtiles){
setani shovel,;
tiles[this.targettiles[1],this.targettiles[2]] = this.dugtiles[2];
tiles[this.targettiles[4],this.targettiles[5]] = this.dugtiles[3];
tiles[this.targettiles[7],this.targettiles[8]] = this.dugtiles[0];
tiles[this.targettiles[10],this.targettiles[11]] = this.dugtiles[1];
updateboard this.targettiles[7],this.targettiles[8],32,32;
}
else if (this.diggingtiles[0] in this.digtilesgrass&&this.diggingtiles[1] in this.digtilesgrass&&this.diggingtiles[2] in this.digtilesgrass&&this.diggingtiles[3] in this.digtilesgrass){
setani shovel,;
tiles[this.targettiles[1],this.targettiles[2]] = this.dugtilesgrass[2];
tiles[this.targettiles[4],this.targettiles[5]] = this.dugtilesgrass[3];
tiles[this.targettiles[7],this.targettiles[8]] = this.dugtilesgrass[0];
tiles[this.targettiles[10],this.targettiles[11]] = this.dugtilesgrass[1];
updateboard this.targettiles[7],this.targettiles[8],32,32;
}
else {setani shovel2,; return;}}

//left
if(playerdir=1){
this.targettiles = {lowerleft,playerx-1,playery+3,lowerright,playerx,playery+3,upperleft,playerx-1,playery+2,upperright,playerx,playery+2}
this.diggingtiles = {tiles[this.targettiles[1],this.targettiles[2]],tiles[this.targettiles[4],this.targettiles[5]],tiles[this.targettiles[7],this.targettiles[8]],tiles[this.targettiles[10],this.targettiles[11]]}
callnpc testnpc(this.targettiles[1],this.targettiles[2]),actiondug,;
if (this.diggingtiles[0] in this.digtiles&&this.diggingtiles[1] in this.digtiles&&this.diggingtiles[2] in this.digtiles&&this.diggingtiles[3] in this.digtiles){
setani shovel,;
tiles[this.targettiles[1],this.targettiles[2]] = this.dugtiles[2];
tiles[this.targettiles[4],this.targettiles[5]] = this.dugtiles[3];
tiles[this.targettiles[7],this.targettiles[8]] = this.dugtiles[0];
tiles[this.targettiles[10],this.targettiles[11]] = this.dugtiles[1];
updateboard this.targettiles[7],this.targettiles[8],32,32;
}
else if (this.diggingtiles[0] in this.digtilesgrass&&this.diggingtiles[1] in this.digtilesgrass&&this.diggingtiles[2] in this.digtilesgrass&&this.diggingtiles[3] in this.digtilesgrass){
setani shovel,;
tiles[this.targettiles[1],this.targettiles[2]] = this.dugtilesgrass[2];
tiles[this.targettiles[4],this.targettiles[5]] = this.dugtilesgrass[3];
tiles[this.targettiles[7],this.targettiles[8]] = this.dugtilesgrass[0];
tiles[this.targettiles[10],this.targettiles[11]] = this.dugtilesgrass[1];
updateboard this.targettiles[7],this.targettiles[8],32,32;
}
else {setani shovel2,; return;}}

//right
if(playerdir=3){
this.targettiles = {lowerleft,playerx+3,playery+3,lowerright,playerx+4,playery+3,upperleft,playerx+3,playery+2,upperright,playerx+4,playery+2}
this.diggingtiles = {tiles[this.targettiles[1],this.targettiles[2]],tiles[this.targettiles[4],this.targettiles[5]],tiles[this.targettiles[7],this.targettiles[8]],tiles[this.targettiles[10],this.targettiles[11]]}
callnpc testnpc(this.targettiles[1],this.targettiles[2]),actiondug,;
if (this.diggingtiles[0] in this.digtiles&&this.diggingtiles[1] in this.digtiles&&this.diggingtiles[2] in this.digtiles&&this.diggingtiles[3] in this.digtiles){
setani shovel,;
tiles[this.targettiles[1],this.targettiles[2]] = this.dugtiles[2];
tiles[this.targettiles[4],this.targettiles[5]] = this.dugtiles[3];
tiles[this.targettiles[7],this.targettiles[8]] = this.dugtiles[0];
tiles[this.targettiles[10],this.targettiles[11]] = this.dugtiles[1];
updateboard this.targettiles[7],this.targettiles[8],32,32;
}
else if (this.diggingtiles[0] in this.digtilesgrass&&this.diggingtiles[1] in this.digtilesgrass&&this.diggingtiles[2] in this.digtilesgrass&&this.diggingtiles[3] in this.digtilesgrass){
setani shovel,;
tiles[this.targettiles[1],this.targettiles[2]] = this.dugtilesgrass[2];
tiles[this.targettiles[4],this.targettiles[5]] = this.dugtilesgrass[3];
tiles[this.targettiles[7],this.targettiles[8]] = this.dugtilesgrass[0];
tiles[this.targettiles[10],this.targettiles[11]] = this.dugtilesgrass[1];
updateboard this.targettiles[7],this.targettiles[8],32,32;
}
else {setani shovel2,; return;}}

this.random = random(0,20);
sleep .3;
if (this.random<5){
lay2 greenrupee,this.targettiles[1],this.targettiles[2]-1;
}
else if (this.random<7){
lay2 bluerupee,this.targettiles[1],this.targettiles[2]-1;
}
else if (this.random<13){
lay2 bombs,this.targettiles[1],this.targettiles[2]-1;
}
else if (this.random<18){
lay2 darts,this.targettiles[1],this.targettiles[2]-1;
}
else if (this.random>18){
lay2 redrupee,this.targettiles[1],this.targettiles[2]-1;
}

}[/CODE]

You should try learn how to use vecx, and vecy in your scripts. They’re pretty good for cutting down repeated code like what you’ve got here.
Also you should study what I did and see how you can use it to your advantage.
http://forums.graal.in/forums/showthread.php?6245-Shovel
Notice the reduced bulk. Another thing is to use == for comparitive statements and keep = for assignment statements.
For example

if (this.variable = 12){
  message hey!;
}

Isn’t correct, it should be:

if (this.variable == 12){
  message Hey!;
}

Other than that, I find it nice that you’ve taken an embrace to scripting and that you’re trying to contribute. It’d be nice to have a few more scripters around here :slight_smile:

Oooh, so that’s what vecx and vecy are for!
I always tought they were some complex math operation.

They’re kinda exactly what they’re named. Vectors. A vector is just a object if you’d call it that has a magnitude(weight/length/etc…) and a direction.
Is if you input 0 in vecx you’d expect to get 0 out since it’s vertical not horizontal. Where as if you put 0 in vecy you’d get out -1 since it’s heading in a direction on the y-axis in a negative direction.

It’s a kinda lame explanation but to be honest there’s not alot to get. The best example I know is staff boots.

if (playerenters){
  this.speed = 1.4;
}

if (keypressed && strtofloat(#p(0)) == keycode(x)){
  this.on = (this.on+1)%2;
  timeout = 0.05;
}

if (timeout && this.on == 1){
  for (this.key = 0; this.key <4; this.key++){
    if (keydown(this.key)){
      playerx += vecx(this.key)*this.speed;
      playery += vecy(this.key)*this.speed;
    }
  }
  timeout = 0.05;
}