Jump to content

Photo

Boomerang Counter Request


  • Please log in to reply
14 replies to this topic

#1 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 03 March 2018 - 02:56 AM

I want to make a custom boomerang with 'ammo'

 

Part 1: A counter for "Script 1"

 

Part 2: A script that disables the item as long as the "Script 1" counter is at zero

 

I would very much like to do this. Thanks in advance.

 

EDIT: Also, each use of the item should reduce the "Script 1" counter by one


Edited by Cukeman, 03 March 2018 - 03:11 AM.


#2 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 04 March 2018 - 05:25 AM

This requires fully-scripting the item in 2.50.2.

#3 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 March 2018 - 05:43 AM

edit


Edited by Cukeman, 04 March 2018 - 05:43 AM.


#4 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 04 March 2018 - 09:36 AM

Eh, nevermind Zoria's post.

 

Needs a global script and an active item script. Set the constant to the item ID of your boomerang.

import "std.zh"

const int BoomerangID = 123; //set number to boomerang item ID

global script Active{
	void run(){
		while(true){
			if ( Game->Counter[CR_SCRIPT1] == 0 ) {
				if ( GetEquipmentA() == BoomerangID )
					Link->InputA = false;
				if ( GetEquipmentB() == BoomerangID )
					Link->InputB = false;
			}
			Waitframe();
		}
	}
}

item script BoomerangActive{
	void run(){
		Game->Counter[CR_SCRIPT1] --;
	}
}

This is untested but should do.


Edited by Avataro, 04 March 2018 - 09:42 AM.


#5 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 March 2018 - 03:33 PM

Eh, nevermind Zoria's post.

 

Needs a global script and an active item script. Set the constant to the item ID of your boomerang.

import "std.zh"

const int BoomerangID = 123; //set number to boomerang item ID

global script Active{
	void run(){
		while(true){
			if ( Game->Counter[CR_SCRIPT1] == 0 ) {
				if ( GetEquipmentA() == BoomerangID )
					Link->InputA = false;
				if ( GetEquipmentB() == BoomerangID )
					Link->InputB = false;
			}
			Waitframe();
		}
	}
}

item script BoomerangActive{
	void run(){
		Game->Counter[CR_SCRIPT1] --;
	}
}

This is untested but should do.

 

 

Compiled, but when I set the Boomerang's Counter Reference to Script 1, and Increase Amount to 1, the Script 1 Counter I added to my Passive Subscreen didn't increase.



#6 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 04 March 2018 - 04:27 PM

Compiled, but when I set the Boomerang's Counter Reference to Script 1, and Increase Amount to 1, the Script 1 Counter I added to my Passive Subscreen didn't increase.

 

You'll have to increase the counter max too. Max counter is basically like bomb bags, quivers, etc.



#7 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 March 2018 - 04:44 PM

It works now, awesome! Thank you!


You'll have to increase the counter max too. Max counter is basically like bomb bags, quivers, etc.

 

Can you add a delay to the item usage, so that you have to wait a little between button presses? It's currently possible to press the button and deplete ammo faster than you actually use it.


Edited by Cukeman, 04 March 2018 - 04:50 PM.


#8 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 04 March 2018 - 04:56 PM

Oh, huh weird. This might be a bit trickier then. Hopefully with this item script it works better:

item script BoomerangActive{
	void run(){
		for (int i = 1; i <= Screen->NumLWeapons(); i++) {
			lweapon wpn = Screen->LoadLWeapon(i);
			if ( wpn->ID == LW_BRANG )
				Quit();
		}
		Game->Counter[CR_SCRIPT1] --;
	}
}

It might be needed to be scripted a bit differently though.


Edited by Avataro, 04 March 2018 - 04:57 PM.


#9 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 March 2018 - 05:20 PM

edit

Edited by Cukeman, 04 March 2018 - 06:59 PM.


#10 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 04 March 2018 - 05:39 PM

Try changing Quit(); to Waitframe();. Might not make a difference, but you never know.



#11 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 March 2018 - 06:59 PM

Okay I made a mistake. I only tested the first script.
 
I just now tested the second script and the counter no longer decreases when I use the item.
 


Edited by Cukeman, 04 March 2018 - 07:09 PM.


#12 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 04 March 2018 - 07:38 PM

Oh it doesn't decrease at all now? If thats the case then then the counter decreasing script needs some different approach. Depending on how urgent you need this, I might get back to you on this  :augh:



#13 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 04 March 2018 - 08:10 PM

