Jump to content

Photo

Anthus Asks Questions About Scripting


  • Please log in to reply
94 replies to this topic

#16 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 10 May 2016 - 03:51 PM

Yeah, it is nice. :P

 

Disregard the combining thing in my last post. I just realized that the FFC trigger can work with either one >.> (or, if I'm not mistaken, any projectile that uses its tile as D0). The two triggers will never be on the same screen in a real quest, so I was confusing myself by having one of each on my test screen. 

 

I'm going to go ahead and try to make a little area with the triggers activating secrets, and changing to warps (portals).

 

 

EDIT: Turns out the Book causes some problems. The script itself is solid. It is a compact and simple script that I can actually understand. Plus, it has a lot of uses. But the book. So, the book as this little habit of changing the current wand's Magic sprite to whatever the Magic sprite is set as in the Book item for all Wand item classes. This effectively breaks the Sun/ Moon differences.

 

So, I guess, is there a way to combine the book enabling with the sun rod/ disabling with the moon rod again? Like before, the book should be 'off' when using the standard Wand item (and the trigger uses the default Magic (Wand) tile), and the book should be enabled when using the Sun Rod. The tile for the book magic, and sun rod magic are the same. I hope I'm making sense. It's hard to articulate exactly what I mean at times with this stuff :heh:

 

Actually, you know what? I can probably get rid of the book altogether. It really only makes this more complicated, and the only reason I wanted it in so badly was so the Sun Rod would act lik Z1's wand w/ Book, but trigger different (custom) triggers. I have a work around for making both wands worth using, even if they function the same outside of the environmental portal puzzles.

 

I am going to try a few more things. If you have any questions, about any of this, please ask. I know I can be bad at explaining stuff at times.



#17 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 10 May 2016 - 05:03 PM

Yeah, probably better not to use the book at all. Anything that would've required it should be easy to add with modifications to the script, or just by adding another.
Having the wands toggle the book might not be as big a deal as I thought, though. It looks like magic remembers whether you had the book when it was created, so toggling it while magic's already on screen may not make a difference. If you want to try, the modifications are trivial. Here's the SunWand script with book enabling added:
item script SunWand{
	void run(){
		if(!Link->Item[I_BOOK])
			Link->Item[I_BOOK] = true;
		int FFCSunWand[] = "FFCSunWand";
		int SunWandID = Game->GetFFCScript(FFCSunWand);
		if(CountFFCsRunning(SunWandID)==0)
			RunFFCScript(SunWandID, 0);
	}
}

  • Anthus likes this

#18 grayswandir

grayswandir

    semi-genius

  • ZC Developers

Posted 10 May 2016 - 05:26 PM

The sun wand is already using an ffc to keep track of things. It wouldn't be too hard to just mimic the effects of the book in the script itself.

#19 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 10 May 2016 - 06:51 PM

Thanks, Saffith, that minor addition worked flawlessly.

 

Now, I can have two wands with the book on one, and have two different magic triggers, Thanks a ton, Moosh, and Saffith!

 

And thanks ywkls, as well. You oughta test your scripts before making them public though ;)

 

The small issue with switching wands is something that will just have to be. Super Metroid had graphical bugs if you switched beams while a shot was on screen, so whatevs, people still love that game :P

 

I will be making all these item/ FFC scripts into one file with some script name changes for my organization, but you will be credited.

 

EDIT: Here is the code I'm using. I put these in one file myself, and it worked. This will make it to the "final engine".

Spoiler


#20 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 13 May 2016 - 11:14 AM

So this is a question more than a request, but I thought I'd post it in this thread so I don't have to start a new one :D

 

Is there a way to make it so that items dropped by enemies stay on the screen permanently? I don't mean things like keys that are held by enemies, or special items that are dropped after they are killed, but rather things like rupees that are dropped.

 

In AlttP, there are Rupee rooms, where you can find several blue rupees on the floor. I set up a dummy enemy in ZC that has a 100% chance of dropping rupees, and dies as soon as you enter the screen (sad little guy, really). Placing this with flags makes a nice rupee room effect, and allows for custom placement, and greater freedom over the built-in 10-rupee rooms. However, the rupees disappear. Is there a way to make them not do that? This is pretty trivial, but it would be cool. Any ideas?



#21 DrDiabetus

DrDiabetus

    Newbie

  • Members
  • Location:Germany

Posted 13 May 2016 - 11:25 AM

You could make an FFC Script that will create Items on different locations once you enter the Screen. If Link collects one of them, it will set a Screen -> D[] Variable, so that the same Rupee won't spawn again

 

Edit: This could do it, but you can only have 8 Rupees at max and you can not use any other Scripts that use the corresponding

        Screen -> D[] Variable.

import "std.zh"  // Only include this once in youre Main Script File

