Skyld
08-21-2006, 11:51 PM
Here is a mining system, also posted in the interest of education. Since I will probably never use these scripts, it makes sense to post them for other people!
There are two parts to the mining system; you will need to add the mining class (which is the script for the rocks), and you will also require the axe.
If you put the mining class in a class called "mining", then use the following to make a rock in a level:
this.join("mining");
The axe is simple enough. Just add the weapon, add in your own animation into setani() and play.
You'll need to edit the mining class though; first, you'll need to put the appropriate images in the right place so the rock looks like it's being mined. Secondly, you'll have to insert your own item adding routine, so that you can actually add the item to the player. The method was different on Rudora, so it's no good putting that in there.
It's a fairly old script and could probably do with some work, especially if you want it to be more complex. Enjoy.
Axe weapon:
//#CLIENTSIDE
function onWeaponFired()
{
setani("ani", "params");
freezeplayer(1);
sleep(0.5);
ar = {player.x + (vecx(player.dir) * 2) + 1.1,
player.y + (vecy(player.dir) * 2) + 1.1};
showimg(2001, "@Courier [email protected]@+", ar[0], ar[1]);
triggeraction(ar[0], ar[1], "axe", 10);
hitobjects(1, ar[0], ar[1]);
putleaps(2, this.wx - 0.5, this.wy - 0.5);
sleep(0.5);
setani("idle", "");
hideimg(2001);
}
Mining class:
function onCreated()
{
this.show();
this.offset = 0;
this.owner = "none";
// Define possible types
this.types = {"bronze", "silver", "gold", "crystal", "metal"};
this.idtype = int(random(0, this.types.size()));
this.rtype = this.types[this.idtype];
// set your default rock image here
this.setshape(1, 32, 32);
this.chat = "(Owner: " @ this.owner @ ")";
}
function onActionaxe()
{
if (this.owner == "none")
{
this.owner = player.account;
}
else
if (this.owner == player.account)
{
setTimer(15);
}
this.chat = "(Owner: " @ this.owner @ ")";
this.progress += params[0];
if (this.progress > 199)
{
player.chat = "You got a " @ this.rtype @ " rock!";
// Add your item to the player here
this.progress = 0;
hide();
sleep(15); // <- how long to vanish for
onCreated();
}
else
if (this.progress > 160)
{
// set first progress rock image
}
else
if (this.progress > 120)
{
// set second progress rock image
}
else
if (this.progress > 80)
{
// set third progress rock image
}
else
if (this.progress > 40)
{
// set fourth progress rock image
}
else
if (this.progress > 0)
{
// set last progress rock image
}
}
function onTimeout()
{
this.owner = "none";
this.chat = "(Owner: " @ this.owner @ ")";
}
There are two parts to the mining system; you will need to add the mining class (which is the script for the rocks), and you will also require the axe.
If you put the mining class in a class called "mining", then use the following to make a rock in a level:
this.join("mining");
The axe is simple enough. Just add the weapon, add in your own animation into setani() and play.
You'll need to edit the mining class though; first, you'll need to put the appropriate images in the right place so the rock looks like it's being mined. Secondly, you'll have to insert your own item adding routine, so that you can actually add the item to the player. The method was different on Rudora, so it's no good putting that in there.
It's a fairly old script and could probably do with some work, especially if you want it to be more complex. Enjoy.
Axe weapon:
//#CLIENTSIDE
function onWeaponFired()
{
setani("ani", "params");
freezeplayer(1);
sleep(0.5);
ar = {player.x + (vecx(player.dir) * 2) + 1.1,
player.y + (vecy(player.dir) * 2) + 1.1};
showimg(2001, "@Courier [email protected]@+", ar[0], ar[1]);
triggeraction(ar[0], ar[1], "axe", 10);
hitobjects(1, ar[0], ar[1]);
putleaps(2, this.wx - 0.5, this.wy - 0.5);
sleep(0.5);
setani("idle", "");
hideimg(2001);
}
Mining class:
function onCreated()
{
this.show();
this.offset = 0;
this.owner = "none";
// Define possible types
this.types = {"bronze", "silver", "gold", "crystal", "metal"};
this.idtype = int(random(0, this.types.size()));
this.rtype = this.types[this.idtype];
// set your default rock image here
this.setshape(1, 32, 32);
this.chat = "(Owner: " @ this.owner @ ")";
}
function onActionaxe()
{
if (this.owner == "none")
{
this.owner = player.account;
}
else
if (this.owner == player.account)
{
setTimer(15);
}
this.chat = "(Owner: " @ this.owner @ ")";
this.progress += params[0];
if (this.progress > 199)
{
player.chat = "You got a " @ this.rtype @ " rock!";
// Add your item to the player here
this.progress = 0;
hide();
sleep(15); // <- how long to vanish for
onCreated();
}
else
if (this.progress > 160)
{
// set first progress rock image
}
else
if (this.progress > 120)
{
// set second progress rock image
}
else
if (this.progress > 80)
{
// set third progress rock image
}
else
if (this.progress > 40)
{
// set fourth progress rock image
}
else
if (this.progress > 0)
{
// set last progress rock image
}
}
function onTimeout()
{
this.owner = "none";
this.chat = "(Owner: " @ this.owner @ ")";
}