Jump to content

Photo

With ZScript how do I add Sword 1 (Wooden) if Link does not have it?


  • Please log in to reply
3 replies to this topic

#1 LikeLike888

LikeLike888

    Spicy food lover!!

  • Members
  • Real Name:Jason
  • Location:North America

Posted 20 November 2017 - 12:39 AM

With ZScript how do I add Sword 1 (Wooden) if Link does not have it?


I am asking up above so I can know how to add items with ZScript as I please.



What format (example .zscript) do I save up above mentioned coding in NotePad?


How do I make up above mentioned ZScript apply to DMap0 named Kylee?

#2 Geoffrey

Geoffrey

    Chosen One

  • Members

Posted 20 November 2017 - 05:19 AM

I know nothing except that the proper file extension is .z.


  • LikeLike888 likes this

#3 justin

justin

    Adept

  • Members

Posted 20 November 2017 - 08:56 AM

Why does this need to be a script? What is the scenario that makes the code run?

 

 

Look in zscript.txt and you'll find under the Link heading. And in std_constants.zh under the Items heading. Wooden sword is I_SWORD1.

 

Here's the entry for Link items from zscript.txt

/**
* True if Link's inventory contains the item whose ID is the index of
* the array access. Use the I_ constants in std.zh as an index into this array.
*/
bool Item[];
 
 
And combined together we get
if(!Link->Item[I_SWORD1]) Link->Item[I_SWORD1]=true;
 
So we are evaluating whether Link has the wooden sword item, and giving it to him if he doesn't. !Link->Item[] means does NOT have, and is the same as writing Link->Item[] == false.
 
But now you have to figure out where to put that and why because it's not going to compile like that.
 
 
Edit:
Oh, and you were asking about DMaps. Well, ZScript doesn't care about what the DMap is named just it's number. 
But if we go back to what ZoriaRPG said in this previous post you made, https://www.purezc.n...showtopic=73163and combine the two ideas...
 
if ( Game->GetCurDMap() == 2 ) 
{
 if(!Link->Item[I_SWORD1]) Link->Item[I_SWORD1]=true;

}
 
So that's assuming that DMap Kylee is DMap 2. You just change the number to whatever it actually is. Or you could create a constant to keep track of it for you.
 
const int DMAP_Kylee = 0;
 
if ( Game->GetCurDMap() == DMAP_Kylee )
{
}
 
Now again, none of this will actually compile. You could put the code in your global loop or as part of FFC or item code.

Edited by justin, 20 November 2017 - 09:01 AM.

  • LikeLike888 likes this

#4 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 20 November 2017 - 10:18 PM

Using constant definitions is indeed, the best option.

//Declare and define a constant so that you can use its identifier:
const int DMAP_Level_1 = 2;
 
if ( Game->GetCurDMap() == DMAP_Level_1 ) //Now we can reference it by name.

DMAP_Level_1 resolves to the literal '2', so the above is identical to : if ( Game->GetCurDMap == 2 ), save that it is more readable this way, and, you can change the DMap comparison throughout a large series of scripts, simply by adjusting the value of the constant definition.

 

You can also pass DMap IDs into ffc script, or item script args:

ffc script OnlyOnDMap
{
    void run(int dmap_id)
    {
        //Quit if we are not on the correct DMap.
        if ( Game->GetCurDMap() != dmap_id )
        {
            this->Data = 0; Quit();
        }
        //Do everything else here.
    }
}
 
const int SFX_ERROR = 64; //An error sound
 
item script Flame
{
    //Do something different if we are on the specified dmap
    //We'll say that one of your DMaps is a water level, so, a fire weapon makes no sense.
    void run(int dmap_id)
    {
        lweapon l;
        if ( Game->GetCurDMap() != dmap_id )
        {
            l = Screen->CreateLWeapon(LW_FIRE);
            l->X = Link->X+InFrontX(Link->Dir, 8);
            l->Y = Link->Y+InFrontY(Link->Dir, 8));
            Game->PlaySound(SFX_FIRE);
        }
        else
        {
            //We are on the water DMap, so, make an error sound.
            Game->PlaySound(SFX_ERROR);
        }
    }
}

Here's a bonus, generic item giving FFC:

ffc script GiveItem
{
    void run(int item_id)
    {
        if ( !Link->item[item_id] ) Link->Item[item_id] = true; Quit();
    }
}

;

 

 

Here is an example of how to invert an boolean state:

ffc script GiveItem
{
    void run(int item_id)
    {
        Link->Item[item_id] = (!(Link->item[item_id])); Quit();
        //Flips the state.
    }
}

Edited by ZoriaRPG, 20 November 2017 - 10:31 PM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users