PDA

View Full Version : Global Scripts...



Archangel
04-20-2009, 12:12 AM
import "std.zh"

global script potion{
bool use = false
void run(){
while(true){
if(Link->InputL = true && Link->InputR = true){
if(Link->Item[40] = true){
Link->Item[40] = false;
Link->ItemJinx = 0;
Link->SwordJinx = 0;
//We restore HP and MP as it is done with potions.
bool use = true;
waitframe();
}
else if(Link->Item[39] = true && use = false){
Link->Item[39] = false;
Link->ItemJinx = 0;
Link->SwordJinx = 0;
//We restore HP and MP as it is done with potions.
bool use = true;
waitframe();
}
else{
waitframe();
}
}
}
}
}

The desired effect is to simply have the potions easier to use by simply pressing L and R at the same time. "Z+X using default keys." This also allows you to use them if your Jinx by both types of bubbles. Also, is the rest of it look functional?

pkmnfrk
04-20-2009, 01:12 AM
import "std.zh"

global script potion{
void run(){
while(true){
if(Link->InputL && Link->InputR) DoPotionUse();
Waitframe();
}
}

void DoPotionUse() {
if(Link->Item[I_POTION2]) {
Link->Item[I_POTION2] = false;
Link->Item[I_POTION1] = true;
} else if(Link->Item[I_POTION1]) {
Link->Item[I_POTION1] = false;
} else {
return;
}

Link->ItemJinx = 0;
Link->SwordJinx = 0;
//We restore HP and MP as it is done with potions.
Link->HP = Link->MaxHP;
Link->MP = Link->MaxMP;

//so this is not triggered next frame
Link->InputL = false;
Link->InputR = false;
}
}

No idea how one could simulate the filling effect of a potion, so don't sweat it, and just restore it instantly.

A few tips:

- When comparing booleans in an if statement, you don't have to go:


if(myBoolean == true)

Just go:


if(myBoolean)

(If you do write " == true", make sure you DON'T write " = true", as that's entirely different!)

- Variables can either go inside a function, or outside the whole script. They cannot go inside the script, but outside a function.

- When writing global scripts, please format them like I did, so that it's easier to combine scripts. Now, it's easy to combine with the ladder script, or whatever.

Joe123
04-20-2009, 03:30 AM
No idea how one could simulate the filling effect of a potion, so don't sweat it, and just restore it instantly.

:eek:
Really?

Store the amount of HP you need to give Link in an integer, then run a for loop for the length of that integer and return 1 hp every frame.
Or something.

Gleeok
04-20-2009, 03:44 AM
Yeah, that's almost it. But here's what you want:



// in your conditional statement
int dif = Link->MaxHP - Link->HP;



// in your main loop
if(dif > 0){
dif--;
Link->HP++;
Game->PlaySound(SFX_REFILL);
}




That will restore hearts as per Z1 style.

Archangel
04-20-2009, 10:57 AM
Try compiling it first guys. It saves a bunch of hassle on my part. :rolleyes:

I keep geting a T21 error on line 191. It can't match DoPotionUse.

Joe123
04-20-2009, 11:04 AM
Try compiling it yourself, it saves a bunch of hassle on our part.
The people who are writing the scripts are doing you a favour.
I just tried that script and it compiles fine for me.


And not quite Gleeok, Z1 doesn't restore a 16th of a heart every frame, it restores a whole heart doesn't it?

Archangel
04-20-2009, 11:18 AM
If you used pkmnfrk's script. Yes, but what if I wanted to do what Gleeok suggested. Which means I'm implementing his idea wrong.

Joe123
04-20-2009, 12:22 PM
Oh.


int dif;

global script potion{
void run(){
while(true){
if(Link->InputL && Link->InputR) DoPotionUse();
Waitframe();
}
}

void DoPotionUse() {
if(Link->Item[I_POTION2]) {
Link->Item[I_POTION2] = false;
Link->Item[I_POTION1] = true;
dif = Link->MaxHP - Link->HP;
} else if(Link->Item[I_POTION1]) {
Link->Item[I_POTION1] = false;
dif = Link->MaxHP - Link->HP;
} else if(dif == 0){
return;
}

Link->ItemJinx = 0;
Link->SwordJinx = 0;
//We restore HP and MP as it is done with potions.
Link->HP = Link->MaxHP;
Link->MP = Link->MaxMP;

//so this is not triggered next frame
Link->InputL = false;
Link->InputR = false;
dif--;
Link->HP++;
Game->PlaySound(SFX_REFILL);
}
}