Jump to content

Any Counter for Any Item

Overview
Creator: RephireZeKasual217 Updated: 30 Sep 2019 Tags: Global, Item Downloads: 23
Rating[?]: No rating
View Script Download Example
(903.45 KB)
Information

Description Setup Reviews Comments

SkyFlare  

Posted 21 January 2022 - 06:33 AM
No, in fact. It does not work!
He makes a mistake in compiling...
item scriptspecialcost
{
	void run(int msg, int counter, int cost, int errorSFX)
	{
		//Dummy script,just to get item cost data
	}
}
Encountered an error between tokens ....
Maybe it doesn't go into 2.53 (Beta 55) ???
 

Timelord  

Posted 30 September 2019 - 08:29 AM
This is an editor option in 2.55, FWTIW.

Please remember to use indents and proper brace structure.

Your item script has a huge efficiency issue with four if statements that are mutually-exclusive. The interpreter will parse each one of those, even when one evaluates true.

I strongly advising chnging those to if, then three else-if statements, as in so doing, once one evaluates true, then the remaineder of the block is skipped.

Also, this running last makes it ineffective:

if(Game->Counter[CR_MAGIC]){
   Cost = Cost*Game->Generic[GEN_MAGICDRAINRATE];
      }
In fact, the entire thing makes little sense there.

All that you need,is this:

// A generic method of applying custom item counter/cost to any item, 
// including flipper diving with sound effects for errors. 
// 30th September, 2019
// By: ZoriaRPG

//D0: The itempickup slot message. Reserved for pickup scripts.
//D1: The counter to use.
//D2: The item cost for that counter.
//D3: The sound to play to indicate an error (cannot use item)
item scriptspecialcost
{
	void run(int msg, int counter, int cost, int errorSFX)
	{
		//Dummy script,just to get item cost data
	}
}
		
global script testItemCosts
{
	void run()
	{
		while(1)
		{
			trybuttoncosts();
			Waitframe();
		}
	}
	void trybuttoncosts()
	{
		int attemptit = 1;
		if ( Link->Action == LA_NONE ) attemptit = 1;
		if ( Link->Action == LA_WALKING ) attemptit = 1;
		if ( Link->Action == LA_ATTACKING ) attemptit = 1;
		if ( Link->Action == LA_SWIMMING ) attemptit = 2; //dive only
		//other actions can't use items
		b_ButtonCosts(attemptit);
		a_ButtonCosts(attemptit);
		
	}
	void a_ButtonCosts(int attemptit)
	{
		itemdata theItem;
		if ( attemptit == 2 )
		{
			theItem = Game->LoadItemData(I_FLIPPERS);
		}
		else if ( attemptit == 1 ) 
		{
			theItem = Game->LoadItemData(GetEquipmentA());
		}
		
		if ( Link->PressA )
		{
			if ( attemptit ) 
			{
				if ( Game->Counter[ theItem->InitD[1] ] < theItem->InitD[2] )
				{
					Link->PressA = false;
					Link->InputA = false;
					Game->PlaySound(theItem->InitD[3]);
				}
				else
				{
					Game->Counter[ theItem->InitD[1] ] -= theItem->InitD[2];
				}
			}
			else //can't use items with the current Action
			{
				Link->PressA = false;
				Link->InputA = false;
				Game->PlaySound(theItem->InitD[3]);
			}
		}
	}
	void b_ButtonCosts()
	{
		itemdata theItem = Game->LoadItemData(GetEquipmentB());
		
		if ( Link->PressB )
		{
			
			if ( attemptit ) 
			{
				if ( Game->Counter[ theItem->InitD[1] ] < theItem->InitD[2] )
				{
					Link->PressB = false;
					Link->InputB = false;
					Game->PlaySound(theItem->InitD[3]);
				}
				else
				{
					Game->Counter[ theItem->InitD[1] ] -= theItem->InitD[2];
				}
			}
			else //can't use items with the current Action
			{
				Link->PressB = false;
				Link->InputB = false;
				Game->PlaySound(theItem->InitD[3]);
			}
		}
	}
}
That should be universally better, for 2.53. The item script just gives the global script's functions data for the costs and sounds for the item being used.

it handles flipper diving, and other events, and requires no global variables to function.

I haven't tested it, but logically, it should all work.
 

Jamian  

Posted 29 September 2019 - 01:47 PM
What is the point of:
if(Link->Jump==0){
Game->Counter[Counter]-=0;
}
?