PDA

View Full Version : Oracles/LttP-style Shop Script



Nimono
10-26-2007, 07:07 PM
Copy-paste from PureZC...


// Shop- Oracles-style shop, where you must press A to buy the item. There is no confirmation message, though, so only press A if you want the item!
// Limtations are simply the fact that I can't use the D variables of any other FFCs besides the one this script is set on, thus only four items per shop,
// and the fact that you won't hold up the item when you buy it... But it's useful, regardless! The shop can be anywhere on the screen now! However, this
// means you'll need to waste a few combos to show the item and the price... But it's worth it. Also, think about this: This script means no more leaving and
// exiting a shop just to buy more than one item...;) Plus, there's more versatility with THIS script. No more wasting Shop Types. Now, one script does it
// all. Each FFC has its own per-screen D variable from 0 to 7. This script uses 0-3 for the items you buy, and 4-7 for their prices. The screen-specificness
// of the D variables adds to the versatility. For example, on one screen, you could set up a shop that sells the 3 Shields, while on another, the very same
// script sets you up a shop that sells Bombs. I made this because I didn't particularly like how Zelda Classic's Z1 shops are done.... Plus, my quest, Realm
// of Mirrors, needed Oracles-styled things... Anyways, have fun with this script! ~Matthew
// Constants:
// nerm- Weird name, yes, but... Message to use when you try to buy an item without the required amount of Rupees. "THAT AIN'T ENOUGH TO BUY!"
// D variables:
// item1- Variable D0. First item you can buy.
// item2- Variable D1. Second item you can buy.
// item3- Variable D2. Third item you can buy.
// item4- Variable D3. Fourth item you can buy.
// price1- Variable D4. Price of item1.
// price2- Variable D5. Price of item2.
// price3- Variable D6. Price of item3.
// price4- Variable D7. Price of item4.

import "std.zh"

