PDA

View Full Version : Reverting Items



Majora
09-04-2007, 07:30 PM
Ok, so in my quest, I have the following Items:

Roc's Feather

Roc's Silver Feather

Roc's Golden Feather


They are Level's 1, 2, and 3, respectively. RSF uses 16 MP, while RGF uses 32. As far as I know, the following cannot be done normally, so I need a script that:

Whichever feather (of either Silver or Golden) are in Link's inventory, revert to the regular feather when Link has no magic, and the Gold reverts to silver if enough magic is present to use the Silver, but not the Golden, in case using the Golden feather leaves link with less than 32 MP, or some other items leaves Link with less than 32 MP, also for the Silver to revert to the regular feather when Link has less than 16 MP, but the Regular feather becomes either Silver or Golden, depending on which Link had obtained.



Checks which feather is in Link's inventory. Which ACQUIRED Feather.
If Link has less than the required Magic needed to use either feather (Silver or Gold), the feather turns into one Link has enough Magic to use.

ShadowMancer
09-04-2007, 08:58 PM
going to need a global script, so just stick this in global slot #2 (or add this code to an already existing global script if you need to)



//Global varible
int FEATHER_LEVEL = 0; //you will need to chance this varible when you aquire a new feather

//just add this simple code to you item pickup for each feather
item script feather1{
void run() {
FEATHER_LEVEL = 1;
Feather_check();
}
}

item script feather2{
void run() {
FEATHER_LEVEL = 2;
Feather_check();
}
}

item script feather3{
void run() {
FEATHER_LEVEL = 3;
Feather_check();
}
}
//NOTE you will need to replace ***1 with the ID for feather 1, ***2 w/2 and ***3 w/3

void Feather_check(){
if (FEATHER_LEVEL >= 2 && Link->MP < 32) {
Link->Item[***3] = false;
Link->Item[***2] = true;
}
if (FEATHER_LEVEL >= 1 && Link->MP < 16) {
Link->Item[***2] = false;
Link->Item[***1] = true;
}
if (FEATHER_LEVEL == 2 && Link->MP >= 16) {
Link->Item[***2] = true;
}
if (FEATHER_LEVEL == 3 && Link->MP >= 32) {
Link->Item[***3] = true;
}

}

Just wrote that up quick, let me know if it works

UPDATE: okay took out the global script now its just a function that will be called each time you use a feather, only possible side effect I can see is, say you have feather 3 and you don't have enough MP the first time you try to activate the item nothing (visible) will happen except the feather level will change. its a minor price to pay for now, once ZC 3.0 comes out the lag of writeing to Link->Item should be fixed.

Majora
09-04-2007, 09:06 PM
Just for clarification:

Import ASM Global Script -> Active (None)

Which are the Feather ID's? Where would I find them?

Once the ID's are in, do I just leave it like that? Also, STD.ZH just has the item ID for Roc's Feather, not the other 2... do I make up numbers?

ShadowMancer
09-04-2007, 09:25 PM
What you want to do goto 'Compile ZScript' if you already have ZScripts loaded you will need to first export your scripts, then open the .z file that was just created (open w/ notepad) copy/paste these scripts into the file (make sure you put the globla varible at the top outside of any script, right below import "std.zh") If you don't have any other scripts just save these scripts as is into a notepad, asve as 'all files' and change the extension to .z. Now when you get back to ZQ goto 'Compile ZScript' again and hit import, and choose the file you just made/edited. hit compile (hopefull no errors) then it will ask you to load the scripts into slots load the main_script into Global slot #2 and load the item scripts into item slots.

To get the ID of the item go into the item editor, it will say the ID right on the title bar ex 'Item 0 Rupie' 0 is the ID. While you are there in the Action tab set the script number for each feather (whatever slot you put each script in is the number you use here)

That should do it

Majora
09-04-2007, 09:42 PM
There was an error while compiling... something about expecting a semicolon on token item, needed on line 7:

