PDA

View Full Version : Dark Form



Grayswandir
01-15-2007, 12:42 AM
My first script:
Hit R to switch to a "Dark Link" which gives him the master sword, golden ring, and regenerating hp while constantly losing magic.

However, when you switch out of it, you are given back a wooden sword. Does anyone know how to read Link's current sword level without having to check for the presence of each individual item? (if has Sword 1, else if has sword 2, etc.)

EDIT: Changed it around to an item script, with a global script running in the background.
Now you can have several different forms, as well.




// ================================================== =============
// DarkForm Item:
// Must include the global script ability.
//
// Use item to toggle between normal Link and a Dark Form,
// which gives him the Master Sword and the Gold Ring,
// as well as regeneration, all for the price of magic.
//
// If Link tries to activate a different form while one is already
// active, the current form will deactivate, and Link must use the
// item again to activate the new one.
//
// Arguments for ability.toggle_darkform():
// 1: Number of frames for Link to lose 1/32 point of magic.
// Set to 0 for no loss.
// 2: Number of Hearts healed per frame, in sixteenths.
// 3: Amount of magic in 32nds that one frame of healing costs.
// 4: Item Id of first item to give/take away.
// 5: Item Id of second item to give/take away.
// ================================================== =============

// Gives golden ring, master sword, and drains magic
item script darkform_item {

void run() {
ability.toggle_darkform(12, 0, 0, 61, 36);
}

}

// Gives golden ring, mirror shield, and heals.
item script darkform_item2 {

void run() {
ability.toggle_darkform(0, 1, 1, 61, 37);
}

}

global script ability {

bool darkform_activated = false;
int darkform_delaycount = 0;
int darkform_magicdelay = 0;
int darkform_healamount = 0;
int darkform_healcost = 0;
int darkform_item1 = 0;
int darkform_item2 = 0;

void run() {
while(true) {
darkform(darkform_magicdelay, darkform_healamount, darkform_healcost);
Waitframe();
}
}

void darkform(int magic_delay, int heal_amount, int heal_cost) {
if(darkform_activated) {
if(Link->HP < Link->MaxHP) {
if(Link->MP >= heal_cost) {
Link->MP = Link->MP - heal_cost;
if(Link->MaxHP - Link->HP > heal_amount) {
Link->HP = Link->HP + heal_amount;
} else {
Link->HP = Link->MaxHP;
}
}
}
if(Link->MP == 0 && magic_delay > 0) {
set_darkform(false);
} else {
darkform_delaycount = darkform_delaycount + 1;
if(darkform_delaycount == magic_delay) {
Link->MP = Link->MP - 1;
darkform_delaycount = 0;
}
}
}
} // end of void darkform

void toggle_darkform(int delay, int heal, int cost, int item1, int item2) {
if(!darkform_activated && (Link->MP > 0 || delay == 0)) {
darkform_magicdelay = delay;
darkform_healamount = heal;
darkform_healcost = cost;
darkform_item1 = item1;
darkform_item2 = item2;
set_darkform(true);
} else {
set_darkform(false);
}
}

void set_darkform(bool state) {
darkform_activated = state;
Link->Item[darkform_item1] = state;
Link->Item[darkform_item2] = state;
if(!state) {
darkform_delaycount = 0;
}
}

}

idontknow
01-15-2007, 01:01 AM
Is this script for an item? If so, i'm still not sure how to attach scripts to an item or compile them or anything. This sounds like it would be useful for an item that grants link "Fierce Diety" status.

Nick
01-15-2007, 01:16 AM
This is a ffc script. As such, you have to attach it to a ffc and put it on any screens that you desire for this to happen on. :shrug:

However, I could see how it'd be useful for an item... but the problem comes with how item scripting currently works: item scripts cannot loop. :sweat:

As far as reading for Link's sword level, the only way to check it is to check for the items (as far as I know, anyway). :shrug:

C-Dawg
01-15-2007, 01:51 AM
You want Link to go back to whatever sword he was using before, right? Then just click the "Link Keeps Old Items" quest rule. Once you take away the new goodies, Link will have the old versions he had before.

Alternatively, you can set global variables to track what items he had before the change and then re-set his inventory after the change.

Grayswandir
01-15-2007, 12:39 PM
Much thanks for the help with the quest rule.

I changed it around to an item/global script, with support for several different forms as well. Just run the global script, and attach the item script for a form to whatever item you want to activate it.
There's still a small problem though, in that whenever I exit the form, my MP is truncated to the nearest integer (1/8th of the meter), and I don't know why.

C-Dawg
01-15-2007, 01:09 PM
The cochles of my heart are warmed by the number of people adding to the scripting library, by the way.

CJC
01-15-2007, 11:36 PM
After a little experimenting with your script (And by a little I mean a lot), I was able to create that oh so wonderful feature, Active Link Tile Modifiers.


This code of yours is amazing, thank you for crafting it.

jman2050
01-15-2007, 11:41 PM
Okay, this is awesome.