Jump to content

Photo

Anthus Asks Questions About Scripting


  • Please log in to reply
94 replies to this topic

#31 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 31 July 2016 - 03:06 PM

T2ne4bL.png

 

What do I do now? Do I still need the first script?

 

Thanks!

 

Script:

Spoiler


#32 coolgamer012345

coolgamer012345

    🔸

  • Members
  • Location:Indiana, USA

Posted 31 July 2016 - 03:14 PM

import "std.zh"
import "ffcscript.zh"

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_BREAK_SWORD ) Screen->Message(MSG_BREAK_SWORD);
							}
						}
					}
				}
			}
			Waitframe();
		}
	}
} 

I think that'll work. Remember that you'll need ffcscript, so if you don't have that, you can find it in Saffith's signature (There's also a thread for it, but I don't know if it's up to date or not).



#33 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 31 July 2016 - 03:47 PM

D' oh, I forgot to include the ffcscript header >.>

 

It compiles now, I have that from the Sun/ Moon Rod shenanigans I was messing with earlier in this thread (which I still intend on using ;))


  • coolgamer012345 likes this

#34 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 31 July 2016 - 04:52 PM

'BEAK' sowrd. Gorgeous.

Send us a note and let us know if it works as you desire; or if it fails to work for whatever reason.
  • Anthus likes this

#35 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 31 July 2016 - 09:23 PM

I have loaded the script into the active slot on the magic sword to test it out. I am using the sword tap SFX, and using string 1 for testing. These are near the top of the script, and are set up like this:

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

The script compiles fine and Item 7 is the magic sword (which will be internally referred to as BEAKSWORD forever :P)

 

The problem is, it doesn't seem to do anything. I made a Stalfos with 10,000 HP, and hit it well over 100 times, and nothing happened. I am not ruling out me setting something up wrong however. If anyone wants to see the quest file, I went ahead and uploaded it. (EDIT: Go down from the starting screen, and wail on the Stalfos who can't actually hurt you, but has a stupid amount of HP.)



#36 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 31 July 2016 - 10:04 PM

As I recall, the sword lweapon doesn't actually exist when the item script runs. It only poofs in a few frames after the button is pressed. So an item script trying to set Misc values on it will fail. That needs to be pushed into the FFC script the item script launches.
  • Anthus likes this

#37 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 01 August 2016 - 12:59 AM

I'm willing to use a global if it is easier to code, and still straightforward enough to plug my stuff in. This quest will only use a few other ffc/ item scripts and no other globals so it is OK.

As long as I have concise instructions I can usually figure stuff out.

And again, thanks for helping me with this guys. It is really cool and I appreciate it.

#38 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 01 August 2016 - 01:20 AM

for (int i = 0; NumLWeaponsOf(LW_SWORD) == 0 && i < 4; i++) Waitframe();
sword = LoadLWeaponOf(LW_SWORD);
if (!sword->isValid()) Quit();
sword->Misc[0] = 10244;
You could add this in to the beginning of BreakSwordFFC. It waits around until there's a sword. If something interrupts the sword attack, it'll auto quit.
  • Anthus likes this

#39 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 01 August 2016 - 01:49 AM

for (int i = 0; NumLWeaponsOf(LW_SWORD) == 0 && i < 4; i++) Waitframe();sword = LoadLWeaponOf(LW_SWORD);if (!sword->isValid()) Quit();sword->Misc[0] = 10244;
You could add this in to the beginning of BreakSwordFFC. It waits around until there's a sword. If something interrupts the sword attack, it'll auto quit.
The reason that I wroyte it to use the item script, is that if the game allows the player to use multiple swords, at one time, which I presume it will given this, that using any sword might add to the value. You need to detect which sword was used last.

I didn't recall that sword lweapons aren't available on the frame on which the item was used.

That codebock may do it, but it's not infallible. Then again, no method of checking the originating item of an lweapon is infallible.

If the script didn't care about checking collision, this would be mad easy. The only method of ensuring it, requires a fully scripted sword, which is more complex than the OP likely wants to consider using.

Edited by ZoriaRPG, 01 August 2016 - 01:55 AM.

  • Anthus likes this

#40 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 01 August 2016 - 02:25 AM

The reason that I wroyte it to use the item script, is that if the game allows the player to use multiple swords, at one time, which I presume it will given this, that using any sword might add to the value. You need to detect which sword was used last.

I didn't recall that sword lweapons aren't available on the frame on which the item was used.

That codebock may do it, but it's not infallible. Then again, no method of checking the originating item of an lweapon is infallible.

If the script didn't care about checking collision, this would be mad easy. The only method of ensuring it, requires a fully scripted sword, which is more complex than the OP likely wants to consider using.

 

Actually; and this is entering minor spoiler territory for my project, but, this will be the only sword available to the player for quite some time. For all intents, and purposes, this is the only sword the player will have and at the very least, be the first sword they can get. The later swords will be obtained after managing to keep this particular sword item (and will be resolved via string control codes). The script only needs to be for one sword item. :)

 

I'm not opposed to using a global script for this since it will be the only one. Especially if it is easier and more efficient to code it that way for you guys. The only reason I was against it before was cause I assumed it would make stuff more complicated. I will try adding Lejes' snippet in tomorrow, but for now, I am pretty beat, and passing out. :P

 

 

EDIT: I'm not exactly sure where to add in that bit of code. I know it has to be after the void run, but I don't know if I need to add brackets, or what the exact syntax should be. I did a simple copy-paste into the line right after void run(), and got some errors.



