PDA

View Full Version : FFC Guys



pkmnfrk
12-15-2008, 01:42 AM
FFC guys:


import "std.zh"

//You can edit these
const int fireCombo = 657;
const int fireCset = 1;
const int fireOffX = 48;

//You probably don't need to edit this,
//but you can if you want (no higher than 7!)
const int screenDVal = 7;

//don't edit these
const int flagFire = 1;
const int flagDisappears = 2;
const int flagRepeatable = 4;
const int flagBlockLink = 8;

ffc createFFC() {
for(int i = 32; i >= 0; i--) {
ffc tmp = Screen->LoadFFC(i);

if(tmp->Data == 0) return tmp;
}
}

bool checkBit(int v, int b) {
return (v & b) != 0;
}

void createFire(ffc this) {
ffc tmp = createFFC();
tmp->X = this->X - fireOffX;
tmp->Y = this->Y;
tmp->Data = fireCombo;
tmp->CSet = fireCset;

tmp = createFFC();

tmp->X = this->X + fireOffX;
tmp->Y = this->Y;
tmp->Data = fireCombo;
tmp->CSet = fireCset;
}

void vanish(ffc this) {
int tmp = this->X;
for(int i = 0; i < 20; i++) {
this->X = -32;
Waitframe();
this->X = tmp;
Waitframe();
}
this->X = -32;
}

void blockLink(ffc this) {
if(Link->InputUp && Link->Y <= this->Y + 16) {
Link->Dir = DIR_UP;
}
}

ffc script MessageGuy {
void run(int strid, int flags) {
if(checkBit(flags, flagFire)) {
createFire(this);
}

Waitframes(2);

if(strid > 0) Screen->Message(strid);

if(checkBit(flags, flagBlockLink)) {
while(true) {
blockLink(this);
Waitframe();
}
}
}
}

ffc script ItemGuy {
void run(int strid, int flags, int itemid) {
if(checkBit(flags, flagFire)) {
createFire(this);
}

if(!checkBit(flags, flagRepeatable) && Screen->D[screenDVal] > 0) {
this->X = -32;
return;
}

item theitem;

if(itemid > 0) {
theitem = Screen->CreateItem(itemid);
theitem->X = this->X;
theitem->Y = this->Y + 32;
}


Waitframes(2);

if(strid > 0) Screen->Message(strid);

if(itemid > 0 && checkBit(flags, flagDisappears)) {
while(theitem->isValid()) {
if(checkBit(flags, flagBlockLink)) blockLink(this);
Waitframe();
}
Screen->D[screenDVal] = 1;
vanish(this);
} else if(checkBit(flags, flagDisappears)) {
while(theitem->isValid()) {
if(checkBit(flags, flagBlockLink)) blockLink(this);
Waitframe();
}
Screen->D[screenDVal] = 1;
vanish(this);
if(checkBit(flags, flagBlockLink)) {
while(true) {
blockLink(this);
Waitframe();
}
}
} else {
if(checkBit(flags, flagBlockLink)) {
while(true) {
blockLink(this);
Waitframe();
}
}
}
}
}

ffc script OneItemGuy {
void run(int strid, int flags, int itemid1, int itemid2, int itemid3) {
if(checkBit(flags, flagFire)) {
createFire(this);
}

if(!checkBit(flags, flagRepeatable) && Screen->D[screenDVal] > 0) {
this->X = -32;
return;
}

item theitem[3];
int i = 0;


if(itemid1 > 0) {
theitem[i] = Screen->CreateItem(itemid1);
theitem[i]->Y = this->Y + 32;
i++;
}

if(itemid2 > 0) {
theitem[i] = Screen->CreateItem(itemid2);
theitem[i]->Y = this->Y + 32;
i++;
}

if(itemid3 > 0) {
theitem[i] = Screen->CreateItem(itemid3);
theitem[i]->Y = this->Y + 32;
i++;
}


if(i == 3) {
theitem[0]->X = this->X - 32;
theitem[1]->X = this->X ;
theitem[2]->X = this->X + 32;
} else if(i == 2) {
theitem[0]->X = this->X - 24;
theitem[1]->X = this->X + 24;
} else if(i == 1) {
theitem[0]->X = this->X;
} else {
//...
}


Waitframes(2);

if(strid > 0) Screen->Message(strid);

if(i == 0) return;
bool valid = true;

while(valid) {
if(checkBit(flags, flagBlockLink)) blockLink(this);
for(int j = 0; j < i; j++) {
if(!theitem[j]->isValid()) {
valid = false;
break;
}
}
Waitframe();
}

for(int j = 0; j < i; j++) {
if(theitem[j]->isValid()) {
theitem[j]->X = -32;
}
}

Screen->D[screenDVal] = 1;

if(checkBit(flags, flagDisappears)) {
vanish(this);
} else if(checkBit(flags, flagBlockLink)) {
while(true) {
blockLink(this);
Waitframe();
}
}


}
}

These are three (count 'em, three!) FFC scripts, written by yours truely. They are, at the most basic level, duplications of the built in Room Types "None", "Special Item" and "Take One Item".

However, they allow for different behaviour:


Can use any combo as the graphic for the guy
You can place the guy anywhere on the screen, and the item (if applicable) will move to match
The guy doesn't have to vanish, if you don't want him to
The guy doesn't have to block the top of the screen, if you don't want him to
Fire? No fire? It's up to you!
If you want the room to be repeatable, you can have this in two different ways!
Finally, and most importantly, you can hack the script to change their behaviour to suit yourself!


To use it, simple add it to your script file and compile.

All guys accept two parameters to start with:


Message ID: The string to play. Or, say 0 for no string.
Flags: There is a standard list of flags, which should be added together to get the desired behaviour:
flagFire (1): Create fire FFCs beside the guy
flagDisappears (2): After Link picks up the item, the guy vanishes.
flagRepeatable (4): When Link leaves the room, the guy will come back, item and all.
flagBlockLink (8): Link cannot walk higher than the Guy, effectively blocking the top of the screen until the item is taken.


MessageGuy

He exists solely to deliver a speech of some kind. He doesn't accept any other parameters, and doesn't support flagDisappears or flagRepeatable (I mean, what does this even mean for him? There's no item to get!).

**NOTE: I left out support for flagDisappears on purpose for simplicity, but will add it if there is popular demand

ItemGuy

Thy guy has an item, and is willing to give it to Link. The third parameter should be the ID of the item. The item will appear 32 pixels below the guy. Currently, this is not customizable but through modifying the source.

Possible additions:

A fee for taking the item?


OneItemGuy

This guy has up to three items, and will part with one to help the hero. Upon picking one item up, the other item(s) will vanish into nothingness. Parameters 3 through 5 should be the IDs of the items. Say 0 for no item in that slot. Regardless of which slots you choose, the items will be spaced out nicely.

Possible additions:

A fee for taking an item?


[hr]

I will make more, at some point, but there are limits to what one can do in ZScript. I can probably replicate the 10 Rupee room (with customizable items/patterns ;)), or maybe the Goria room. But, no others.

That said, I can also make up new guys entirely. However, I canNOT do anything like:


A more flexible shop (would be possible with "negative rupees", which don't really exist)
Info rooms (ditto)
Gambling (a la Zelda 1 (for the above reason), but other formats might be possible)
Learn techniques (can't manipulate techniques via scripting)


Anyway, enjoy!