import "std.zh"

//Global varible
int FEATHER_LEVEL = 0 //you will need to chance this varible when you aquire a new feather

//just add this simple code to you item pickup for each feather
item script feather1{ (This is Line 7)
void run() {
FEATHER_LEVEL = 1;

ShadowMancer
09-05-2007, 11:24 AM
Alright, I edited the script. It should work for you now, I realized that I f*cked it up after I got offline yesterday :rolleyes:

C-Dawg
09-05-2007, 01:47 PM
Hey, you might want to modify that script. As it stands, it will write to Link's inventory every frame depending on his magic level. You should stick some IF statements in there so it only writes if Link doesn't have the proper feather for his magic level.

This is a good idea because, as I recently discovered, writing to Link's inventory is a mega-slow operation. It slowed Zodiac down from a solid 60fps to 12fps. Granted, Dark Dragon has optimized the code somewhat and it runs better now, but food for thought.

ShadowMancer
09-05-2007, 03:18 PM
Yea thats true I remeber reading that the other day, humm mabye I'll change it so it only checks for feather level when the item is actually used, that should cut down on processing time. (I played Zodiac before DD's optimaization heh I already have a slow computer, I was thinking oh no I hope too many scripts don't slow down ZC that much :eek:)

C-Dawg
09-05-2007, 03:34 PM
I streamlined the code a little bit by replacing:

Link->Item[8] = true;

with

If(!Link->Item[8]){ Link->Item[8] = true;}

It's a simple fix, and ensures that the Item variable doesn't get written to each frame. I don't think checking an Item variable has the same sort of overhead.

Majora
09-05-2007, 04:38 PM
So can I just use the script in ShadowMancer's original post?

ShadowMancer
09-05-2007, 08:02 PM
Yea, I updated it so it will not lag now. You won't need a globlal script anymore just the item scripts and the function (its all there in my original post now) Go ahead and keep a copy of the old one (i did not save it) try them both, if the original one causes slowdown use the updated one.

Majora
09-12-2007, 09:51 PM
Hmm... the script in your original post does not seem to work... It compiles fine, and I assign "feather1" to Roc's Feather, "feather2" to Roc's Silver Feather, and "feather3" to Roc's Golden Feather. When I test it, I can't jump anymore at all when I've used all my magic using the other 2 feathers.

ShadowMancer
09-13-2007, 09:58 PM
New approach:



import "std.zh"
//Global vars
int MAX_ROC_LEV = 0;
int CUR_ROC_LEV = 0;

item script pickup_roc1{
void run() {
MAX_ROC_LEV = 1;
}
}

item script pickup_roc2{
void run() {
MAX_ROC_LEV = 2;
}
}

item script pickup_roc3{
void run() {
MAX_ROC_LEV = 3;
}
}

global script main_script{
void run(){
while(true){
roc_change = CUR_ROC_LEV;
if (Link->MP >= 32 && MAX_ROC_LEV == 3) {CUR_ROC_LEV = 3;}
if (Link->MP >= 16 && Link->MP < 32 && MAX_ROC_LEV >= 2) {CUR_ROC_LEV = 2;}
if (Link->MP < 16 && MAX_ROC_LEV >= 1) {CUR_ROC_LEV = 1;}
if (CUR_ROC_LEV != roc_change){
if (CUR_ROC_LEV == 3) {
Link->Item[**3] = true;
Link->Item[**2] = false;
Link->Item[**1] = fales;
}
if (CUR_ROC_LEV == 2) {
Link->Item[**3] = false;
Link->Item[**2] = true;
Link->Item[**1] = fales;
}
if (CUR_ROC_LEV == 1) {
Link->Item[**3] = false;
Link->Item[**2] = false;
Link->Item[**1] = true;
}
Waitframe();
}
}
}


give that a spin,
oh the item scripts will be executed when you pickup the item not use it (make sure you put the script number in the item editor under pickup)
As always keep me updated on how it works :)