PDA

View Full Version : [Request] Custom potions



Shazza Dani
12-20-2008, 11:20 PM
I'm posting this here because I'm pretty sure this can't be done without scripting.

I want to have seperate potions for HP and MP. I know I can edit the normal potions to refill HP only, but can I make a custom item to refill MP?

Russ
12-21-2008, 01:51 AM
Sure you can. It would be a very simple script. I might try to right it. I'll see if I can.

Edit:



import "std.zh"

//This script, when attached to an item, works as a magic potion.
//It refills Link's magic, but disappears after one use.
//A simple script, but useful.
//Set D0 to be the ID of the item.

item script MagicPotion{

void run (int id){

Link->MP=Link->MaxMP;
Link->Item[id] = false;

}

}


I haven't tested it, but it compiles fine.

Shazza Dani
12-21-2008, 02:35 AM
It works~

Though… I forgot to specify that I only want it to refill 128MP, not 100%.

EDIT: Blerrblerrblehgh.

Joe123
12-21-2008, 05:58 AM
Urm....

When you pick up a magic jar item, does your HP increase steadily or instantly?
If it's steadily, then this script wouldn't be very hard to do.

If it's instantly then you'd have to add a section to the global script which is a bit of a pain really.

Shazza Dani
12-21-2008, 06:21 AM
Ya' know, that part's not important. Forget the gradual refill. What I really need if for the potion to fill 128 MP instead of the maximum. Also, how would I change this to work for HP, so I can make custom health potions as well?

Joe123
12-21-2008, 06:30 AM
item script CustomPotion{
void run(int refil,int counter){
if(counter == 0){
Link->MP += refil;
if(Link->MP > Link->MaxMP) Link->MP = Link->MaxMP;
}else{
Link->HP += refil;
if(Link->HP > Link->MaxHP) Link->HP = Link->MaxHP;
}
}
}

D1: Amount to refil
D2: 1 to refil hearts, 0 to refil magic

To take the item away after useage, there's a little checkbox somewhere in the item editor.

Gleeok
12-21-2008, 06:32 AM
No, it's actually quite easy to do.



void Refill(){
int hp = Link->MaxHP-Link->HP;
for(int i;i<mp;i++){
Link->HP++;
Game->PlaySound(SFX_REFILL);
Waitframe();
}
}

void RefillMagic(){
int mp = Link->MaxMP-Link->MP;
for(int i;i<hp;i++){
Link->MP++;
if(Link->MP < Link->MaxMP){
Link->MP++;i++;
}
Game->PlaySound(SFX_REFILL);
Waitframe();
}
}

Shazza Dani
12-21-2008, 06:40 AM
item script CustomPotion{
void run(int refil,int counter){
if(counter == 0){
Link->MP += refil;
if(Link->MP > Link->MaxMP) Link->MP = Link->MaxMP;
}else{
Link->HP += refil;
if(Link->HP > Link->MaxHP) Link->HP = Link->MaxHP;
}
}
}

D1: Amount to refil
D2: 0 to refil hearts, 1 to refil magic

To take the item away after useage, there's a little checkbox somewhere in the item editor.

Schweet~ Everything works. Except you said the D2 thing backwards; 0 is magic and 1 is hearts.

Joe123
12-21-2008, 06:48 AM
Oops. Nevermind.


No, it's actually quite easy to do.

If you want to A: add a section to the global script and B: stop all other functions in the global script for 128 frames or something then yeah sure...

Shazza Dani
12-21-2008, 06:54 AM
Yeah, I'm not worried about the gradual refill. I just wanted the custom MP potion to match the behavior of the normal potion, but I'm just using a custom HP potion instead so the both refill instantly.

Joe123
12-21-2008, 07:24 AM
Well, if the magic jar item refils gradually you could just spawn a magic jar on top of Link when he drinks a potion. I can't remember though.

Russ
12-21-2008, 04:08 PM
Wait, why does it need to be that complicated? Couldn't you just make it like:



import "std.zh"

//This script, when attached to an item, works as a magic potion.
//It refills Link's magic, but disappears after one use.
//A simple script, but useful.
//Set D0 to be the ID of the item.

item script MagicPotion{

void run (int id){

Link->MP+=128;
Link->Item[id] = false;

}

}

Wouldn't that work and be less complicated than your script?

CaRmAgE
12-21-2008, 06:50 PM
Yes, but good programming habits say to make your code as general as possible, so it can be re-used.

Speaking of which, can't this be done w/o scripting (using the item editor)?

Shazza Dani
12-21-2008, 07:02 PM
Speaking of which, can't this be done w/o scripting (using the item editor)?

I don't think so, beause there's only one potion class. You have to use a custom item class to make a seperate potion, and custom classes aren't exactly customisable [without scripting].

Joe123
12-21-2008, 07:25 PM
Yes, but my script works for both types of potion, and you can choose how much it'll refill.

Your script will also fill Link's MP over the max, which is never very good.
You don't really need the line to remove the item either, as there's an option in the item editor which does that.

Russ
12-21-2008, 07:39 PM
Scripts can set Link's MP high than his max MP? Just goes to show how much I know about scripting.

Joe123
12-21-2008, 07:46 PM
Yeah, that's what the 'if(Link->MP > Link->MaxMP) Link->MP = Link->MaxMP;' line is for.