Read-only archive of the Armageddon Games Forums Archive (2000–2026) · About this archive

items.zh

13 replies · 110,104 views · Started 24 March 2015

https://dl.dropboxusercontent.com/u/94061979/ZC/scripts/items.zh

Updated link: https://1drv.ms/u/s!Anx-XGRXU_d2gsxpd1bZWFoFLq6x_Q

Update 3/26/14
-some function name fixes
-added GetActiveEquipmentOfFamily()
-added demo script EquipmentSlotX

A header for managing and using Equipment as well as other item related functions.
This is a header I have been working on for a while. It started out as just some functions I made for my quest but when interest in those functions grew(and the quest died) I decided to make it into a header. It is still a WIP. Also even though I am pretty sure there is no items.zh already the name could change if needed.

The biggest part of this header is the ability to use Equipment on Inputs other than A and B. I wanted to make that very simple to do. I really want this to get plenty of testing so if you try it out please post some feedback. I am also sorry for it's state. Some organization, commenting, refining, and possibly renaming of some functions are still in order. I am also working on some example scripts to help people who are not scripters get some use out of this.

This script allows you to use

[hide=Use hardcoded equipment on all extra buttons]
All Extra inputs including L & R have been hardcoded to use an item if acquired

import "items.zh"
import "std.zh"

global script UseEquipmentOnExInput{
void run(){
while(true){
//UseEquipmentOnExInput(Ex1, Ex2, Ex3, Ex4, L, R);
UseEquipmentOnExInput(I_CANDLE2, I_BRANG1, I_WAND, I_HOOKSHOT1, I_ARROW1, I_BOMB);
Waitframe();
}
}
}


[/hide]
[hide=Use hardcode equipment on one button]
Pressing Ex1 will use the Roc's Feather making Link Jump
import "items.zh"
import "std.zh"

global script UseEquipment{
void run(){
while(true){
ResetEquipment();
UseEquipmentOnInput(I_ROCSFEATHER, EQP_INPUT_EX1);
Waitframe();
}
}
}


[/hide]

Script that creates an Ex1 Equipment slot that functions like A and B
This one is a little more involve. You will need to make a new equipment slot
on you subscreen and then figure out the coordinates for Zscript and put it in the constants.
To select equipment for Ex1 press L and R. Demo file
[hide='Equipment Slot X']
import "items.zh"
import "std.zh"

const int XSLOT_X = 100;
const int XSLOT_Y = -24;

//Equipment Slot Ex1
int EquipmentX[4];
const int EX1_ID = 0;
const int EX1_OLDID = 1;
const int EX1_TILE = 2;
const int EX1_CSET = 3;

global script EquipmentSlotX{
void run(){

while(true){
ResetEquipment();
EquipmentX();

Waitframe();
}
}
bool EquipmentXIsValid(){
return (EquipmentX[EX1_ID] > 0 && EquipmentX[EX1_ID] < 256);
}
void ShiftEquipmentX(int dir){
if(EquipmentXIsValid()){
int storeB = EquipmentB(); //save EquipmentB value
SwapEquipmentB(EquipmentX[EX1_ID]); //Change EquipmentB to EquipmentX[EX1_ID]
Link->SelectBWeapon(dir); //Adjust EquipmentB as directed
if(EquipmentB() == storeB)Link->SelectBWeapon(dir); //make sure we don't set X to B
EquipmentX[EX1_ID] = EquipmentB(); //set X
SwapEquipmentB(storeB); //reset B
}
}
void UpdateEqupimentX(){
//Makes sure the value of EquipmentX is in inventory or another item of the same family is in inventory
if(EquipmentXIsValid()){
int get = GetActiveEquipment(EquipmentX[EX1_ID]); //Confirm EquipmentX or Equipment in the same family is in inventory
if(get == -1) get = GetActiveEquipmentOfFamily(EquipmentX[EX1_ID]); //Link does not have that Equipment try Equipment of Family
if(get == -1) EquipmentX[EX1_ID] = 0; //Link does not have that Equipment
else if(get != EquipmentX[EX1_ID]) EquipmentX[EX1_ID] = get; //Equipment found set it to X
}

//If EquipmentX has no value
else if(CountActiveEquipment() > 2) {
EquipmentX[EX1_ID] = EquipmentB();
}
//change EquipmentX if it it already on A or B and we are not using EquipmentX
if( (EquipmentX[EX1_ID] == EquipmentB() || EquipmentX[EX1_ID] == EquipmentA()) && !Link->Misc[EQP_LINK_MISC]){
ShiftEquipmentX(DIR_RIGHT);
}
//if EquipmentX has changed update draw variables
if(EquipmentX[EX1_ID] != EquipmentX[EX1_OLDID]){
GetItemTileAndCSet(EquipmentX[EX1_ID]);
EquipmentX[EX1_OLDID] = EquipmentX[EX1_ID];
}
}
//get tile and cset of our equipment to draw
void GetItemTileAndCSet(int it){
item get = Screen->CreateItem(it);
EquipmentX[EX1_CSET] = get->CSet;
EquipmentX[EX1_TILE] = get->Tile;
Remove(get);
}
void EquipmentX(){
//makes sure we have a good equipment ID and it's not a duplicate
UpdateEqupimentX();
//Press L or R to change EquipmentX
if(Link->PressL && CanUseEquipment()) ShiftEquipmentX(DIR_LEFT);
else if(Link->PressR && CanUseEquipment()) ShiftEquipmentX(DIR_RIGHT);


if(EquipmentXIsValid()){
//draw item tile to subscreen
Screen->FastTile(7, XSLOT_X, XSLOT_Y, EquipmentX[EX1_TILE], EquipmentX[EX1_CSET], 128);
//Use our equipment with with the right input
UseEquipmentOnInput(EquipmentX[EX1_ID], EQP_INPUT_EX1);
}
}
}


