Why is it you always beat me to answering people's questions? It's not fair!
Sorry ^_^
Well, why do you want to set Link's MP to a variable?
So that you can have the script run, then add a clause that says to undo what you just told it to do?
Wouldn't it be better to just tell the script not to up the frame delay whilst Link is on said flag?
It's also not as easy as that to check where Link is, and what flags are at that position.
You have to say 'check for the combo at Link's X position and Link's Y position to see whether that flag is placed on it'.
Something like:
Screen->ComboF[ComboAt(Link->X+8,Link->Y+8)] != 98
I'll run through that a bit better:
Firstly, the command is 'int ComboF[i];'.
This means that ZC checks for what flag is at the position 'i', and then sends it back through the integer.
This is a 'Screen' Variable, so it has to have the 'Screen->' pointer before it.
Now, checking for the flag at 'i', where ZC counts along each row of pixels, then when it gets to the end, starts again at the next row, isn't all too helpful.
This is where 'ComboAt(x,y)' comes into play.
It's a utility routine from std.zh, which allows you to convert a single number pixel reference into geometric coordinates.
Then, within ComboAt, we have 'Link->X' and 'Link->Y'. 'X' and 'Y' are (reasonably obvious) generic integers, and with the 'Link->' pointer, we tell ZC that we're referencing Link's coordinates.
I've added 8 onto both of them, because passing '(Link->X, Link->Y)' through a parameter brings up the coordinates of his top-left pixel, and that's not where he 'is' to you, so by adding on those 8 pixels, we make it reference the centre of Link instead.
'!=' means 'is not equal to', so this just makes sure Link is not standing on a safe zone.
And finally, why make it 96?
We have script specific flags nowadays, might as well use'em y'know?
I've put it to 98.
Unless you wanted it to be 96 for some specific reason? 😕
Anyway, enough of that; let's put it into the script.
import "std.zh" // I've put this on the first line, just to emphasize that it's not attributed just to your script. It's generic, and only needs to be (well, only can be) in the script file once. Put all your scripts in the same file, otherwise your impending doom awaits.// My First Script
// Magic Drain
//
// Made Possible by Joe123
//
ffc script magicdrain{
void run(int speed){
int framedelay; //I have declared two integers here that we're going to use later, to make the script not occur every single frame; otherwise Link would die at an alarming rate.
if(speed == 0){speed = 15;} //this line checks whether the integer 'speed', which is 'DO' in the ffc's arguments is == 0. if it is, then it sets it to 15.
while(true){ //this clause is a loop, causing the script to continue checking, rather than just once.
if(Screen->ComboF[ComboAt(Link->X+8, Link->Y+8)] != 98){ // so here we check that Link is not on a safe zone
framedelay ++; //this line increases framedelay by one each frame. We do this so that the script doesn't remove Link's MP so fast.
}
//what this first 'if' clause does then, is make sure Link is not on a safe zone before adding one to the framedelay counter. If he is on a safezone, the counter will not increase, and therefore the script's effects will not be applied.
if(framedelay == speed){ //if the integer 'framedelay' is equal to the value that you give to 'speed' in D0, continue with the script. If you leave speed as 0, this will happen every quarter of a second.
if(Link->MP > 0){ //if Link's MP is greater than 0
Link->MP -=8; //remove 8 MP from Link (8 MP is half a block I think, 1 isn't very much)
}else{ //so, if Link's MP is equal to 0
Link->HP -=8; //remove half a heart from Link (once again, one heart is 16 HP)
}
framedelay = 0; //this resets the framedelay counter
}
Waitframe(); //we need this, otherwise the script will continually loop and freeze the system. Also helps with how long you want to wait for things to happen
}
}
}
EDIT: Oh yeah, and if you ever need to know anything like how to access Link's HP or whatever, you need to check 'zscript.txt'.
It has all of the information you need, and saves you from making things up 😊
Just on a side note to that, all of the functions are in sections. The header for the section is the pointer needed to access the array, ie.
'PlaySound(i);' is in the 'Game' section, therefore you use it via 'Game->PlaySound(i);'
That had me confused for months. Well, possibly a month. I haven't been at this too many months come to think of it.
Anyway.
EDIT2: Oh no, I had a semicolon instead of an L brace in there somewhere.
I've changed it, better copy it over again.
Apologies.
I'm getting quite good at posting novels here 😱