Jump to content

Photo

Multiple Chest Script (Request)


  • Please log in to reply
18 replies to this topic

#1 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 14 May 2016 - 12:07 AM

Can someone Make A Chest Script?

I would like to place multiple chests it one subscreen

I was thinking arguments like..

A0 closed combo

A1 open combo

A2 item it contains

A3 sound1 it plays when opened or - 1 for nothing

A4 sound2 it plays when opened or - 1 for nothing

A5 text it shows when opened or -1 for nothing

A6 item it requires to open or -1 for nothing

 

Edit Better yet I'm going to try to do it myself.

however how do I get a ffc scripts arguments?

 

here is my code for tonight I'll work more on it tomorrow

if you guys see anything wrong with it so far please let me know.

import "std.zh"

ffc script Chest
{
    void run(int arg)
    {            
        ffc Chest = Screen->LoadFFC(1);    
        int OpenCombo = arg;
        
        bool Closed = true; 
        while (Closed)
        {  
            if (Link->InputB && (Link->X == Chest->X && Link->Y == (Chest->Y+1.0)))
            {
                Chest->Data = OpenCombo;
                Closed = false;       
            }
        }
    }
}


Edited by Shadowblitz16, 14 May 2016 - 01:26 AM.


#2 grayswandir

grayswandir

    semi-genius

  • ZC Developers

Posted 14 May 2016 - 03:32 AM

