Jump to content

Photo

Random scripts I have written... :p


  • Please log in to reply
15 replies to this topic

#1 lucas92

lucas92

    Defender

  • Members

Posted 24 October 2008 - 10:09 PM

CODE
ffc script GrowingCircle
{
    void run()
    {
        ffc circle=Screen->LoadFFC(1);
        int radius;
        while(true)
        {
            Screen->Circle(5,40,40,radius,3,1,0,0,0,true,128);
            radius++;
            Waitframe();
        }
    }
}


Ohh a growing circle. icon_razz.gif

CODE
ffc script BlackOutScreenCircleLink
{
    void run()
    {
        ffc blackout=Screen->LoadFFC(1);
        while(true)
        {
            Screen->Rectangle(5,0,0,256,176,0,1,0,0,0,true,128);
            Screen->Circle(5,Link->X,Link->Y,32,3,1,0,0,0,false,64);
            Waitframe();
        }
    }
}


It makes the screen goes black then draw a circle at Link's position... I wished that I could make the screen visible only within the circle... Anyone can help?

CODE
ffc script guydoesLinkinversemovements
{
    void run(int v)
    {
        ffc guy=Screen->LoadFFC(1);
        while(true)
        {
            int x=this->X;int y=this->Y;
            if (Link->InputLeft==true)
            {
                this->Vx=v;
                if (x>=240)
                {
                    this->Vx=0;
                    this->X=240;
                }
                if (Link->InputUp==true)
                {
                    this->Vy=v;
                }
                if (Link->InputDown==true)
                {
                    this->Vy=v*-1;
                }
                if ((Link->InputDown==true)&&(Link->InputUp==true))
                {
                    this->Vy=0;
                }
                if ((Link->InputUp==false)||(Link->InputDown==false))
                {
                    this->Vy=0;
                }
            }
            if (Link->InputRight==true)
            {
                this->Vx=v*-1;
                if (x<=0)
                {
                    this->Vx=0;
                    this->X=0;
                }
                if (Link->InputUp==true)
                {
                    this->Vy=v;
                }
                if (Link->InputDown==true)
                {
                    this->Vy=v*-1;
                }
                if ((Link->InputDown==true)&&(Link->InputUp==true))
                {
                    this->Vy=0;
                }
                if ((Link->InputUp==false)||(Link->InputDown==false))
                {
                    this->Vy=0;
                }
            }
            if (Link->InputDown==true)
            {
                this->Vy=v*-1;
                if (y<=0)
                {
                    this->Vy=0;
                    this->Y=0;
                }
                if (Link->InputLeft==true)
                {
                    this->Vx=v;
                }
                if (Link->InputRight==true)
                {
                    this->Vx=v*-1;
                }
                if ((Link->InputLeft==false)&&(Link->InputRight==false))
                {
                    this->Vx=0;
                }
                if ((Link->InputLeft==false)||(Link->InputRight==false))
                {
                    this->Vx=0;
                }
            }
            if (Link->InputUp==true)
            {
                this->Vy=1;
                if (y>=160)
                {
                    this->Vy=0;
                    this->Y=160;
                }
                if (Link->InputLeft==true)
                {
                    this->Vx=v;
                }
                if (Link->InputRight==true)
                {
                    this->Vx=v*-1;
                }
                if ((Link->InputLeft==false)&&(Link->InputRight==false))
                {
                    this->Vx=0;
                }
                if ((Link->InputLeft==false)||(Link->InputRight==false))
                {
                    this->Vx=0;
                }
            }
            if ((Link->Action==0)||(Link->Action==2))
            {
                this->Vx=0;
                this->Vy=0;
            }
            if (x<=0)
            {
                this->X=0;
            }
            if (x>=240)
            {
                this->X=240;
            }
            if (y<=0)
            {
                this->Y=0;
            }
            if (y>=240)
            {
                this->Y=240;
            }
            if ((Link->InputRight==true)&&(Link->InputLeft==true))
            {
                this->Vx=0;
            }
            if ((Link->InputDown==true)&&(Link->InputUp==true))
            {
                this->Vy=0;
            }
        Waitframe();
        }
    }
}


Well, that script could be shorter... Anyway, what it does is making the ffc moving when Link moves. And stops when Link stops or attacks. Also I've made him stop when he reaches the border of the screen. But I wanted it to move in diagonal when Link moves in diagonal... Right now it just moves in the four directions up left down and right...

Edited by lucas92, 24 October 2008 - 10:11 PM.


#2 Saffith

Saffith

    IPv7 user

  • Members