/////////////////////////////////////////////////////////////////////////////////////////
// FFC Script Rupee Room                                                               //
//                                                                                     //
// Check run at Screen Init for better visual.                                         //
//                                                                                     //
// D0: ItemID to spawn.                                                                //
// D1: Screen -> D[] Variable to use (0-7).                                            //
/////////////////////////////////////////////////////////////////////////////////////////

ffc script Rupee_Room {
	void run(int rupee, int screend) {
		item itm;
		if(Screen -> D[screend] == 0) {
			itm = CreateItemAt(rupee, this -> X, this -> Y);
		}
		while(Screen -> D[screend] == 0) {
			Waitframe();
			if(!itm -> isValid()) {
				Screen -> D[screend] = 1;
			}
		}
	}
}

Edited by IntimFuchtler, 13 May 2016 - 12:04 PM.

  • Anthus likes this

#22 grayswandir

grayswandir

    semi-genius

  • ZC Developers

Posted 13 May 2016 - 12:42 PM

The main thing is that ZC uses the same flag for items disappearing as for them being able to be picked up by weapons. So if you want permanent items, you can't have them boomerangable, etc.
(You might be able to bypass this by toggling the flag every frame somehow.)
 
 
The above script is a decent way to do that. If you want to get past the 8 rupee limit, you can treat the D as a flagset - that'll give you 16 (17?) slots per D.
 