const int nerm = 12;
ffc script shop
{
void run(int item1, int item2, int item3, int item4, int price1, int price2, int price3, int price4) //load up the D variables
{
int nobuy = 0;
int wait = 1;
while(true) //as long as the script is active, it'll NEVER stop. Yay!
{
ffc buy1 = Screen->LoadFFC(31);
ffc buy2 = Screen->LoadFFC(30); //we load the 4 FFCs to be used for the shop here...
ffc buy3 = Screen->LoadFFC(29);
ffc buy4 = Screen->LoadFFC(28);
while(Link->X == buy1->X && Link->Y == buy1->Y) //continue only if Link is on the FFC
{
if(nobuy == 1) //checks if it shouldn't allow buying, "no-buy timer"
{
while(wait > 0)
{ //this whole section prevents you from buying an item over and over again if you hold down A, AKA "no-buy timer"
wait -= 1; //take away from the timer
Waitframes(60); //wait one full second before continuing. 60 frames = 1 second....therefore, the value of "wait" is the amount of seconds on the no-buy timer... I wouldn't try 3, though. Too long, trust me.
}
nobuy = 0; //reset everything back to normal
wait = 1;
}
if(Link->InputA && nobuy == 0 && Game->Counter[1] >= price1 && Link->Dir == 0) //only allow buying if you press A, if the no-buy timer has expired, if you have enough Rupees, and if you're...y'know, FACING the item...
{
Link->InputA = false; //stops Link from attacking....can't have that
nobuy = 1; //helps start the no-buy timer
Screen->CreateItem(item1); //create the item that we're buying
int itemcount = Screen->NumItems(); //find out how many items are on-screen...just a simple precaution. Since the item you're buying is most likely going to be the last item in the list, NumItems will give you the item's ID all the time...but then, that's if no other script creates items...
item newitem = Screen->LoadItem(itemcount);
newitem->X = Link->X; //this section places the item on Link...simply GIVING it to him isn't enough... After all, what will tell the player they bought it successfully?
newitem->Y = Link->Y;
int drainwait = price1; //places the price of the item you just bought into a new variable to be deducted from...we can't deduct from the price variable, or else the price of the item might go down. XD
while(drainwait > 0)
{
Game->Counter[1] -= 1; //we take away Link's Rupees gradually here...just like with the normal shops.
drainwait -= 1; //take away 1 from the deduction variable so it knows how much more to take away
Waitframe(); //wait one frame...without this, the script would freeze the player...and that could be dangerous. VERY dangerous indeed...
}
}
else if(Link->InputA && Game->Counter[1] < price1) //check if the player tries to buy an item without enough Rupees
{
Screen->Message(nerm); //bring up a message to tell the player that he/she needs more Rupees
nobuy = 1; //hey, without this, the message will keep repeating! :O
}
Waitframe();
}
while(Link->X == buy2->X && Link->Y == buy2->Y)
{
if(nobuy == 1)
{
while(wait > 0)
{
wait -= 1;
Waitframes(60);
}
nobuy = 0;
wait = 1;
}
if(Link->InputA && nobuy == 0 && Game->Counter[1] >= price2 && Link->Dir == 0)
{
Link->InputA = false;
nobuy = 1;
Screen->CreateItem(item2);
int itemcount = Screen->NumItems();
item newitem = Screen->LoadItem(itemcount);
newitem->X = Link->X;
newitem->Y = Link->Y;
int drainwait = price2;
while(drainwait > 0)
{
Game->Counter[1] -= 1;
drainwait -= 1;
Waitframe();
}
}
else if(Link->InputA && Game->Counter[1] < price2)
{
Screen->Message(nerm);
nobuy = 1;
}
Waitframe();
}
while(Link->X == buy3->X && Link->Y == buy3->Y)
{
if(nobuy == 1)
{
while(wait > 0)
{
wait -= 1;
Waitframes(60);
}
nobuy = 0;
wait = 1;
}
if(Link->InputA && nobuy == 0 && Game->Counter[1] >= price3 && Link->Dir == 0)
{
Link->InputA = false;
nobuy = 1;
Screen->CreateItem(item3);
int itemcount = Screen->NumItems();
item newitem = Screen->LoadItem(itemcount);
newitem->X = Link->X;
newitem->Y = Link->Y;
int drainwait = price3;
while(drainwait > 0)
{
Game->Counter[1] -= 1;
drainwait -= 1;
Waitframe();
}
}
else if(Link->InputA && Game->Counter[1] < price3)
{
Screen->Message(nerm);
nobuy = 1;
}
Waitframe();
}
while(Link->X == buy4->X && Link->Y == buy4->Y)
{
if(nobuy == 1)
{
while(wait > 0)
{
wait -= 1;
Waitframes(60);
}
nobuy = 0;
wait = 1;
}
if(Link->InputA && nobuy == 0 && Game->Counter[1] >= price4 && Link->Dir == 0)
{
Link->InputA = false;
nobuy = 1;
Screen->CreateItem(item4);
int itemcount = Screen->NumItems();
item newitem = Screen->LoadItem(itemcount);
newitem->X = Link->X;
newitem->Y = Link->Y;
int drainwait = price4;
while(drainwait > 0)
{
Game->Counter[1] -= 1;
drainwait -= 1;
Waitframe();
}
}
else if(Link->InputA && Game->Counter[1] < price4)
{
Screen->Message(nerm);
nobuy = 1;
}
Waitframe();
}
Waitframe();
}
}
}
Yes, Oracles-style. It's actually more of LttP-style, since you don't pick up the item you buy and take it to the shopkeeper... But anyways...

REPLACE THIS WITH ALL NORMAL Z1 SHOPS IN YOUR QUESTS OR ELSE YOU WILL DIE! :P Just kidding. This is more versatile than normal shops. For starters, since I'm using the FFCs... You get to put your items anywhere you want. They don't even have to be right next to each other. Second, you get up to FOUR items in your shop! My original plan was to have that limit only be limited by the number of FFCs you could use...but I can't figure out how to access the D variables on other FFCs. If I could do THAT... Well, the script would be super-awesome. But oh well. Third, this one script, thanks again to the D variables, allows you to make MANY shops! Just one script is all that's needed. :) Now, how to work it...

D0-D3 are the item IDs for the items you buy. Look in std.zh for the info for THAT. D4-D7 are the prices for those items. Yes, it's respective. The only constant in the entire script decides what message appears when you don't have enough Rupees to buy an item. I actually thought about adding in a message for when you buy an item, but decided against that. For one, I don't have any D variables left for that, and two, you can do that with another script, placed on the item... Anyways, I don't wanna do it.

Don't mess with anything else, 'kay? Well, except "wait". Change that if you want to wait LONGER before you can try to buy an item again. Change the value in the "Waitframes", too, if you wanna try to make it wait a SHORTER amount of time. 60 frames = 1 second, by the way. If you wanna know how anything works, look at my little notes there. Just began using them with this script... And for this very reason, I might add! So, have fun with the script and stuffs! :D Let me know if there's anything else you wish to know about this script...

*le gasp for air* A lot to post, but... I hope that most new quests will use this script over the original shop types. :D

Din
10-26-2007, 08:22 PM
Cool, an FFC script, that's a change. Anyway, good job with this script! It's been a while since you submitted one. This script pwns :p

ShadowMancer
10-26-2007, 08:48 PM
Not bad :)
one question, does it display the prices? I quickly skimmed the code but could not see a price display routine anywhere
EDIT:
n/m found my answer.

although:

This script means no more leaving and exiting a shop just to buy more than one item...;) Plus, there's more versatility with THIS script.
This I like, It may be a useful feature to add to my 'Advanced Shop' Script (if you don't mind me useing the routine :) )

You might want to consider useing drawing routines to display the price (see Advanced Shop) you can copy the routines if you want them.

Nimono
10-27-2007, 02:47 PM
You might want to consider useing drawing routines to display the price (see Advanced Shop) you can copy the routines if you want them.

Heck no. If you don't wanna use combos for the prices, why should you use this script? ._. I mean... Look at it this way. You're using combos anyways no matter HOW the prices are put onto the screen. So which would you rather do? Be lazy and expect a script to do it all so you need only set up the combos? Or do the work to put them on a screen (Just a simple click on combo, click on play area)? Which sounds better as a questmaker? Would you REALLY want to play a quest made by someone who was lazy and made other things to do all the work for him? ...Okay, bad analogy. But seriously, if you're not gonna place down the combos yourself, why should you use this script? D:

Joe123
10-27-2007, 04:11 PM
The prices won't dissapear after you've bought the items though if you do it that way...

Nimono
10-27-2007, 06:51 PM
The prices won't dissapear after you've bought the items though if you do it that way...

The items don't disappear. DUH! You use combos to show what you're buying. Press "A" in front of it, a new item is created, and set to Link's position, so he gets it. Simple as that. Did you even TRY to use my script? O_o

Joe123
10-27-2007, 07:02 PM
No, I haven't tried it yet. However I might do, because it looks quite interesting.

ShadowMancer
10-27-2007, 11:54 PM
if you're not gonna place down the combos yourself, why should you use this script? D:
I see your point. :)
I come more from a development background then questmakeing so I'm always on the lookout to make things easier to use. I might not use this script (heck I probley won't use my own shop script) only because I am designing a different sort of quest right now, although I can see this script bieng very useful to some questmakers.

Joe123
12-01-2007, 09:50 AM
OK, I've actually used this script now and I must say I'm very impressed.
It takes a long time to set up, and quite a while to figuire out, but it's really worth it.
Could you post the updated version from the expo here though?

And howcomes the FFC for the first item is 31 rather than 32? That really had me stuck for quite a while =P
Also, if you put 'Game->PlaySound(18);' within the rupee drain loop, it plays the sound like in the hardcoded shops also.

Thanks for a great script :D

Nimono
12-01-2007, 02:45 PM
OK, I've actually used this script now and I must say I'm very impressed.
It takes a long time to set up, and quite a while to figuire out, but it's really worth it.
Could you post the updated version from the expo here though?

And howcomes the FFC for the first item is 31 rather than 32? That really had me stuck for quite a while =P
Also, if you put 'Game->PlaySound(18);' within the rupee drain loop, it plays the sound like in the hardcoded shops also.

Thanks for a great script :D

....It does. I think. 32 is missing because that's the FFC I put the script on.


// Shop- Oracles-style shop, where you must press A to buy the item. There is no confirmation message, though, so only press A if you want the item!
// Limtations are simply the fact that I can't use the D variables of any other FFCs besides the one this script is set on, thus only four items per shop,
// and the fact that you won't hold up the item when you buy it... But it's useful, regardless! The shop can be anywhere on the screen now! However, this
// means you'll need to waste a few combos to show the item and the price... But it's worth it. Also, think about this: This script means no more leaving and
// exiting a shop just to buy more than one item... ;) Plus, there's more versatility with THIS script. No more wasting Shop Types. Now, one script does it
// all. Each FFC has its own per-screen D variable from 0 to 7. This script uses 0-3 for the items you buy, and 4-7 for their prices. The screen-specificness
// of the D variables adds to the versatility. For example, on one screen, you could set up a shop that sells the 3 Shields, while on another, the very same
// script sets you up a shop that sells Bombs. I made this because I didn't particularly like how Zelda Classic's Z1 shops are done.... Plus, my quest, Realm
// of Mirrors, needed Oracles-styled things... Anyways, have fun with this script! ~Matthew
// Constants:
// nerm- Weird name, yes, but... Message to use when you try to buy an item without the required amount of Rupees. "THAT AIN'T ENOUGH TO BUY!"
// boughtmsg- Message to use when you buy something.
// D variables:
// item1- Variable D0. First item you can buy.
// item2- Variable D1. Second item you can buy.
// item3- Variable D2. Third item you can buy.
// item4- Variable D3. Fourth item you can buy.
// price1- Variable D4. Price of item1.
// price2- Variable D5. Price of item2.
// price3- Variable D6. Price of item3.
// price4- Variable D7. Price of item4.

import "std.zh"

const int nerm = 12;
ffc script shop
{
void run(int item1, int item2, int item3, int item4, int price1, int price2, int price3, int price4) //load up the D variables
{
int nobuy = 0;
int wait = 1;
while(true) //as long as the script is active, it'll NEVER stop. Yay!
{
ffc buy1 = Screen->LoadFFC(31);
ffc buy2 = Screen->LoadFFC(30); //we load the 4 FFCs to be used for the shop here...
ffc buy3 = Screen->LoadFFC(29);
ffc buy4 = Screen->LoadFFC(28);
while((Link->X > buy1->X-4 && Link->X < buy1->X+4) && Link->Y == buy1->Y) //continue only if Link is on the FFC
{
while(Link->InputA) //only allow buying if you press A
{
if(nobuy == 0 && Game->Counter[1] >= price1 && Link->Dir == 0) //buy only if you're not constantly holding A, if you have enough Rupees, and if you are facing the item.
{
nobuy = 1; //helps start the no-buy timer
Link->Item[item1] = true; //gives Link the item
Game->PlaySound(25);
Screen->Message(71);
int drainwait = price1; //places the price of the item you just bought into a new variable to be deducted from...we can't deduct from the price variable, or else the price of the item might go down. XD
while(drainwait > 0)
{
Game->Counter[1] -= 1; //we take away Link's Rupees gradually here...just like with the normal shops.
drainwait -= 1; //take away 1 from the deduction variable so it knows how much more to take away
Waitframe(); //wait one frame...without this, the script would freeze the player...and that could be dangerous. VERY dangerous indeed...
}
}
else if(nobuy == 0 && Game->Counter[1] < price1 && Link->Dir == 0) //check if the player tries to buy an item without enough Rupees
{
Screen->Message(nerm); //bring up a message to tell the player that he/she needs more Rupees
nobuy = 1; //hey, without this, the message will keep repeating! :O
}
Waitframe();
}
if(!Link->InputA)
{
nobuy = 0;
}

Waitframe();
}
while((Link->X > buy2->X-4 && Link->X < buy2->X+4) && Link->Y == buy2->Y)
{
while(Link->InputA) //only allow buying if you press A
{
if(nobuy == 0 && Game->Counter[1] >= price2 && Link->Dir == 0) //buy only if you're not constantly holding A, if you have enough Rupees, and if you are facing the item.
{
nobuy = 1; //helps start the no-buy timer
Link->Item[item2] = true; //gives Link the item
Game->PlaySound(25);
Screen->Message(13);
int drainwait = price2; //places the price of the item you just bought into a new variable to be deducted from...we can't deduct from the price variable, or else the price of the item might go down. XD
while(drainwait > 0)
{
Game->Counter[1] -= 1; //we take away Link's Rupees gradually here...just like with the normal shops.
drainwait -= 1; //take away 1 from the deduction variable so it knows how much more to take away
Waitframe(); //wait one frame...without this, the script would freeze the player...and that could be dangerous. VERY dangerous indeed...
}
}
else if(nobuy == 0 && Game->Counter[1] < price2 && Link->Dir == 0) //check if the player tries to buy an item without enough Rupees
{
Screen->Message(nerm); //bring up a message to tell the player that he/she needs more Rupees
nobuy = 1; //hey, without this, the message will keep repeating! :O
}
Waitframe();
}
if(!Link->InputA)
{
nobuy = 0;
}

Waitframe();
}
while((Link->X > buy3->X-4 && Link->X < buy3->X+4) && Link->Y == buy3->Y)
{
while(Link->InputA) //only allow buying if you press A
{
if(nobuy == 0 && Game->Counter[1] >= price3 && Link->Dir == 0) //buy only if you're not constantly holding A, if you have enough Rupees, and if you are facing the item.
{
nobuy = 1; //helps start the no-buy timer
Link->Item[item3] = true; //gives Link the item
Game->PlaySound(25);
Screen->Message(14);
int drainwait = price3; //places the price of the item you just bought into a new variable to be deducted from...we can't deduct from the price variable, or else the price of the item might go down. XD
while(drainwait > 0)
{
Game->Counter[1] -= 1; //we take away Link's Rupees gradually here...just like with the normal shops.
drainwait -= 1; //take away 1 from the deduction variable so it knows how much more to take away
Waitframe(); //wait one frame...without this, the script would freeze the player...and that could be dangerous. VERY dangerous indeed...
}
}
else if(nobuy == 0 && Game->Counter[1] < price3 && Link->Dir == 0) //check if the player tries to buy an item without enough Rupees
{
Screen->Message(nerm); //bring up a message to tell the player that he/she needs more Rupees
nobuy = 1; //hey, without this, the message will keep repeating! :O
}
Waitframe();
}
if(!Link->InputA)
{
nobuy = 0;
}

Waitframe();
}
while((Link->X > buy4->X-4 && Link->X < buy4->X+4) && Link->Y == buy4->Y)
{
while(Link->InputA) //only allow buying if you press A
{
if(nobuy == 0 && Game->Counter[1] >= price4 && Link->Dir == 0) //buy only if you're not constantly holding A, if you have enough Rupees, and if you are facing the item.
{
nobuy = 1; //helps start the no-buy timer
Link->Item[item4] = true; //gives Link the item
Game->PlaySound(25);
Screen->Message(71);
int drainwait = price4; //places the price of the item you just bought into a new variable to be deducted from...we can't deduct from the price variable, or else the price of the item might go down. XD
while(drainwait > 0)
{
Game->Counter[1] -= 1; //we take away Link's Rupees gradually here...just like with the normal shops.
drainwait -= 1; //take away 1 from the deduction variable so it knows how much more to take away
Waitframe(); //wait one frame...without this, the script would freeze the player...and that could be dangerous. VERY dangerous indeed...
}
}
else if(nobuy == 0 && Game->Counter[1] < price4 && Link->Dir == 0) //check if the player tries to buy an item without enough Rupees
{
Screen->Message(nerm); //bring up a message to tell the player that he/she needs more Rupees
nobuy = 1; //hey, without this, the message will keep repeating! :O
}
Waitframe();
}
if(!Link->InputA)
{
nobuy = 0;
}

Waitframe();
}
Waitframe();
}
}
}

Happy?

Shazza Dani
12-19-2008, 01:30 AM
I'm having immense trouble with this script. I can't seem to just press A to buy an item; I have to keep running over it and mashing the A button until the game decides I can have it…

Nimono
12-19-2008, 01:49 PM
...


...


Umm... Yeah. Are you placing the FFCs at the exact spot you need to stand to buy the item? Or are you trying to place it on top of the item? Put it at the spot you stand. That's how it works.


If you're doing that, then I don't know what the problem is. Sorry. More details would be nice... Though, it'd probably be that the new builds are breaking my scripts.

Shazza Dani
12-19-2008, 05:43 PM
Yeah, I'm standing on the FFC. (The item is the FFC, but I am standing on the item.)

I made a short video to show what's happening: http://s8.photobucket.com/albums/a40/tdrisko/myvids/?action=view&current=shopscriptvid.flv

Joe123
12-19-2008, 06:15 PM
Didn't I post in this thread :confused:

Anyway, I'll send you my version if you want.

Shazza Dani
12-19-2008, 07:23 PM
Okay, I changed

while((Link->X > buy1->X-4 && Link->X < buy1->X+4) && Link->Y == buy1->Y)

To this:

while((Link->X > buy1->X-8 && Link->X < buy1->X+8) && Link->Y > buy1->Y-8 && Link->Y < buy1->Y+8)

But I'm sure that's layed out incorrectly, since I don't know anything about scripting… Still, it seems to let me buy the items easier. I've also noticed that the game makes me wait way too long between buying items, and I don't know how to change that.

At this point I'm willing to try a different shop script.