Posted 24 October 2008 - 10:49 PM

QUOTE(lucas92 @ Oct 24 2008, 11:09 PM) View Post

CODE
ffc script GrowingCircle
{
    void run()
    {
        ffc circle=Screen->LoadFFC(1);
        int radius;
        while(true)
        {
            Screen->Circle(5,40,40,radius,3,1,0,0,0,true,128);
            radius++;
            Waitframe();
        }
    }
}


Ohh a growing circle. icon_razz.gif

Neat. Two things: ffc circle=Screen->LoadFFC(1); is unnecessary, since you never use that pointer, and you should be sure to initialize the radius before you use it.

QUOTE
CODE
ffc script BlackOutScreenCircleLink
{
    void run()
    {
        ffc blackout=Screen->LoadFFC(1);
        while(true)
        {
            Screen->Rectangle(5,0,0,256,176,0,1,0,0,0,true,128);
            Screen->Circle(5,Link->X,Link->Y,32,3,1,0,0,0,false,64);
            Waitframe();
        }
    }
}
Again, the ffc pointer is unnecessary.

QUOTE
It makes the screen goes black then draw a circle at Link's position... I wished that I could make the screen visible only within the circle... Anyone can help?

If you want to do it using just drawing functions, I don't think it's possible without using a ridiculous number of them to fill in every last pixel. However, you could do it this way: use an FFC (or multiple FFCs) to fill in the corners of the circle around Link, then draw four rectangles between the screen borders and the FFC.
IPB Image
Red=FFC
Blue=Rectangle()

QUOTE
Well, that script could be shorter... Anyway, what it does is making the ffc moving when Link moves. And stops when Link stops or attacks. Also I've made him stop when he reaches the border of the screen. But I wanted it to move in diagonal when Link moves in diagonal... Right now it just moves in the four directions up left down and right...

I'm not quite certain I understand, but if you're trying to make it move opposite Link, the easiest way is this:
CODE
ffc script OpposeLink
{
    void run()
    {
        while(true)
        {
            this->X = 240 - Link->X;
            this->Y = 160 - Link->Y;
            Waitframe();
        }
    }
}


#3 lucas92

lucas92

    Defender

  • Members

Posted 25 October 2008 - 11:50 AM

QUOTE(Saffith @ Oct 24 2008, 11:49 PM) View Post

CODE
ffc script OpposeLink
{
    void run()
    {
        while(true)
        {
            this->X = 240 - Link->X;
            this->Y = 160 - Link->Y;
            Waitframe();
        }
    }
}



What the.... That's neat... Nice one. icon_smile.gif

#4 lucas92

lucas92

    Defender

  • Members

Posted 26 October 2008 - 02:34 PM

Scripting Randomness! icon_razz.gif

http://www.youtube.c...h?v=RAp4t4K3jnI

CODE
ffc script BossTest
{
    void run()
    {
        ffc boss=Screen->LoadFFC(1);
        int HP=3;
        while(true)
        {
            lweapon sword=Screen->LoadLWeapon(1);
            if ((Link->X>=this->X)&&(Link->X<=this->X+32)&&(Link->Y>=this->Y)&&(Link->Y<=this->Y+32))
            {
                Game->PlaySound(19); //Link gets hit when he touches the enemy...Might have to tweak a little bit more the collisions...
                Link->Action=7;
                Link->HP=Link->HP-8;
                Waitframe();
            }
            if ((sword->X>=this->X)&&(sword->X<=this->X+32)&&(sword->Y>=this->Y)&&(sword->Y<=this->Y+32))
            {
                HP--;
                Game->PlaySound(11);
                boss->CSet=8;//enemy flashes when being hit with a sword
                Waitframes(5);
                boss->CSet=7;
                Waitframes(5);
                boss->CSet=8;
                Waitframes(5);
                boss->CSet=7;
            }
            if (HP==0)
            {
                Game->PlaySound(10);
                boss->Data=24988;boss->CSet=8; //the death tiles
                Waitframes(5);
                boss->Data=24990;
                Waitframes(5);
                boss->Data=24996;
                Waitframes(5);
                boss->X=500;boss->Y=500;
                Quit();
            }
        Waitframe();        
        }
    }
}


Static 2*2 enemy. Link's position got screwed a little bit when he gets hit though... icon_unsettled.gif
Oh, and there is sound too but the video is screwed it...

#5 Majora

Majora

    Unironic Marxist-Leninist

  • Members

Posted 26 October 2008 - 03:54 PM

