Jump to content

Photo

Scripts I've Written


  • Please log in to reply
12 replies to this topic

#1 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 08 December 2008 - 02:58 PM

CODE
ffc script Hotplace{
       void run(int item){
            while(true){
              if(Link->Item[item]){
               Link->HP=Link->HP;
            }
             else if(!Link->Item[item]){
                   Waitframes(120);
                 Link->HP-=1;
               Waitframe();
           }
      }
}

ffc script Press_A{
       void run(int frames){
          while(true){
            if(Link->InputA){
             Waitframes(frames);
           this->Data=Cmb_autowarp;
              Waitframe();
          }
     }
}

ffc script PlaySfx{
        void run(int sfx_slot, int frames){
               int sound = 0;
                     if(sound == 0){
                 Game->PlaySound(sfx_slot);
                    sound = frames;
                  }else{
                      sound--;
                }
                     Waitframe();
           }while(frames !=0);
     }
}

ffc script Evil_Sound_message{
      void run(int s, int sfx, int frames)
        if(Screen->NumNPCs() > 0){
           Waitframes(frames);
         Game->PlaySound(sfx);
         Screen->Message(s);
        }
    }
}

ffc script WavyScreen{
      void run(int sfx , int frames){
           Screen->Wavy=frames;
           Game->PlaySound(sfx);
       }
}

item script FlippersSound{
       void run(){
          Game->PlaySound(SFX_SWIMMING);
          }
}

ffc script Play_ScreenSfx{
    void run(int sfx){
      Game->PlaySound(sfx)
   }
}

                  

const int SFX_OPENCHEST = 0;
const int SFX_ITEMFANFARE = 0;
const int T_ITEMTILE = 0;
const int S_GETITEM  = 0;
ffc script Chest{
      void run(int chestlock, int chestunlock, int item){
            int chest = ComboAt(this->X,this->Y);
            int unloc = Screen->ComboD[chest];
            int x = 0;
            int y = 0;
           While(Screen->ComboD[chest] == chestlock){
                 if(Link->X == this->X && Link->Y == this-Y && Dir == 0 && Link->InputA){  Waitframe();
                  int freeze = Screen->ComboT[0];
                  Screen->ComboT[0] = CT_SCREENFREEZE;
                    Game->PlaySound(SFX_OPENCHEST);
                          Waitframes(2);
                  Screen->ComboD[chest] == chestunlock;
                  Screen->Drawtile(1,x,y,T_ITEMTILE,1,0,0,0,0,true,128);
                    Game->Playsound(SFX_ITEMFANFARE);
                       Screen->ComboT[0] = freeze;
                       Screen->Message(S_GETITEM);
                  Screen->Drawtile(1,x,y,T_ITEMTILE,1,0,0,0,0,false,128);
                    Link->Item[item] = true;
            }
      }
}

const int CMB_AUTOWARP = 0;//set here combo i.d of  the stairs combo with
const int SFX_STAIRS = 0;//set here the sfx of the entrance
const int StairsCSet  = 0;//set here the cset of the stairs you will use

ffc script StairsSound{
        void run(int combo, int sound){
                int stairs = ComboAt(this-X,this->Y);
                int steps  = Screen->ComboD[stairs];
                while(Screen->ComboD[stairs] == combo){ Waitframe();
                           if(Link->X == this->X && Link->Y == this->Y);
                            this->Data=CMB_AUTOWARP:
                            this->CSet= StairsCSet;
                          Game->PlaySound(SFX_STAIRS);
                   }//end of while
             }//end of if
       }//end of void run
}//end of script
                    














