Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //import "std.zh"
- const int S_NORUPEES = 7; //Message saying 'Not enough rupees'
- const int S_THANKS = 31; //Message saying 'Thanks for buying'
- const int S_INVISABLE_COMBO = 65279;
- const int S_LINK_CARRY_TILE = 34792;
- const int S_LINK_CARRY_SPEED = 8;
- ffc script FFC_NPC{
- void run(int msg, int sfx, int defdir, int dist, int ffcnumber, int input){
- ffc NPC = this;
- if(ffcnumber != 0) Screen->LoadFFC(ffcnumber);
- NPC->Misc[0] = NPC->Data;
- if(dist == 0) dist = 40;
- while(true){
- SetGraphic(NPC,defdir,dist);
- if(CanTalk(NPC,input)){
- SetInput(input,false);
- if(sfx != 0) Game->PlaySound(sfx);
- Screen->Message(msg);
- }
- Waitframe();
- }
- }
- bool CanTalk(ffc NPC,int input){
- return (SelectPressInput(input) && Abs(NPC->X-Link->X) < 24 && Abs(NPC->Y-Link->Y) < 24 && Link->Z == 0);
- }
- void SetGraphic(ffc NPC, int defdir, int dist){
- int dx = NPC->X-Link->X; int ax = Abs(dx);
- int dy = NPC->Y-Link->Y; int ay = Abs(dy);
- if(defdir != 0){
- if(ax < dist && ay < dist){
- if(ax <= ay){
- if(dy >= 0) NPC->Data = NPC->Misc[0]+DIR_UP;
- else NPC->Data = NPC->Misc[0]+DIR_DOWN;
- }else{
- if(dx >= 0) NPC->Data = NPC->Misc[0]+DIR_LEFT;
- else NPC->Data = NPC->Misc[0]+DIR_RIGHT;
- }
- }else NPC->Data = NPC->Misc[0]+(defdir-1);
- }
- }
- }
- ffc script SecretSFX
- {
- void run(int playsound)
- {
- Game->PlaySound(playsound);
- }
- }
- ffc script FFC_Shop{
- void run(int tileoffset, int itm, int price, int info, int input){
- int origTile = this->Data;
- int origX = this->X;
- int origY = this->Y;
- int origCSet = this->CSet;
- int pickedUp = 0;
- int pickedUpFrame = 0;
- int pickedUpDelay = 0;
- while(true)
- {
- if (pickedUp == 0)
- {
- int ss[]="Tracing price: "; TraceS(ss); Trace(price);
- Screen->DrawInteger(3, this->X + 0, this->Y - 12, FONT_MATRIX, 8, -1, 16, 16, price, 0, 128);
- if (info > 0) Screen->DrawInteger(3, this->X + 16, this->Y + 8, FONT_MATRIX, 8, -1, 16, 16, info, 0, 128);
- if(CanPick(input, origX, origY))
- {
- SetInput(0, 0);
- SetInput(1, 0);
- pickedUp = 1;
- this->Data = S_INVISABLE_COMBO;
- pickedUpFrame = 0;
- }
- }
- else
- {
- SetInput(0, 0);
- SetInput(1, 0);
- if (Link->Action == LA_NONE)
- {
- pickedUpFrame = 0;
- pickedUpDelay = 0;
- }
- else
- {
- if (pickedUpDelay <= 0)
- {
- pickedUpFrame = (pickedUpFrame + 1) % 2;
- pickedUpDelay = 16;
- }
- else
- pickedUpDelay --;
- }
- Link->Invisible = true;
- Screen->FastTile(3, Link->X, Link->Y, S_LINK_CARRY_TILE + Link->Dir * 2 + Floor(pickedUpFrame), 6, 128);
- Screen->FastCombo(3, Link->X, Link->Y - 16, origTile + tileoffset, origCSet, 128);
- this->X = Link->X;
- this->Y = Link->Y - 8;
- if(CanPick(input, origX, origY))
- {
- SetInput(0, 0);
- SetInput(1, 0);
- Link->Invisible = false;
- pickedUp = 0;
- this->X = origX;
- this->Y = origY;
- this->Data = origTile;
- }
- }
- if (Link->Action != LA_NONE && Link->Action != LA_WALKING)
- {
- Link->Invisible = false;
- pickedUp = 0;
- this->X = origX;
- this->Y = origY;
- this->Data = origTile;
- }
- Waitframe();
- }
- }
- }
- bool CanPick(int input, int x, int y)
- {
- return (Abs(Link->X-x) < 16 && Abs(Link->Y-(y+16)) < 8 && SelectPressInput(input) && Link->Dir == DIR_UP);
- }
- int GetFFCID(ffc ff){
- int q; ffc f;
- for ( q = 1; q <= 32; q++ ) {
- f = Screen->LoadFFC(q);
- if ( f == ff ) return q;
- }
- }
- void ShopItemThanks(int itm){
- Screen->Message(S_THANKS);
- Game->PlaySound(SFX_SCALE);
- WaitNoAction();
- CreatePickupItem(Link->X,Link->Y,itm);
- Game->PlaySound(SFX_PICKUP);
- WaitNoAction();
- }
- void CreatePickupItem(int x, int y, int itm){
- item Spawn = Screen->CreateItem(itm);
- Spawn->Pickup |= (IP_TIMEOUT|IP_HOLDUP);
- Spawn->HitWidth = 16; Spawn->HitHeight = 16;
- Spawn->X = x; Spawn->Y = y;
- }
- void DeductRupees(int amount){
- FreezeScreen();
- for(int i=0;i<amount;i++){
- Game->PlaySound(SFX_MSG);
- Game->Counter[CR_RUPEES]--;
- Waitframe();
- }
- UnFreeze();
- }
- int FreezeID;
- void FreezeScreen(){
- FreezeID = Screen->ComboT[0];
- Screen->ComboT[0] = CT_SCREENFREEZE;
- }
- void UnFreeze(){
- Screen->ComboT[0] = FreezeID;
- }
- //These functions should only be included in your script file once
- bool SelectPressInput(int input){
- if(input == 0) return Link->PressA;
- else if(input == 1) return Link->PressB;
- else if(input == 2) return Link->PressL;
- else if(input == 3) return Link->PressR;
- }
- void SetInput(int input, bool state){
- if(input == 0) Link->InputA = state;
- else if(input == 1) Link->InputB = state;
- else if(input == 2) Link->InputL = state;
- else if(input == 3) Link->InputR = state;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement