Jump to content

Photo

Make any item use magic.


  • Please log in to reply
6 replies to this topic

#1 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 12 July 2017 - 01:28 AM

Hello all. I was wondering if anyone can whip up an item script that allows me to set a D0 value which is the amount of magic that item would use. I would like to implement a 'stamina' bar like ALBW where every item uses "Stamina". However, some items will not use stamina, but if this is doable, I was hoping it could just be an active script attached to certain items.

 

Thanks again! :)



#2 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 12 July 2017 - 04:22 AM

That will require a global active script. Is that what you want?
 
Set costs for each item in your Init script using SetItemMagicCost(), following the example global scripts (below).
 
const int SFX_MAGIC_ERROR = 0;

item script UseMagic{
	void run(int cost){
		cost = cost*Game->Generic[GEN_MAGICDRAINRATE];
		if ( Game->Counter[CR_MAGIC] >= cost )
		{
			Game->DCounter[CR_MAGIC] -= cost;
		}
		else Game->PlaySound(SFX_MAGIC_ERROR);
	}
}

int ItemMagicCosts[512];

void SetItemMagicCost(int itm, int cost){ ItemMagicCosts[itm] = cost;
	
void GetItemMagicCost(int itm){ return ItemMagicCosts[itm] * Game->Generic[GEN_MAGICDRAINRATE];
bool CanUseItem(int itm){ if ( GetItemMagicCost(itm) <= Game->Counter[CR_MAGIC] ) return true; return false; }
void DoMagicCost(int itm){ Game->DCounter[CR_MAGIC] =- GetItemMagicCost(itm); }
	
void ItemACost(){ 
	if ( Link->PressA ){
		if ( !CanUseItem(GetEquipmentA()) ) {
			Link->PressA = false;
			if ( SFX_MAGIC_ERROR > 0 ) Game->PlaySound(SFX_MAGIC_ERROR);
		}
		else DoMagicCost(GetEquipmentA());
	}
}

void ItemBCost(){ 
	if ( Link->PressB ){
		if ( !CanUseItem(GetEquipmentB()) ) {
			Link->PressB = false;
			if ( SFX_MAGIC_ERROR > 0 ) Game->PlaySound(SFX_MAGIC_ERROR);
		}
		else DoMagicCost(GetEquipmentB());
	}
}

void StaminaCosts(){
	ItemACost();
	ItemBCost();
}

global script Stamina{
	void run(){
		while(true){
			StaminaCosts();
			Waitdraw();
			Waitframe();
		}
	}
}

global script Init{
	void run(){
		SetItemMagicCost(5, 1);
	}
}
 
You can set a magic cost on all items in the item editor. If that is not sufficient, then you will need to wait for 2.54+ where you can set itemdata->MagicCost.
 
To give scripted items a magic cost, you do this:
const int SFX_MAGIC_ERROR = 0;

item script UseMagic{
    void run(int cost){
        cost = cost*Game->Generic[GEN_MAGICDRAINRATE];
        if ( Game->Counter[CR_MAGIC] >= cost )
        {
            Game->DCounter[CR_MAGIC] -= cost;
        }
        else Game->PlaySound(SFX_MAGIC_ERROR);
    }
}
This won't stop unscripted item effects from occurring. That is why I used a global script.

Edited by ZoriaRPG, 12 July 2017 - 04:44 AM.


#3 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 12 July 2017 - 10:10 AM

Hm, that might be a bit over my head for the moment. If it matters, this quest won't be using any scripted items. In fact, the only items that would use magic that don't normally are the hookshot, hammer, and boomerang. I have something different in mind for bombs and arrows, and obviously the candle and wand are good to go as is.

I probably should have said that first, but I'm not sure if it matters. I obviously don't know, but is it currently impossible to have an active item script subtract x magic, and if your magic is too low, have it not work? If not, I suppose it is a feature that can be omitted from this version of the project, and maybe added back in when 2.54 comes around.

As always, thanks for your time.

#4 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 12 July 2017 - 10:17 AM

An active item script happens when the item is already used. An active script can't disable usage of the item. Therefore, a global script is needed.


Edited by Avataro, 12 July 2017 - 10:17 AM.


#5 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 12 July 2017 - 11:28 AM

An active item script happens when the item is already used. An active script can't disable usage of the item. Therefore, a global script is needed.


Oh, okay. I forgot about them only running for one frame and all that. I'll check out Zoria's later then, I'm at work now.

#6 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 13 July 2017 - 05:31 AM

Oh, okay. I forgot about them only running for one frame and all that. I'll check out Zoria's later then, I'm at work now.


Just add those scripts into your buffer, imported before anything else. You can manually populate the item magic cost array, or use an Init script with a series of instructions to give each item a magic cost that you wish to have one. This only uses MP when Link presses a button to use an item. It does not do it on a timer system, so if you need that too, you will need to specify how you want it to work.

I did make a stamina system around the time that SS came out, if you ever wish to look at it. I also made an item rental system after the release of LBW. All of these are floating on the servers in my signature.

Edited by ZoriaRPG, 13 July 2017 - 05:54 AM.


#7 Anthus

Anthus

    Lord of Liquids

  • Members
  • Location:Ohio

Posted 13 July 2017 - 05:13 PM

I appreciate the help with this. Here's what I decided. Basically, I'm not going to be using this for my metroidvania entry, but I will be using it for the "DX" version which will hopefully exist at some point. I'm trying to keep designing this as simple as possible for now, in hopes that I actually finish it. :P

As far as bombs and arrows, if you're curious here's what I'm doing. It's probably also a good measure to make sure this is doable within the editor. So basically, Link starts with a max of 2 bombs and 2 arrows. Using a magic bomb bag and quiver, these will regenerate at around 5 seconds. Link will also be able to find expansions that increment this by 1, all the way to 10. So that's 8 upgrades each. These would also be bomb bags/ quivers that increase the max by 1. Is this possible without a script? Will picking up an "expansion bag/ quiver" overwrite the regenerative bags?


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users