[/hide]

A few small updates to the header. Nothing to get all worked up about.

I completed the example script for creating a new item slot. It of course requires you to have a space for it to draw on the subscreen. You adjust where it goes with the constants XSLOT_X and XSLOT_Y. Unfortunately it seems the coordinates for Y in the subscreen editor are a little different than Zscript so a little guesswork and trial and error goes into that. I made a little demo quest for this one. Use L and R to change the equipment in the X Slot.

The demo file
The script file

[MENTION=38528]SUCCESSOR[/MENTION]
Have you updated this recently, to a more 'final' version? I've been waiting for news on it, so that I can update scripts to depend on it, rather than what I've been using, but I never heard back from you (PM'd about six months back).

Does anyone have a mirror of this library? The download links are all dead, most likely due to dropbox killing public folders.

Lunaria wrote:Does anyone have a mirror of this library? The download links are all dead, most likely due to dropbox killing public folders.

I have some of his functions cloned in my old ItemHandling.zh header. I may have the newer one, on a server somewhere.

Is there a specific function, or set of utilities that you needed from it, failing that?

THis old, ugly weapon script uses some of them, but it does not have L/R Ex item buttons in it. The general premise for that, is this:

Store an item ID to a button somehow.
When the button is pressed, read the item stored to it.
Set that item to A or B.
Fake a press of A or B (respectively).

Not pretty, and the one frame graphical glitch will probably irritate you; which means scripting a visual fix for it.

Future ZC Notes and Notions
[spoiler]
I'm leaning toward adding something along the lie of Game->RunItemScript() to ZScript in the future to allow using a scripted item from any button, and possibly Link->UseItem() if i want to lose more sleep, and more sanity. I've considered adding buttons mapped to all of the eight non-directional buttons for 2.60. That'll be joyful, and merit a other case of whiskey.
[/spoiler]

Well I was both wanting to look into how it handled things in code as well as maybe implementing it depending on how it worked, I'm not yet certain exactly what kind of solution I want so I really can't see exactly what I need from it. If you do find it that would be appreciated.

Also paging [MENTION=38528]SUCCESSOR[/MENTION] in case you're still around and have it.

Lunaria wrote:Well I was both wanting to look into how it handled things in code as well as maybe implementing it depending on how it worked, I'm not yet certain exactly what kind of solution I want so I really can't see exactly what I need from it. If you do find it that would be appreciated.

Also paging [MENTION=38528]SUCCESSOR[/MENTION] in case you're still around and have it.

Sorry for the late reply. I have updated the OP with a new link on my onedrive. I don't really know what is happening with dropbox. I'll try getting that one fixed as well.

Lelouche Vi Britannia wrote:Any updates? Having more equipment buttons is a nice thing.

Sorry, I have not really updated this. Lost touch with ZC and ZScript. If there is anything lacking, faulty, or other such let me know! I realize this reply is coming a year late, but it goes to anyone else who might have a similar question.

SUCCESSOR wrote:Sorry for the late reply. I have updated the OP with a new link on my onedrive. I don't really know what is happening with dropbox. I'll try getting that one fixed as well.

Sorry, I have not really updated this. Lost touch with ZC and ZScript. If there is anything lacking, faulty, or other such let me know! I realize this reply is coming a year late, but it goes to anyone else who might have a similar question.


[MENTION=38528]SUCCESSOR[/MENTION] : You may want to consider adding it to the databases on zeldaclassic.ocm and pureze.com.

One nice thing that I added to 2.54 and above, thatwill benefit this, and to which you may want to update it (once released), is:

[FONT=Courier New]
int SetItemSlot(int itm_id, int slot, int force);

/**
* This allows you to set Link's button items without binary operations, and to decide whether to
* obey quest rules, or inventory.
*
* When using this, 'itm_id' is the ID number of the item.
* Set 'slot' to one of the following: 0 == Slot B, 1 == Slot A
* Other buttons may be added in the future, and other values for 'slot' are thus, reserved.
* Set the flags on 'force' as follows:
* const int ITM_REQUIRE_NONE = 0
* const int ITM_REQUIRE_INVENTORY = 1
* const int ITM_REQUIRE_A_SLOT_RULE = 2
* Thus, require both inventory, and following quest slot rules, force == 3. [/FONT]

Thus, needing to set up a subscreen, or using idiotic functions to page through items, is a duck.

I want to add either, or both, RunitemScript(int script) and Useitem(int item_id) at some point--I may have mentioned this in the thread earlier, but I've forgotten--and I want to add bitem slots for the extra buttons, plus L and R; hence the configuration for SetItemSlot(), which can be expanded to cover additional slots, if we add more.

The real issue, is the suibscreen: I could add item slots for more buttons, but making the subscreen show them would be hellish.

Lunaria wrote:Well I was both wanting to look into how it handled things in code as well as maybe implementing it depending on how it worked, I'm not yet certain exactly what kind of solution I want so I really can't see exactly what I need from it. If you do find it that would be appreciated.

One of the things that I did, to suppress the graphical inconsistency, was this:

Set the tile positions for A and B item slots (the subscreen icons) as constants:
const int SUBSC_PSV_ITEM_A_X = n;
const int SUBSC_PSV_ITEM_A_Y = n;
const int SUBSC_PSV_ITEM_B_X = n;
const int SUBSC_PSV_ITEM_B_Y = n;

Draw a solid black tile over the item that I am substituting.
Draw the item tile for the item the item that is truly held in that slot (the one that I am temporarily shifting out) over the black tile.

This overrides the graphics of the item that I am using for a frame, so that the graphical glitch is less obvious.

I was more clever with 2.54, and in that version, I do:


//global

const int TEMP_ITM_B_ID = 0;
const int TEMP_ITM_B_TILE = 1;
const int TEMP_ITM_A_ID = 2;
const int TEMP_ITM_A_TILE = 3;
const int TEMP_ITM_L_ID = 4;
const int TEMP_ITM_L_TILE = 5;

int tempitem[8]; //holds the item that should be in the slot, and its tile.
// Item that should be there: item id (B), tile (B), item id (A), tile (A)
//item that we are using this frame tempidtem_id, tempitem_tile

void UseItemOnL(int itm_id)
{
itemdata temp = Game->LoadItemData(GetItemSlot(SLOT_B));
itemdata itmL = Game->LoadItemData(itm_id);
//store the original item information for the slot
tempitem[TEMP_ITM_B_ID] = temp->ID; //what was in the slot.
tempitem[TEMP_ITM_B_TILE] = temp->Tile; //..
tempitem[TEMP_ITM_L_ID] = itm_id;
tempitem[TEMP_ITM_L_TILE] = temp->Tile; //the original tile for the temporary item
itmL->Tile = tempitem[1];
Link->SetItemSlot(itm_id, SLOT_B, 0);
Link->PressB = true;
Waitframe();
}

void RestoreItemB()
{
itemdata temp = Game->LoadItemData(tempitem[TEMP_ITM_L_ID]);
itemdata real = Game->LoadItemData(tempitem[TEMP_ITM_B_ID]);
Link->SetItemSlot(tempitem[TEMP_ITM_B_ID], SLOT_B, 0); //restore the true item
temp->Tile = tempitem[TEMP_ITM_L_TILE]; //restore the original tile.
}

ZoriaRPG wrote:[MENTION=38528]SUCCESSOR[/MENTION] : You may want to consider adding it to the databases on zeldaclassic.ocm and pureze.com.

Maybe, if I get around to it.

ZoriaRPG wrote:
Thus, needing to set up a subscreen, or using idiotic functions to page through items, is a duck.

You don't need to set up a subscreen for this. subscreens by default let you toggle linearly through all items. It's custom subscreens that can be a problem for this header. Other than that cycling through items isn't really so much of an issue so far as I can tell. And seems to rarely be visible. If people actually start using it in quests we might get a better idea though. Most people generally just want to have an extra button for a single constant item, from what I've seen.

SUCCESSOR wrote:Maybe, if I get around to it.

You don't need to set up a subscreen for this. subscreens by default let you toggle linearly through all items. It's custom subscreens that can be a problem for this header. Other than that cycling through items isn't really so much of an issue so far as I can tell. And seems to rarely be visible. If people actually start using it in quests we might get a better idea though. Most people generally just want to have an extra button for a single constant item, from what I've seen.

Eh? Of course you need a subscreen. You can't change the item on A or B to another item without a subscreen, as the 2.50 functions to set Link's equipment make use of the subscreen layout, to page through items until you find the one that you want. Thus, if you want to temporarily substitute an item into B, if you do not have it on the subscreen, or paging through the subscreen in a linear manner would not land upon it, you would not be able to set it.

The default subscreens allow you to cycle through the default items in ZC, if that is what you mean. That is not true, if you add special/new items to a quest. This method is also horrific and slow, as it requires iterating the subscreen objects, and that does quite a lot (internally).

ZoriaRPG wrote:Eh? Of course you need a subscreen. You can't change the item on A or B to another item without a subscreen, as the 2.50 functions to set Link's equipment make use of the subscreen layout, to page through items until you find the one that you want. Thus, if you want to temporarily substitute an item into B, if you do not have it on the subscreen, or paging through the subscreen in a linear manner would not land upon it, you would not be able to set it.

The default subscreens allow you to cycle through the default items in ZC, if that is what you mean. That is not true, if you add special/new items to a quest. This method is also horrific and slow, as it requires iterating the subscreen objects, and that does quite a lot (internally).

I'm well aware of all of that. But the options are limited. If someone adds an item to the default subscreen and don't match the behavior to it, they're an idiot. I can't help the stupidity of others. The quest developer needs to understand how this works and adjust their quest accordingly. If there are improvements I can make to this for an official ZC release let me know and I will try to get to it before school starts up again and sucks me back into the void.

SUCCESSOR wrote:I'm well aware of all of that. But the options are limited. If someone adds an item to the default subscreen and don't match the behavior to it, they're an idiot. I can't help the stupidity of others. The quest developer needs to understand how this works and adjust their quest accordingly. If there are improvements I can make to this for an official ZC release let me know and I will try to get to it before school starts up again and sucks me back into the void.

I don't know when that would be mate. 😉

2.54 is close to Beta, but I need to finish implementing all of the datatypes and some less dramatic stuff. It sucks, as I lost the combodata vars in my HDD crash. I thought that I had committed it to the repo, but apparently I did not, so I have the added bonus if doing that again. It's a mere 83 instructions . 😞

...plus some new stuff that I was prepared to append to it. Ugh.

Alpha 21 will be close to what I envision as 'Beta 0'.

SUCCESSOR wrote:A few small updates to the header. Nothing to get all worked up about.

I completed the example script for creating a new item slot. It of course requires you to have a space for it to draw on the subscreen. You adjust where it goes with the constants XSLOT_X and XSLOT_Y. Unfortunately it seems the coordinates for Y in the subscreen editor are a little different than Zscript so a little guesswork and trial and error goes into that. I made a little demo quest for this one. Use L and R to change the equipment in the X Slot.

The demo file
The script file

Any chance you might have an updated download link for that script file?