//this script makes the npc gives link an item,if he has the correct item with him
//from MatthewPZC NPC script, modified by me
ffc script Npc_Item{
    void run(int item, int message1, int item2, int message2, int perm){
        int d_x;
        int d_y;
        int a_x;
        int a_y;
        while(true){
            d_x = this->X - Link->X;
            d_y = this->Y - Link->Y;
            a_x = Abs(d_x);
            a_y = Abs(d_y);            
            if(Link->InputL && a_x < 24 && a_y < 24 && Link->Z == 0){
                Link->InputL = false;
                               if(!Link->Item[item]){
                               Screen->Message(message1); Waitframe();
                           }
                             else if(Link->Item[item]){
                                   Waitframes(2);
                               Screen->Message(message2);
                                 Link->Item[item2] =true;
                                Screen->CreateItem[item2];
                                     Waitframes(2);
                             if(!GetArray(NpcItem,perm)){
                               Screen->Message(message2);
                              SetArray(NpcItem,perm,true);
                          }
                }
         }
}


hav'nt tested some of them , as i dont have patience icon_razz.gif
can someone spot any errors or correction it'll be awesome to release these to other people
who's in need icon_smile.gif

Edited by drzchulo973, 08 December 2008 - 03:29 PM.


#2 lucas92

lucas92

    Defender

  • Members

Posted 08 December 2008 - 03:23 PM

I like the chest one. icon_smile.gif

Good job.

#3 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 08 December 2008 - 03:34 PM

QUOTE(lucas92 @ Dec 8 2008, 03:23 PM) View Post

I like the chest one. icon_smile.gif

Good job.


icon_smile.gif thanks , im thinking of writing every script that 0oS and OoA have.
they dont use very hard scripts. there all quite simple. alongside your bush script icon_razz.gif that made it all up icon_smile.gif

Edited by drzchulo973, 08 December 2008 - 03:35 PM.


#4 Joe123

Joe123

    Retired

  • Members

Posted 08 December 2008 - 04:07 PM

3 of those script will work in the way you expect them to.
Most won't compile.

There's very little point in writing scripts for other people to use if you can't even be bothered to test them yourself.

#5 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 08 December 2008 - 04:51 PM

Well the description does say "help with re-vision". Can you point what errors it has? Its not that i dont bother its that im scared of the compiler myself icon_frown.gif i get annoyed when the compiler tells me an error and i go back and fix every line. Do you mind and help me with these?

#6 Joe123

Joe123

    Retired

  • Members

Posted 10 December 2008 - 05:16 AM

It's important that you get used to the compiler.
Sure it's annoying when you write a script and it doesn't compile, but with practise you'll get used to it.
I used to always have errors when I compiled my scripts, but I tend to not have many now.

Script One
CODE
ffc script Hotplace{
    void run(int item){
        while(true){
            if(Link->Item[item]){
                  Link->HP=Link->HP;//This line does absolutely nothing. It's like saying '1 == 1'. It's not necessary.
            }else if(!Link->Item[item]){ //you don't need 'else if' here, only else. If you are checking one thing, 'else' will be called for all other cases. In this situation, '!Link->Item[item]' is the only other case
                Waitframes(120);
                Link->HP-=1;//'--' is the same as '-=1'.
            //You haven't closed this if statment. Not good.
            Waitframe();
        }
    }
}


Proposed Fix One
CODE
ffc script HotPlace{
    void run(int item, int rate){ //I've added an extra variable so you can alter the rate of HP loss
    if(rate == 0) rate = 10; //If the user leaves D1 blank, it will now revert to 10 by default.
        while(true){
            if(!Link->Item[item]){//Check to see whether Link DOESN'T have the item
                Link->HP--; //Remove one HP
                Waitframes(rate); //Control the rate at which HP is removed
            }//Make sure to close the if
            //We don't need to check whether Link DOES have the item, because we're not going to do anything if he does
            Waitframe();//Add a Waitframe() to make sure we don't crash the system by running an infinite loop if Link has the item
        }//Close the while loop
    }//Close void run
}//End of script



Script Two
CODE
ffc script Press_A{
       void run(int frames){
          while(true){
            if(Link->InputA){ //To be honset, I'm not really sure where you're going with this.
                Waitframes(frames);//I'm going to assume that you want to have the player press A, then wait, and then warp. It's a bit of a mess though.
                this->Data=Cmb_autowarp;
              //Don't forget to close your ifs
              Waitframe();
          }
     }
}


Proposed Fix Two
CODE
ffc script Press_A{
       void run(int frames){
        while(true){
            if(Link->InputA){
                Waitframes(frames);
                this->Data=Cmb_autowarp;
            }
        Waitframe();
        }
     }
}

I suppose you could just write it like this, so the only think you really did wrong was to not close that if. It's not the way I'd write it though, I'd do this:
CODE
cosnt int CMB_AUTOWARP = 0; //set an autowarp combotype combo here
ffc script PressA{
    void run(int frames){
        while(!Link->InputA) Waitframe();
        Waitframes(frames);
        this->Data = CMB_AUTOWARP;
    }
}

I'll let you work that one out ;-)

#7 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 10 December 2008 - 11:55 AM

icon_razz.gif so i always close the if before a waitframe. Thanks pretty little errors. I have an idea though. Can you tell me the names of the scripts i wrote that have errors in them so i could fix them and post them to see if i got it right? It'll be a really good exercise. And yea, practise and patience. Lol

#8 Joe123

Joe123

    Retired

  • Members

Posted 10 December 2008 - 02:22 PM

They all have errors in except for WavyScreen, FlippersSound and Play_ScreenSfx.

FlippersSound will compile, but it won't work like you want it to I'm afraid.

#9 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 10 December 2008 - 04:15 PM

CODE
import "std.zh"              

ffc script Hotplace{
       void run(int i, int rate){
        if(rate == 0) rate = 10;
            while(true){
            if(!Link->Item[i]){
            Link->HP--;
            Waitframes(rate);
        }
        Waitframe();
        }
    }
}

const int CMB_AUTOWARP = 0;

ffc script Press_A{
       void run(int frames){
          while(true){
            if(Link->InputA){
             Waitframes(frames);
           this->Data=CMB_AUTOWARP;
                  }
              Waitframe();
          }
     }
}

ffc script PlaySfx{
        void run(int sfx_slot, int frames){
               int sound = 0;
                     if(sound == 0){
                 Game->PlaySound(sfx_slot);
                    sound = frames;
                  }else{
                      sound--;
                }
           while(frames !=0){
            Waitframe();
        }
    }
}

ffc script Evil_Sound_message{
      void run(int s, int sfx, int frames){
        if(Screen->NumNPCs() > 0){
           Waitframes(frames);
          }
         Game->PlaySound(sfx);
         Screen->Message(s);
     }
}

ffc script WavyScreen{
      void run(int sfx , int frames){
           Screen->Wavy=frames;
           Game->PlaySound(sfx);
       }
}

const int SFX_SWIMMING = 0;

item script FlippersSound{
       void run(){
         while(Link->InputLeft && Link->InputDown &&
                 Link->InputRight && Link->InputUp){
                Game->PlaySound(SFX_SWIMMING);
           }
      }
}



ffc script Play_ScreenSfx{
    void run(int sfx){
      Game->PlaySound(sfx);
   }
}

                  

const int SFX_OPENCHEST = 0;
const int SFX_ITEMFANFARE = 0;

ffc script Chest{
      void run(int chestlock, int chestunlock, int x, int y, int s, int Itile, int cset){
            int chest = ComboAt(this->X,this->Y);
            int unloc = Screen->ComboD[chest];
            item CreateItem[0];//set here the item i.d of an item you wish to create
           while(Screen->ComboD[chest] == chestlock){
                 if(Link->X == this->X && Link->Y == this->X+16 && Link->Dir == 0 && Link->InputA){ Waitframe();
                       Link->InputUp = false;
                       Link->InputDown = false;
                       Link->InputLeft = false;
                       Link->InputRight = false;
                       Link->InputStart = false;
                    Game->PlaySound(SFX_OPENCHEST);
                          Waitframes(2);
                  Screen->ComboD[chest] == chestunlock;
                  Screen->DrawTile(3,x,y,Itile,16,16,cset,1,0,0,0,0,true,128);
                    Game->PlaySound(SFX_ITEMFANFARE);
                  Screen->Message(s);
                       Link->Item[0] = true;//give the item to link when he opens the chest
                       Link->InputUp = true;
                       Link->InputDown = true;
                       Link->InputLeft = true;
                       Link->InputRight = true;
                       Link->InputStart = true;
                  Screen->DrawTile(3,x,y,Itile,16,16,cset,1,0,0,0,0,false,128);
                  }
            }
      }
}

const int CMB_AUTOWAR = 0;//set here the i.d of a stairs combotype combo. it must be a stairs combo though
const int StairsCset  = 0;//set here the cset of the stairs combo

ffc script StairsSound{
        void run(int combo, int sound){
                int stairs = ComboAt(this->X,this->Y);
                int steps  = Screen->ComboD[stairs];
                while(Screen->ComboD[stairs] == combo){ Waitframe();
                           if(Link->X == this->X && Link->Y == this->Y);
                          Game->PlaySound(sound);
                         this->Data = CMB_AUTOWARP;
                         this->CSet = StairsCset;
                   }
             }
       }
                    




//this script makes the npc gives link an item,if he has the correct item with him
//from MatthewPZC NPC script, modified by me
ffc script Npc_Item{
    void run(int i1, int message1, int item2, int message2, int x, int y){
        int d_x;
        int d_y;
        int a_x;
        int a_y;
        item CreateItem[0];//set here the item i.d you wish to create
        while(true){
            d_x = this->X - Link->X;
            d_y = this->Y - Link->Y;
            a_x = Abs(d_x);
            a_y = Abs(d_y);            
            if(Link->InputL && a_x < 24 && a_y < 24 && Link->Z == 0){
                Link->InputL = false;
                        }
                               if(!Link->Item[i1]){
                               Screen->Message(message1); Waitframe();
                           }
                             else if(Link->Item[i1]){
                                   Waitframes(2);
                               Screen->Message(message2);
                               Link->Item[0] = true;//give link the new item
                            }
                                Waitframes(2);
                }
        }
}


there i corrected alot of errors though and trust me there was quite alot icon_razz.gif
the only thing i didnt get was the
CODE
item->CreateItem
didnt know how to set to link's position so he'll be able to hold it. so i added
CODE
Link->Item[] = true;
to give it to him when he opens the chest or talks to the npc.

Edited by Christian, 10 December 2008 - 04:27 PM.


#10 Joe123

Joe123

    Retired

  • Members

Posted 11 December 2008 - 04:49 AM

Hotplace, Press_A, PlaySfx, Evil_Sound_message, WavyScreen and Play_ScreenSfx now all work fine.
The only issue is that you're still not spacing out your code in a logical manner.
Yes, they will compile in the way you've written them, but noone else will be able to read them.
It really is very important that you space it out legibally.

The other four won't though still.
I'm afraid the flippers one just isn't going to work like that.
The action scripts only work for active items (ie, ones you can select in the subscreen).
The flippers are a passive item, so setting an action script for them just won't do anything icon_shrug.gif
If you wanted to set this up properly, you'd have to have a section in your global script (or an ffc script on each screen with water) which checks whether Link's on a water combo, then increments a global variable every frame, and when it gets to 30 or something, plays the sound effect and then resets to 0.



The chest one still needs quite a lot of work.
To create an item, you first declare the item object, like this:
CODE
item newitem;

Now you have an item object called 'newitem'

Then, you have to tell 'newitem' what item it should be. You do that like this:
CODE
newitem = Screen->CreateItem(I_SWORD1);

newitem is now the wooden sword.

Then you can manipulate 'newitem' using the commands from ZScript.txt and the arrow operator.
CODE
newitem->X = Link->X;
newitem->Y = Link->Y


And that's how you create and use an item.
It works the same for npcs, lweapons and eweapons, except you declare them as an 'npc', 'lweapon' or 'eweapon' object, and set them with 'Screen->CreateLWeapon()' etc.

You can also use Screen->LoadItem() to set an item, but that's not really relevant in this case.
So that line that says 'item CreateItem[0]' I'm afraid just doesn't make sense.

The lines which actually make the chest open look ok at a glance, so try giving Link the item like that and we'll see how it goes.



The syntax and things in the stairs one is quite good, but it's not really necessary.
I'll run you through it:

CODE
const int CMB_AUTOWAR = 0;//set here the i.d of a stairs combotype combo. it must be a stairs combo though
const int StairsCset  = 0;//set here the cset of the stairs combo

ffc script StairsSound{
    void run(int combo, int sound){
    int stairs = ComboAt(this->X,this->Y);    //This part isn't really necessary, because we don't actually need to check any combos, only link's position relative to the ffc
    int steps  = Screen->ComboD[stairs];
        while(Screen->ComboD[stairs] == combo){//you don't actually need to check what the combotype is, because it's not going to chance. You might as well write 'while(true){'
            if(Link->X == this->X && Link->Y == this->Y); //Don't start an if with a semicolon. It'll compile fine, but it just won't work.
                Game->PlaySound(sound);
                this->Data = CMB_AUTOWARP; //Warping Link with the script is ok I suppose, but it's not really necessary
                this->CSet = StairsCset;
            //You need to close the if
        Waitframe();
        }
    }
}


What you've done is you've checked where Link is relative to a combo.
But what it would be better to do is to check where he is relative to the ffc, without using Screen->Combo[].

So I'd do it like this:
CODE
ffc script StaisSound{
    void run(int sound){ //load the variable for the sfx to play
        while(true){ //Run an infinite loop, because we want it to check the whole time Link is on the screen
            if(Abs(Link->X-this->X) < 4 && Abs(Link->Y-this->Y < 4){ //check whether Link is on the ffc
                Game->PlaySound(sound); //play the sfx
                Quit(); //Quit the script so the sfx doesn't play again
            }
        Waitframe(); //Waitframe() so as not to crash the system
        }
    }
}


So you don't actually need to check the combos at all, just where Link is.
If you now place this ffc on top of a stairs combo, it'll work like you want it to.

One thing that you might not understand though is the way I've done the distance checking.
I'll run you through that...

'Abs()' means 'Absolute()'.
It returns the absolute value of a number.
What that maens is, if it's positive, you just get the number. If it's negative, it makes it positive.

So...
CODE
Abs(3) == 3
Abs(-3) == 3
Abs(-PI) == PI
Abs(-x) == x
Abs(this->Y-Link->Y) == distancebetweenthis->YandLink->Y


I'm sure you'll agree that subtracting two numbers finds the difference between them.
So if we find the difference between Link's X coordinate and the ffc's X coordinate, and check if it's less than 4, then do the same for the y coordinates, we can check whether Link is on the ffc.

#11 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 11 December 2008 - 11:55 AM

Hmmm...i'm pretty sure i learned that absolute value of coordinates in math class. icon_frown.gif times like these i now know math is really important should have payed more attention to it rather than just fool around. So in the stairs script you made it work with a transparent combo now? And with the chest and npc script everything is good right? The only thing i need to work on is with the item code. Is it possible to have D0 in the create item array?

Edited by Christian, 11 December 2008 - 12:01 PM.


#12 Joe123

Joe123

    Retired

  • Members

Posted 11 December 2008 - 12:06 PM

Yes, the stairs script works with a transparent combo.
The chest and npc script aren't good no.
I think the chest will work if you add the item code (you'll have to test it), but it'll allow you to pick up the item every time you enter the screen, and I haven't got to the npc one yet.

Create Item isn't an array, but yes, you can put D0 in it.

#13 Christian

Christian

    Summoner

  • Members
  • Real Name:Chris
  • Location:New Jersey

Posted 11 December 2008 - 12:44 PM

So is there a way i can make the chest permanent so that everytime i enter the screen the chest won't reload? I'll test the chest right now then and see what was the result.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users