So is the "Lantern in a Dark Room" (like in MC, for example) script usable? I'd like to use it >.>

#6 lucas92

lucas92

    Defender

  • Members

Posted 26 October 2008 - 06:00 PM

Nah... It isn't... I could try to write it though. Just give me some info... How big do you want the circle? 3 tiles of radius?

EDIT-Already written:
http://www.purezc.co...showtopic=36686

EDIT2-
Moving boss! icon_razz.gif

CODE
ffc script BossMovingTest
{
    void run()
    {
        ffc boss=Screen->LoadFFC(1);
        int HP=3;
        int d=Rand(3);//randomly decides which way the boss goes
        int counter=0;
        while(true)
        {
            lweapon sword=Screen->LoadLWeapon(1);
            if ((Link->X>this->X-8)&&(Link->X<this->X+30)&&(Link->Y>this->Y-8)&&(Link->Y<this->Y+32))
            {
                boss->Vx=0;
                boss->Vy=0;
                Game->PlaySound(19);
                Link->Action=7;//Link is hit
                Link->HP=Link->HP-8;//HP to remove
                Waitframes(60);
            }
            if ((sword->X>this->X-8)&&(sword->X<this->X+30)&&(sword->Y>this->Y-8)&&(sword->Y<this->Y+32))//if Link sword is at him
            {
                boss->Vx=0;boss->Vy=0;
                HP--;
                Game->PlaySound(11);//sound played when boss is hit
                boss->CSet=8;//flashing boss
                Waitframes(5);
                boss->CSet=7;
                Waitframes(5);
                boss->CSet=8;
                Waitframes(5);
                boss->CSet=7;
            }
            if (HP==0)//if boss does have no more HP left
            {
                boss->Vx=0;boss->Vy=0;
                Game->PlaySound(10);//the sound of the boss destroyed
                boss->Data=24988;boss->CSet=8; //Dying graphic
                Waitframes(5);
                boss->Data=24990;//Dying graphic
                Waitframes(5);
                boss->Data=24996;//Dying graphic
                Waitframes(5);
                boss->X=500;boss->Y=500;
                Quit();
            }
            if (d==0)
            {
                boss->Vx=1.5;
                boss->Vy=0;
            }
            if (d==1)
            {
                boss->Vx=-1.5;
                boss->Vy=0;
            }
            if (d==2)
            {
                boss->Vy=1.5;
                boss->Vx=0;
            }
            if (d==3)
            {
                boss->Vy=-1.5;
                boss->Vx=0;
            }
            if ((boss->X>=230)&&(d==0))//to keep the boss on the screen
            {
                d=1;
            }
            if ((boss->X<=0)&&(d==1))
            {
                d=0;
            }
            if ((boss->Y>=140)&&(d==2))
            {
                d=3;
            }
            if ((boss->Y<=0)&&(d==3))
            {
                d=2;
            }
            counter++;
            if (counter==60)//at each 60 frames, he changes direction
            {
                d=Rand(3);
                counter=0;
            }
            Waitframe();        
        }
    }
}


Pretty simple way to move though...

Edited by lucas92, 26 October 2008 - 07:09 PM.


#7 Christian

Christian

    Summoner

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

Posted 27 October 2008 - 01:56 AM

Ok one question , how do those boss scripts work? Like both of them. But mainly the bosstest one?

#8 lucas92

lucas92

    Defender

  • Members

Posted 27 October 2008 - 05:09 PM

Well, the boss test one is the same than the one with the movements but without movements.

The first if condition check if Link touches the FFC. Then it removes HP from Link.

The second if condition check if Link's sword touches the FFC. Then it removes HP from boss.

The last if condition check if boss has HP remaining. If not, then boss dies and the FFC ends.

Those scripts are mostly scripting practise though... I'm sure anyone could do better just by creating an npc then extending it... without Scripting. icon_razz.gif

#9 Joe123

Joe123

    Retired

  • Members

Posted 27 October 2008 - 05:18 PM

Why don't you attach an NPC to the ffc?
It's much easier than scripting your own collision detection.

#10 lucas92

lucas92

    Defender

  • Members

Posted 27 October 2008 - 05:30 PM

Could you show how to make the boss test with a npc pointer? I just don't have any idea how to attach a npc to a script... icon_frown.gif

#11 Joe123

Joe123

    Retired

  • Members

Posted 27 October 2008 - 05:49 PM

Ah, ok =P
Another point that I just thought of though;
Howcomes you've declared the ffc at the start of the script?
If you use 'this' as the name for the ffc, the system will use the ffc that the script is attached to, so you don't have to declare it.


