I just spontaneously scripted a univeral chest NPC that could perhaps replace the default one. Dunno, comment it.
If you decide to use it, make sure to replace the parts that are obviously placeholders
NPC Code:
function chest_open() {
// What should happen once the chest is opened, playerrupees ++ or so
}
if (created) {
setstring this.mystring,SOME_UNIQUE_NAME;
}
join chests;
//#CLIENTSIDE
if (created) {
// Same as already done serverside
setstring this.mystring,SOME_UNIQUE_NAME;
// Optional:
setstring this.image_open,your_chest_graphic;
setstring this.image_closed,your_chest_graphic;
this.part_open = { params for setimgpart };
this.part_closed = { params for setimgpart };
// End Optional
setstring this.image_chestitem,graphic_for_item_in_chest;
this.part_chestitem = { params for changeimgpart };
init();
}
class chests:
NPC Code:
if (created)
setshape 1, 32, 32;
if (actionchest_open) {
if (strtofloat(#p(0)) == id) {
if (lindexof(#s(this.mystring), clientr.chests_opened) < 0)
addstring clientr.chests_opened, #s(this.mystring);
chest_open();
}
}
//#CLIENTSIDE
if (playertouchsme) {
if (playery - y == 1 && this.active == true) {
triggeraction x+1, y+1, chest_open, #v(id);
this.active = false;
setimgpart #s(this.image_open), this.part_open[0], this.part_open[1], this.part_open[2], this.part_open[3];
play chest.wav;
showimg 200, #s(this.image_chestitem), x+1 - this.part_chestitem[2]/32, y+0.5 - this.part_chestitem[3]/32;
changeimgpart 200, this.part_chestitem[0], this.part_chestitem[1], this.part_chestitem[2], this.part_chestitem[3];
sleep 2;
hideimg 200;
}
}
function init() {
if (lindexof(#s(this.mystring), clientr.chests_opened) < 0)
this.active = true;
else this.active = false;
if (strlen(#s(this.image_open)) < 1) setstring this.image_open, default_open_graphic;
if (!strlen(#s(this.image_closed)) < 1) setstring this.image_closed, default_closed_graphic;
if (arraylen(this.part_open) < 1) this.part_open = {default params};
if (arraylen(this.part_closed) < 1) this.part_closed = {default params};
if (this.active == false) setimgpart #s(this.image_open), this.part_open[0], this.part_open[1], this.part_open[2], this.part_open[3];
else setimgpart #s(this.image_closed), this.part_closed[0], this.part_closed[1], this.part_closed[2], this.part_closed[3];
}
As I just typed it from scratch, it sure contains some major logical and typistic flaws, please tell me about them.
I suggest that these chests are secured not only by unwalkable tiles or whatever, but by putting them into a seperate level, as it is in theory possible to trigger the chest_open action without in fact touching the chest, using trainers.
Also, they obviously only work with the standard chest size of 2x2 tiles
