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.