// To set rupee i (starting from 0):
Screen->D[0] |= 1 << i;
// To test rupee i (starting from 0):
if (0 == Screen->D[0] & (1 << i)) {

  • DrDiabetus likes this

#23 Saffith

Saffith

    IPv7 user

  • ZC Developers

Posted 13 May 2016 - 12:44 PM

I think if you unset the pickup flag, the items would hang around. But, yeah, it's easier and cleaner to use a script that just places the items itself.
Here's my version. Uses flags General Purpose 1-5 (layer 0, not inherent) to mark item locations, up to 17 per screen. D0 is flag 1 item, D1 is flag 2 item, etc. Set an argument to -1 to ignore the corresponding flag.
const int ITEMPLACER_SCREEND = 0; // Set to 0-7

ffc script ItemPlacer
{
    void run(int item1, int item2, int item3, int item4, int item5)
    {
        int itemIDs[]={ item1, item2, item3, item4, item5 };
        item items[17];
        int index=0;
        int maxIndex=0;
        
        for(int i=0; i<176 && index<17; i++)
        {
            int flag=Screen->ComboF[i]-CF_SCRIPT1;
            if(flag<0 || flag>4)
                continue;
            
            if(itemIDs[flag]>=0)
            {
                if((Screen->D[ITEMPLACER_SCREEND]&(1<<index))==0)
                    items[index]=CreateItemAt(itemIDs[flag], ComboX(i), ComboY(i));
                index++;
            }
        }
        maxIndex=index;
        
        while(true)
        {
            Waitframe();
            for(index=0; index<=maxIndex; index++)
            {
                if((Screen->D[ITEMPLACER_SCREEND]&(1<<index))==0)
                {
                    if(!items[index]->isValid())
                        Screen->D[ITEMPLACER_SCREEND]|=1<<index;
                }
            }
        }
    }
}

The main thing is that ZC uses the same flag for items disappearing as for them being able to be picked up by weapons. So if you want permanent items, you can't have them boomerangable, etc.
(You might be able to bypass this by toggling the flag every frame somehow.)

No, that doesn't work. The timer isn't reset when the flag is toggled, so it'd just take longer.
  • Anthus likes this

#24 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 30 July 2016 - 11:12 PM

Hello all. So I have another random script request. I don't know if this would be hard to do or not, but we'll see. I am wondering if someone could script a sword that breaks (leaves Link's inventory permanently) after connecting with an enemy 100 times. Basically, the Razor sword from Majora's Mask. I want to specify though, it should only count against the sword's 'life' if Link actually hits an enemy with it. Not just by swinging it alone. I'm hoping this can be something simple like an active item script, and not something global. This will only be used for one sword in the game, if that matters.

 

This could be more than someone might be willing to do, but it would be cool if I could tell the script to play a string, and possibly a sound effect when it does "break" (on the 100th contact with an enemy).

 

This would be greatly appreciated, and if anyone takes the time to do this, I thank you. :)



#25 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 31 July 2016 - 12:34 AM


int EngineEvents[214747]; //Global array to hold game event datum.
const int BREAK_SWORD_COUNT = 214700; //Leave alone unless you  know why this exists.

const int ITM_BREAK_SWORD = 1; //Breakable sword item number
const int SFX_BREAK_SWORD = 34; //Sound effect
const int MSG_BREAK_SWORD = 1000; //Message string.

item script BreakSword{
	void run(int msg){ //d0 left open for pickup script message.
		lweapon sword; npc n;
		for ( int q = Screen->NumLWeapons(); q >= 0; q--){
			sword = Screen->LoadLWeapon(q);
			if ( sword->ID == LW_SWORD ) {
				for ( int w = Screen->NumNPCs(); w >= 0; w--) {
					n = Screen->LoadNPC(w);
					if (Collision(sword,n) {
						++EngineEvents[BREAK_SWORD_COUNT];
						if ( EngineEvents[BREAK_SWORD_COUNT] >= 100 ) {
							EngineEvents[BREAK_SWORD_COUNT] = 0;
							if ( SFX_BREAK_SWORD ) Game->PlaySound(SFX_BREAK_SWORD);
							Link->Item[ITM_BREAK_SWORD] = false;
							if ( MSG_BEAK_SWORD ) Screen->Message(MSG_BREAK_SWORD);
						}
					}
				}
			}
		}
	}
}  

Try this (hopefully no typos, made on me mobile).
  • Anthus likes this

#26 coolgamer012345

coolgamer012345

    🔸

  • Members
  • Location:Indiana, USA

Posted 31 July 2016 - 12:41 AM

 

-snipped for tidiness-

Try this (hopefully no typos, made on me mobile).

 

Looking over that code, wouldn't that increase EngineEvents[BREAK_SWORD_COUNT] for however many frames the sword contacted an enemy?



#27 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 31 July 2016 - 12:55 AM

No, it only runs for one frame, but that brings me to a sudden conclusion: Thinking about it...this will need an ffc, as it'll ignore sword events that take place frames later than the item use.

That's what I get for a minimalist approach.

Edited by ZoriaRPG, 31 July 2016 - 12:57 AM.


#28 grayswandir

grayswandir

    semi-genius

  • ZC Developers

Posted 31 July 2016 - 01:07 AM

It'd be pretty easy to work around if you changed it from "per enemy hit" to "per swing that hits an enemy" - you could just use a misc value on the weapon itself. You could also run the check in the active script.


  • Anthus likes this

#29 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 31 July 2016 - 01:13 AM

Let's try it again...this time, it requires

int EngineEvents[214747]; //Global array to hold game event datum.
const int BREAK_SWORD_COUNT = 214700; //Leave alone unless you  know why this exists.

const int ITM_BREAK_SWORD = 1; //Breakable sword item number
const int SFX_BREAK_SWORD = 34; //Sound effect
const int MSG_BREAK_SWORD = 1000; //Message string.

item script BreakSword{
	void run(int msg){
		int ff[]="BreakswordFFC";
		int fs = Game->GetFFCScript(ff);
		bool match; lweapon sword; int q;
		for ( q = Screen->NumLWeapons(); q >= 0; q--){
			sword = Screen->LoadLWeapon(q); 
			if ( sword->ID == LW_SWORD ) sword->Misc[9] = 10244;
		}	
		for (int q = 1; q <= 32; q++) {
			ffc f = Screen->LoadFFC(q);
			if ( f->Script == fs ) match = true;
		}
		if (!match ) RunFFCScript(fs,NULL);
	}
}

ffc script BreakswordFFC{
	void run(){
		lweapon sword; npc n;
		while(true){
			for ( int q = Screen->NumLWeapons(); q >= 0; q--){
				sword = Screen->LoadLWeapon(q);
				if ( sword->ID == LW_SWORD && sword->Misc[9] == 10244 ) {
					for ( int w = Screen->NumNPCs(); w >= 0; w--) {
						n = Screen->LoadNPC(w);
						if (Collision(sword,n) ){
							sword->Misc[9] = 0;
							++EngineEvents[BREAK_SWORD_COUNT];
							if ( EngineEvents[BREAK_SWORD_COUNT] >= 100 ) {
								EngineEvents[BREAK_SWORD_COUNT] = 0;
								if ( SFX_BREAK_SWORD ) Game->PlaySound(SFX_BREAK_SWORD);
								Link->Item[ITM_BREAK_SWORD] = false;
								if ( MSG_BEAK_SWORD ) Screen->Message(MSG_BREAK_SWORD);
							}
						}
					}
				}
			}
			Waitframe();
		}
	}
}

P.S. He specified no global active script usage in the request, hence why this is now needlessly complicated.
Edit: Requires ffcscript.zh

I'm not up to reposting all that to edit the top line. I simple adore these Android browsers, and their penchant to demolish PureZC post edits...

Edited by ZoriaRPG, 31 July 2016 - 01:11 AM.

  • Anthus likes this

#30 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 31 July 2016 - 10:48 AM

You guys are awesome, thanks. :)

I will be trying this out later after looking at some cars (which is almost as exciting as this script).

Edit: and I feel the mobile posting pain. 75% of my posts are from my phone these days and I can't imagine trying to write a script on this phone. :P


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users