CODE
ffc script thisMovingTest{
    void run(){
        npc e = Screen->CreateNPC(85); //this line names the npc, and creates it. In this case, it's a fire (Enemy ID 85), but it could be anything.
        e->Extend = 3;    // These make the boss bigger, and increase it's hitbox. Take them out if you don't want a 2x2 npc.
        e->TileWidth = 2;
        e->TileHeight = 2;
        e->EffectWidth = 32;
        e->EffectHeight = 32;
        int d=Rand(3);
        int counter; //if you declare a variable, it's set to '0' (or false for booleans) by default.
        
        //I'm assuming that the npc's going to be invisible, and the ffc will have the graphics. You could, however, use the npc's graphics and not have an ffc in the script.
        while(true){
            //Check whether the npc has died
            if(e->HP == 0){
                this->Vx=0;this->Vy=0;
                Game->PlaySound(10);
                this->Data=24988;this->CSet=8;
                Waitframes(5);
                this->Data=24990;
                Waitframes(5);
                this->Data=24996;
                Waitframes(5);
                this->Data = 0; // This removes the ffc in one line rather than two.
                Quit();
            }
            if(d == 0){
                this->Vx=1.5;
                this->Vy=0;
            }
            if(d == 1){
                this->Vx=-1.5;
                this->Vy=0;
            }
            if(d == 2){
                this->Vy=1.5;
                this->Vx=0;
            }
            if(d == 3){
                this->Vy=-1.5;
                this->Vx=0;
            }
            if(this->X >= 230 && d == 0) d = 1; //You don't need brackets around the individual checks, and if you only have one function to call inside an if, you don't need braces either
            if(this->X <= 0 && d == 1) d = 0;
            if(this->Y >= 140 && d == 2) d = 3;
            if(this->Y <= 0 && d == 3) d = 2;
            
            counter++;
            if(counter==60){
                d=Rand(3);
                counter=0;
            }
            
            //Attaching the enemy to the ffc is as simple as setting it's X and Y coordinates to the ffc's
            e->X = this->X;
            e->Y = this->Y;
            Waitframe();        
        }
    }
}


If you want the ffc to flash when the enemy gets hurt, I'll show you how I'd do it.

#12 lucas92

lucas92

    Defender

  • Members

Posted 27 October 2008 - 06:04 PM

Oh cool. icon_smile.gif

So if you want to include the script, you'd have to include the enemy on the screen, right?




#13 Joe123

Joe123

    Retired

  • Members

Posted 27 October 2008 - 06:06 PM

Well, no.
Not in this case.
This script uses Screen->CreateNPC, which means the script itself spawns the enemy.

You could just as easily use Screen->LoadNPC, which would load one of the enemies on the list that you put down in the editor.
You have to be wary with that one though; the system doesn't create the enemies on the list until the 4th frame you've been on the screen.
So that means you have to put 'Waitframes(4);' before Screen->LoadNPC.

#14 lucas92

lucas92

    Defender

  • Members

Posted 08 November 2008 - 10:06 AM

CODE
ffc script open2tilesdoor
{
    void run(int combodata,int combocset, int sound, int map,int screen)
    {
        bool drawcombo=false;
        while(true)
        {
            if ((Link->Y==this->Y+16)&&(Link->X>=this->X)&&(Link->X<=this->X+16)&&(Link->InputUp==true)&&(drawcombo==false))
            {
                Link->InputUp=false;
                Waitframe();
                drawcombo=true;
                Game->PlaySound(sound);
                Game->SetComboSolid(map,screen,(ComboAt(this->X,this->Y)),1111b);
                Game->SetComboSolid(map,screen,(ComboAt(this->X+16,this->Y)),1111b);
                Waitframe();
            }
            if (drawcombo==true)
            {
                Screen->DrawCombo(1, this->X, this->Y,combodata,2,1,combocset, 1, 0, 0, 0,1, 0, false, 128);
            }
        Waitframe();
        }
    }
}


This is a house door script just like in LTTP... The problem is that I need to make the combos walkable so Link could go to the stairs. The problem is that SetComboSolid always freeze Link's movements and the enemies' movements... How can I make the combos walkable?

#15 Saffith

Saffith

    IPv7 user

  • Members

Posted 08 November 2008 - 10:21 AM

When you change a combo's solidity, it changes the definition of the combo itself. In other words, it affects that combo everywhere it appears in the quest.
If you want to change a single tile's solidity, you need to use Screen->ComboD[] to change it to a different combo altogether.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users