#41 Saffith

Saffith

    IPv7 user

  • Members

Posted 01 August 2016 - 04:14 PM

I took a shot at it. See if this'll do.
const int BREAKSWORD_ITEM = 7;
const int BREAKSWORD_SFX = 57;
const int BREAKSWORD_MSG = 1;

int BreakSword_Counter;

item script BreakSword_action
{
    void run()
    {
        int scriptName[]="BreakSword_ffc";
        int scriptNum=Game->GetFFCScript(scriptName);
        if(CountFFCsRunning(scriptNum)==0)
            RunFFCScript(scriptNum, NULL);
    }
}

item script BreakSword_pickup
{
    void run()
    {
        BreakSword_Counter=100;
    }
}

ffc script BreakSword_ffc
{
    void run()
    {
        bool hit=false;
        bool found=true;
        while(found)
        {
            found=false;
            for(int i=1; i<=Screen->NumLWeapons(); i++)
            {
                lweapon sword=Screen->LoadLWeapon(i);
                if(sword->ID!=LW_SWORD)
                    continue;
                found=true;
                if(!hit) // If it already hit, don't check again
                {
                    for(int j=1; j<=Screen->NumNPCs(); j++)
                    {
                        npc enemy=Screen->LoadNPC(j);
                        if(enemy->ID<20) // Ignore fairies
                            continue;
                        if(enemy->Defense[NPCD_SWORD]==NPCDT_IGNORE)
                            continue;
                        if(Collision(sword, enemy))
                        {
                            hit=true;
                            break;
                        }
                    }
                }
                break;
            }
            
            Waitframe();
        }
        
        if(hit)
        {
            BreakSword_Counter--;
            if(BreakSword_Counter==0)
            {
                Link->Item[BREAKSWORD_ITEM]=false;
                Game->PlaySound(BREAKSWORD_SFX);
                Screen->Message(BREAKSWORD_MSG);
            }
        }
    }
}
This one waits for the sword to disappear before removing it because I found a bug. Removing the sword in mid-swing will cause the game to read the wrong item data when deciding whether to fire a beam.
  • Anthus likes this

#42 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 01 August 2016 - 04:45 PM

Thanks for taking a stab at it, Saffith (sword pun totally intended).

 

It compiles fine, and it's cool that it appears that you can edit the amount of hits on line 22. Since I didn't feel like stabbing something 100 times to test it, I changed the value to 4, and it still doesn't seem to do anything. I also tested it with 100 as the value just in case, and still no dice.

 

Are there any quest rules or anything I should look at? I have 'messages freeze all action', and 'messages can be be sped up' checked. Other than that, the quest is pretty much NES rules. This is kind of a dumb question, but I don't have to place the FFC on each screen right? I'm guessing the script handles all of that. Just want to be sure I'm not missing any obvious set-up stuff. I also added import std.zh, and ffcscript.zh to the top of the script. In the real game, the scripts will be imported from a master file, and this script won't have that stuff at the top, this is just for testing.

 

Also, on a side note, this is the first time I've had a script compile, but not work. Usually they won't compile if it's not gonna work, so that is a good sign, since it probably means it is on my end, and not a problem with the script. >.>

 

I'm gonna try a few more things. I have this on the default Magic Sword, but should it be on the Level 1 sword (not level 3)? And out of random curiosity, how long does it take to write up a script like that? It seems like a longer one, but I've seen some super long scripts for bosses, or for other engine-y stuff.



#43 Saffith

Saffith

    IPv7 user

  • Members

Posted 01 August 2016 - 05:18 PM

You might have to do something else to initialize the counter. It's set in the pickup script, so it won't work if it's given in init data or something.
If you only ever need it to work once, you could just set the counter where it's declared. That would mean changing the fourth line to
int BreakSword_Counter=100;
 

I have this on the default Magic Sword, but should it be on the Level 1 sword (not level 3)?

The script will work the same on any sword. You need to set BREAKSWORD_ITEM accordingly, but it could also be changed to an argument easily.
 

And out of random curiosity, how long does it take to write up a script like that? It seems like a longer one, but I've seen some super long scripts for bosses, or for other engine-y stuff.

That one took... half an hour, maybe? Partly because the first version triggered that stupid bug. It's really a pretty simple one, so fixing typos and testing were the time-consuming parts.
  • Anthus likes this

#44 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 01 August 2016 - 05:54 PM

You might have to do something else to initialize the counter. It's set in the pickup script, so it won't work if it's given in init data or something.

 

Ah, so that's good to know. I did have it given in the init. data. I started a new file with the item placed on the screen directly, and picked it up. I changed line 4. It still compiles fine, but I'm still not able to get it to do anything.

 

Were you able to get it to work in your testing? Was it just a clean quest file with no rules, or anything? I'm sorry to trouble you guys so much, but I can't figure it out lol. Is there any way I could see the working example in your quest file?

 

Here is what the script looks like in my quest file:

Spoiler

 

I also re-uploaded the test quest, if anyone is willing to take a look.

 

Endless thanks again to the scripting wizards who help me, and anyone else less able to script for themselves :D



#45 Saffith

Saffith

    IPv7 user

  • Members

Posted 01 August 2016 - 05:58 PM

Huh. You're not reusing an existing save, right? Doesn't sound like you are.

If you enable level 4 cheats and check Cheat > Show/Hide Layer > Current FFC Scripts, does BreakSword_ffc show up briefly when you use the sword?


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users