Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-09-2003, 08:54 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Chest Template

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

Last edited by Loriel; 08-10-2003 at 05:07 PM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:35 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.