The first script works perfectly as long as the player's not rapidly pressing the item button, and doing so isn't going to do anything but discourage the player from doing it again  :P

 

I'll stick with the first script for now, as it allows me to make a lot of progress on my quest. Just a nitpick of a bug that can be addressed later.

 

Thanks for getting me this far, means a lot to me  :)


Edited by Cukeman, 04 March 2018 - 08:10 PM.


#14 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 22 March 2018 - 09:21 AM

Huh, I notice that this boomerang item can cause the assigned SFX to loop endlessly. I noticed it when:

 

A) The button was pressed as a message string was coming up (but the SFX stopped when the message was dismissed)

 

and

 

B) A button was pressed as I picked up the item, even though both A and B slots had items in them that weren't replaced. This time the SFX just kept going until I assigned the boomerang item and used it.


Edited by Cukeman, 22 March 2018 - 02:02 PM.


#15 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 22 March 2018 - 10:43 AM

tol'ja so

Eh, nevermind Zoria's post.
 
Needs a global script and an active item script. Set the constant to the item ID of your boomerang.

import "std.zh"

const int BoomerangID = 123; //set number to boomerang item ID

global script Active{
	void run(){
		while(true){
			if ( Game->Counter[CR_SCRIPT1] == 0 ) {
				if ( GetEquipmentA() == BoomerangID )
					Link->InputA = false;
				if ( GetEquipmentB() == BoomerangID )
					Link->InputB = false;
			}
			Waitframe();
		}
	}
}

item script BoomerangActive{
	void run(){
		Game->Counter[CR_SCRIPT1] --;
	}
}

This is untested but should do.

Aye, obviously it was this simple. :P

Tol'ja.

You can get most of the way there with these hacks, but, not in a 'foolproof' way.

If you want something better:

const int SFX_ERROR = 63;

//Call before Waitdraw() in the infinite loop of your active script.
//It might suffice.
void BoomerangCancel()
{
     int iA = GetEquipmentA(); int iB = GetEquipmentB();
     itemdata idA = Game->LoadItemData(iA);
     itemdata idB = Game->LoadItemData(iB);
     int icA = idA->Class; int icB = idB->Class;
     if ( Link->PressA() )
     {
          if ( icA == IC_BRANG )
          {
               if ( Game->Counter[CR_SCRIPT1] > 0 )
               {
                    --Game->Counter[CR_SCRIPT1];
               }
               else { Link->PressA = false; Game->PlaySound(SFX_ERROR); }
          }
     }
     if ( Link->PressB )
     {
          if ( icB == IC_BRANG )
          {
               if ( Game->Counter[CR_SCRIPT1] > 0 )
               {
                    --Game->Counter[CR_SCRIPT1];
               }
               else { Link->PressB = false; Game->PlaySound(SFX_ERROR); }
          }
     }
}

This may do what you want. The only way to interrupt using the brang itemclass items is to cancel button presses, however, this can also cancel buttoninputs needed by other scripts, and cause conflicts. (e.g., If you have a script that reads pressing A, or B, to talk to an NPC.)

Fully scripting the item is the only way to do what Cukeman wants, without a chance of quest bugs.

If that gives you an error on itemdata->Class, change 'Class' to 'Type'.


Avataro also forgot, or didn't know that this type of thing requires a proper call to Waitdraw() in the active script, and must be called prior to it:

global script TestBrangCounter
{
     void run()
     {
          while(1)
          {
               BoomerangCancel(); // <---- Must be BEFORE Waitdraw()
               Waitdraw(); // <---- MUST CALL this instruction!
               Waitframe();
          }
     }
}

The bug that causes his script to repeat is caused primarily by reading Link->Input, instead of Link->Press, but either way, you want this kind of event to occur prior to drawing.

(It can still cause issues with other code that requires reading button presses on the same button, all the same.)

P.S. I used itemdata here, as that ensures that the code works with any boomerang class item, rather than specific item IDs.

If you want a list of specific items, then you'd iterate an array that contains a list of each specific item ID against each button press. Let me know if you need that. :shrug:


P.P.S. I have an error on line 11. Editing that post, to correct it, using Android OS would require me to manually re-tab the whole thing.

Remove the parens from PressA() ... It should be PressA

Sorry for the classic Zoria-length™ post, but these were all key points to cover.


P.P.P.S.

Try changing Quit(); to Waitframe();. Might not make a difference, but you never know.


Calling Waitframe() in an item script acts as Quit(). As soon as the frame ends, the script execution (item script stack execution) immediately halts.

Spoiler



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users