You can get the arguments like so:
void run (int a0, int a1, int a2) {
Of course, you can name them anything you want.

For sound, you can leave it as 0 for no sound, if you want, since there's no actual sound 0.

Also, you probably don't need a "closed" combo as an argument, since you'll probably want to just set the ffc's starting combo to that.

ffc Chest = Screen->LoadFFC(1);
You don't want this part - that'll only work if your chest ffc happens to be the first ffc on the screen. FFC scripts automatically make a variable "this" for whatever ffc is currently running. So instead of "Chest" later on, just use "this".

You're off to a good start. :)

#3 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 14 May 2016 - 06:29 AM

I wrote a Z3 style chest minigame script, if that'd be useful to you.

I suggest using '0' (rather than '-1') for the 'do nothing' value with your args, as when doing a statement evaluation, -1 will return true, thus:

ffc script foo{
    void run(int sfx, int msg){
        if ( sfx ) Game->PlaySound(sfx);
        if ( msg ) Screen->Mesage(msg);
    }
}
In these evaluations, setting msg to -1 would cause it to evaluate true, whereas if you use 0 (String: None), the statement would evaluate false. This is IMO the best way to call functions of this sort: Make calling the function depend on if the argument evaluates true, so that the function doesn't run if the user doesn't set it (to a valid value). This means that you use one argument for up to three purposes, provided they are mutually exclusive, as negative values still evaluate true, and you can redirect them:

if ( gfx ) {
    if ( gfx < 0 ) Screen->FastTile(GFX_LAYER, this->X, this->Y, (gfx *-1) , GFX_CSET, GFX_OPACITY);
    //Use a tile if gfx is negative.
    else this->Data = gfx; //Otherwise use a combo.
}
In most cases, these components will only have a valid value to call, with a rangeof 1 to 255, or similar. Usable sounds, sprites, strings combos, and tiles begin at a value of '1', and 0-value objects are designated as 'none' for each category.

Likewise, ffcs, *weapon objects, and npcs have pointers starting at '1'. This is to make full advantage of the ZScript (float to bool) automatic typecasting, so if you build your syntax around this, you will have cleaner, more efficient, and easier to implement code.[/quote]

Edited by ZoriaRPG, 14 May 2016 - 06:34 AM.


#4 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 14 May 2016 - 12:39 PM

Hmm how do I give Link a Item?

also does he automatically do his item stance when he picks an item up?

 

Edit: Also what is IT_constants used in Link->Item[]


Edited by Shadowblitz16, 14 May 2016 - 12:50 PM.


#5 jsm116

jsm116

    Script kludger

  • Members
  • Location:The 301

Posted 14 May 2016 - 05:30 PM

There's two ways to give Link an item. The simple way is to use 

Link->Item[itemnumber] = true;

But this won't show Link holding the item up or activate any changes that occur on pickup (such as item scripts or things like Rupees or Heart Containers). Having both the hold up and pickup effects happen you need to create the item on the screen at the correct moment. This would follow whatever triggers the chest opening.

item itemtodrop;

itemtodrop = Screen->CreateItem(itemtogive);
itemtodrop->X = Link->X;
itemtodrop->Y = Link->Y;
itemtodrop->Pickup = IP_HOLDUP;

where itemtogive is defined elsewhere as the item number to be hidden in the chest. Since the item is put in the same location as Link the game engine will automatically make him pick it up. For standard items, the numbers are the list I_ that start with I_AMULET = 50. You can also find the numbers in the item editor within ZQuest.


Edited by jsm116, 14 May 2016 - 05:31 PM.


#6 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 15 May 2016 - 11:20 AM

how do I make an ffc combo solid?

also how do I make my chest snap to the nearest grid block?


Edited by Shadowblitz16, 15 May 2016 - 09:02 PM.


#7 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 15 May 2016 - 09:38 PM

Can someone tell me why this isn't working?

import "std.zh"

ffc script chest
{
    void run(int itm, int sfx, int msg)
    {   

        ffc Chest = this;;
        Chest->X = Floor(Chest->X);
        Chest->Y = Floor(Chest->Y);
        //while(Closed)
        //{
            if (Link->PressA && Floor(Link->X) == Floor(Chest->X) && Floor(Link->Y) == Floor(Chest->Y))
            {
                Screen->FastTile(0, Chest->X, Chest->Y, Chest->Data+1, Chest->CSet, 1);
                dropItem(Link->X, Link->Y, itm);
                if (sfx > 0) { Game->PlaySound(sfx); }
                if (msg > 0) { Screen->Message(msg); }
            }
            Waitframe();
        //}
    }
    
    void dropItem(int X, int Y, int itm)
    {
        item itemtodrop;
        itemtodrop = Screen->CreateItem(itm);
        itemtodrop->X = X;
        itemtodrop->Y = Y;
        itemtodrop->Pickup = IP_HOLDUP;
    }
}



#8 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 15 May 2016 - 09:59 PM

Because you've commented out a bunch of key lines for some reason. Even after you fix that it won't work well, because you have nothing that sets the Closed variable. Matching Link's position to the chest is also way too stringent; use absolute value (Abs()) instead.

#9 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 15 May 2016 - 10:18 PM

Because you've commented out a bunch of key lines for some reason. Even after you fix that it won't work well, because you have nothing that sets the Closed variable. Matching Link's position to the chest is also way too stringent; use absolute value (Abs()) instead.

Ya seems like the tile graphic switch isn't working either

also the tile doesn't seem to aline when run.


Edited by Shadowblitz16, 15 May 2016 - 10:20 PM.


#10 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 15 May 2016 - 10:41 PM

FastTile (and all other draw commands) only draws something to the screen for a single frame. This is what you want to change the graphic of the chest.
 
this->Data++;
The FFC will be wherever you placed it. If it's not aligned to the grid, that's where it will stay. You can be more careful when you place it in ZQuest, or you can use a function like GridX() to align it for you.

Edited by Lejes, 15 May 2016 - 10:42 PM.


#11 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 15 May 2016 - 11:10 PM

ok thankyou

Edit: GridX() is a global function?


Edited by Shadowblitz16, 15 May 2016 - 11:18 PM.


#12 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 15 May 2016 - 11:21 PM

It's part of std.zh.

#13 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 16 May 2016 - 12:58 AM

how do I make my chest solid?

I know I can place a solid combo underneath/over it but is there a way to do this in a script?



#14 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 16 May 2016 - 01:19 AM

Nope. You can fake solidity, but it tends to look weird when you try to mess with Link's movement in an FFC script.

#15 Shadowblitz16

Shadowblitz16

    Illustrious

  • Members

Posted 16 May 2016 - 05:03 PM

My chest won't open when I put a solid tile on it!

import "std.zh"

ffc script chest
{
    void run(int itm, int sfx, int msg)
    {   
        ffc Chest = this;
        bool Open = true;
        while(Open)
        {
            if ((Link->PressA) && (Link->Dir == DIR_UP) && (Abs(Link->X) == Abs(Chest->X)) && (Abs(Link->Y) == Abs(Chest->Y+1)))
            {
                Screen->FastTile(0, Chest->X, Chest->Y, Chest->Data++, Chest->CSet, 1);
                if (sfx > 0) { Game->PlaySound(sfx); }
                dropItem(Link->X, Link->Y, itm);
                if (msg > 0) { Screen->Message(msg); }
                
                Open = false;
            }
            Waitframe();
        }
    }
    
    void dropItem(int X, int Y, int itm)
    {
        item itemtodrop;
        itemtodrop = Screen->CreateItem(itm);
        itemtodrop->X = X;
        itemtodrop->Y = Y;
        itemtodrop->Pickup = IP_HOLDUP;
    }
}

Edit:also Is there a way to save the chest's state?

so you can't open it more then once?


Edited by Shadowblitz16, 16 May 2016 - 05:05 PM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users