PDA

View Full Version : Can someone explain itemclass varible type?



ShadowMancer
08-23-2007, 04:18 PM
I am trying to change an items itemclass with script, I am a bit confused as it says in the docs:

itemclass Class
* The class (the type of item) to which this item belongs.

Alright, itemclass is a varible type right? so I think that I would need to set the Family varible under itemclass..

int Family
* The kind of item to which this class belongs (swords, boomerangs,
* potions, etc.) Use the IC_ constants in std.zh to set or compare this
* value.

So, here is what I wrote:



global script main_script {
void run() {
item drop;
item itm_1;
item itm_2;
item itm_3;
item itm_4;
item itm_5;
itemclass old_cls;
itemclass new_cls;
new_cls->Family = 252;
old_cls->Family = 253;
int item_num = 1;
while(true) {
//Mana timer routine
if (MANA_TIMER >= 100) {
if (Link->MP < Link->MaxMP) {Link->MP += 1;}
MANA_TIMER = 0;}
else {MANA_TIMER += 1;}

if(is_spending > 0) {rupie_taker();}
//Custom Item Drop Routine
if (item_num <= Screen->NumItems()) {
drop = Screen->LoadItem(item_num);
if (drop->Class == old_cls) {
drop->Tile = 0;
drop->Class = new_cls;
itm_1 = Screen->CreateItem(150);
itm_1->X = (drop->X-4)+Rand(8);
itm_1->Y = (drop->Y-4)+Rand(8);

}
item_num += 1;
}
else { item_num = 1; }
Waitframe();
}
}
}


I defined the varibles:
itemclass old_cls;
itemclass new_cls;
new_cls->Family = 252;
old_cls->Family = 253;

Now I want to check to see if Drop->Class (Family??) is equal to itemclass id# 253

if (drop->Class == old_cls)

Then change its class to id# 252

drop->Class = new_cls;

Right, seems like it would work but it does not detect the item at all :confused:

Could someone explain how this works please.

Btw All I really want to do is find some unique way to detect a droped item then create a different item and make the droped item disappear. I tried useing item->Tile which can detect the unique tile alright, change the tile to 0. But the script just keeps creating items despite the fact the the detected item drop is now a different tile, very strange.

Here is my old code if someone wants to test it for themselfs:




global script main_script {
void run() {
item drop;
item itm_1;
item itm_2;
item itm_3;
item itm_4;
item itm_5;
int item_num = 1;
while(true) {
if (item_num <= Screen->NumItems()) {
drop = Screen->LoadItem(item_num);
if (drop->Tile == 31165 && drop->CSet != 0) {
drop->Tile = 0;
drop->CSet = 0;
itm_1 = Screen->CreateItem(150);
itm_1->X = (drop->X-4)+Rand(8);
itm_1->Y = (drop->Y-4)+Rand(8);

}
item_num += 1;
}
else { item_num = 1; }
Waitframe();
}
}
}


:googly::googly::googly::googly:

C-Dawg
08-23-2007, 05:03 PM
Oy. I've just been choosing itemclasses I'm not using the quest (like the glove, whistle, etc) and using those itemclasses for custom things. The subscreen editor lets you select or not select any item you want, which is great for taking advantage of pre-existing itemclasses. We have a ton of them now, what with the rings and such.

It's not perfect, but unless you plan on using EVERY itemclass, it's a little easier for now.

DarkDragon
08-23-2007, 05:13 PM
itemclass is a pointer type, so it's only valid if it points to something. The code


itemclass foo;
foo->Type = bar;

makes no sense because at the time you're assigning to foo's Type, foo isn't pointing to anything. (The compiler should complain about the first line, in fact; probably a bug.)

If there's no LoadItemclass method somewhere, that's an oversight; post a bug report.

ShadowMancer
08-23-2007, 05:21 PM
Oy. I've just been choosing itemclasses I'm not using the quest (like the glove, whistle, etc) and using those itemclasses for custom things.

I don't think you understand what I am asking so i will reiterate:


All I really want to do is find some unique way to detect a droped item then create a different item and make the droped item disappear. I tried useing item->Tile which can detect the unique tile alright, change the tile to 0. But the script just keeps creating items despite the fact the the detected item drop is now a different tile, very strange.


This is the basic idea of what I want. I just figured if the Tile changeing does not work right mabye I can check for a certain itemclass. The itemclass thing has me even more confused so back to square one. Mabye this should be reported as a ZScript bug but I would like some confermation from other ppl before doing that. (see my 2nd code box in the 1st post)

ShadowMancer
08-23-2007, 05:37 PM
If there's no LoadItemclass method somewhere, that's an oversight; post a bug report.

itemclass LoadItemClass(int family)
* Retrieves the itemclass pointer corresponding to the given item family.
* Use the IC_ constants in std.zh as values of family.

The compiler did not complain about the following lines:
itemclass old_cls;
itemclass new_cls;
new_cls->Family = 252;
old_cls->Family = 253;

So okay itemclass is a pointer type I understand that much, so how do I CHANGE the class of a specific item onscreen

itemclass Class
* The class (the type of item) to which this item belongs.

so is this the proper use??:
new_cls = LoadItemClass(252);
item->Class = new_cls;
(I've been trying to wrap my brain around this for awile) :D

(oops double post, sorry)

DarkDragon
08-23-2007, 06:03 PM
Yes. At least in theory, I don't think this corner of ZScript has been extensively tested :)