Author Topic: Looping Variable System Help  (Read 535 times)

Legacy_SokataKlasa

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Looping Variable System Help
« on: February 20, 2016, 04:19:38 pm »


               

Hello there, I'm posting here because I'm running into issues with a looping variable system I designed for a custom magic system. It was working fine until the point where I decided to make it more complex and changed the number of variables the system was keeping track of from 1 to 4.


 


MP would go up an amount every round and was used for most custom script spells.


TP would only go up during combat every round and would be reset to 0 if not in combat. It was used for the more advanced spells.


LP is a counter that would go up each time a spell was used. It would also reset to 0 once combat ended.


And AL was used for the specific spell Auto-Life, which actually works not how it sounds. That spell simply tags the player as Immortal and then fires when they're at 1 hp.


 


Anywho, those are the variables and the functions they are supposed to follow. However, when I updated the script to include them all it suddenly decided to break, and I can't understand why. Here is the script that hopefully someone better at scripting than I can discover my mistakes and explain them to me.



#include "nw_i0_spells"
#include "x0_i0_spells"

object oPC = GetItemActivator();
object oItem = GetItemActivated();
int iLevel = GetHitDice(oPC);
int iIntel = GetAbilityModifier(ABILITY_INTELLIGENCE , oPC);
int iMP = (10 + iLevel + iIntel) * 2;
int cMP;
string MP;
int tMP;
int cTP;
string TP;
int cLP;
string LP;
string AL;
effect eTime = EffectTimeStop();
effect eVis1 = EffectVisualEffect(VFX_FNF_NATURES_BALANCE);
effect eVis2 = EffectVisualEffect(VFX_FNF_TIME_STOP);


void mana()
{
    if (GetCurrentHitPoints(oPC) > 1)
{
    if (GetLocalInt(oItem, AL) == 3)
    {
    SendMessageToPC(oPC, "Autolife: Delta");
    }
    if (GetLocalInt(oItem, AL) == 2)
    {
    SendMessageToPC(oPC, "Autolife: Beta");
    }
    if (GetLocalInt(oItem, AL) == 1)
    {
    SendMessageToPC(oPC, "Autolife: Alpha");
    }

}

if (GetCurrentHitPoints(oPC) == 1)
{
    if (GetLocalInt(oItem, AL) == 3)
    {
    SendMessageToPC(oPC, "Autolife: Delta");
    SetLocalInt(oItem, MP, iMP);
    ExecuteScript("healtime",oPC);
    ExecuteScript("shield",oPC);
    ExecuteScript("reflect",oPC);
    SetLocalInt(oItem, AL, 0);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis1, oPC);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis2, oPC);
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eTime, oPC, 30.0);
    DelayCommand(7.0, SetImmortal(oPC, FALSE));
    }
    if (GetLocalInt(oItem, AL) == 2)
    {
    SendMessageToPC(oPC, "Autolife: Beta");
    SetLocalInt(oItem, MP, iMP);
    ExecuteScript("healtime",oPC);
    ExecuteScript("shield",oPC);
    ExecuteScript("reflect",oPC);
    SetLocalInt(oItem, AL, 0);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis1, oPC);
    DelayCommand(7.0, SetImmortal(oPC, FALSE));
    }
    if (GetLocalInt(oItem, AL) == 1)
    {
    SendMessageToPC(oPC, "Autolife: Alpha");
    ExecuteScript("healtime",oPC);
    SetLocalInt(oItem, AL, 0);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis1, oPC);
    DelayCommand(7.0, SetImmortal(oPC, FALSE));
    }

}
    if (GetIsInCombat(oPC) == TRUE)
    {
     cTP = GetLocalInt(oItem, TP) + 1;
    SendMessageToPC(oPC, "TP: " + IntToString(cTP));
    DelayCommand(1.0, SetLocalInt(oItem, TP, cTP));
        if (GetLocalInt(oItem, LP) > 8)
        {
        SendMessageToPC(oPC, "Delta");
        }
        else if (GetLocalInt(oItem, LP) > 4 && GetLocalInt(oItem, LP) < 9)
        {
        SendMessageToPC(oPC, "Beta");
        }
        else if (GetLocalInt(oItem, LP) < 5)
        {
        SendMessageToPC(oPC, "Alpha");
        }
    }

    if (GetIsInCombat(oPC) == FALSE)
    {
     SendMessageToPC(oPC, "Time Out");
     SetLocalInt(oItem, TP, 0);
     SetLocalInt(oItem, LP, 0);
    }

   // if (tMP == 3)
   // {
   //  SendMessageToPC(oPC, "Mana System Deactivated");
   // }
    if (GetLocalInt(oItem, MP) < 1)
    {
    SetLocalInt(oItem, MP, 1);
    SendMessageToPC(oPC, "Mana System Initiated");
    DelayCommand(6.0, mana());
    }
    else if (GetLocalInt(oItem, MP) == iMP)
    {
    SendMessageToPC(oPC, "Mana at full capacity");
    tMP++;
    DelayCommand(6.0, mana());
    }
    else if (GetLocalInt(oItem, MP) > 0)
    {
    cMP = GetLocalInt(oItem, MP) + 3;
    SendMessageToPC(oPC, "MP: " + IntToString(cMP));
    DelayCommand(1.0, SetLocalInt(oItem, MP, cMP));
    DelayCommand(6.0, mana());
    }
}

void main()
{   int tMP = 0;
    SetLocalInt(oItem, TP, 0);
    SetLocalInt(oItem, LP, 0);
    mana();
}



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Looping Variable System Help
« Reply #1 on: February 20, 2016, 06:14:53 pm »


               

You need to define the strings you are using for the variables names. For example you have string AL; and GetLocalInt(oItem, AL); but AL is never given a value so you are saying GetLocalInt(oItem, "");   where "" is an empty string. I suspect that always returns 0. Something like string AL = "AL";  for all the local variable names you are using.


 


Here is a version that does that. I cleaned it up a bit to use local variables instead of the same GetLocalInt over and over again but otherwise tried not to change the code style too much from what you had so you can see.  It compiles. I have not tested it further than that. I also removed the int tMP =0; from main since it did nothing.



#include "nw_i0_spells"
#include "x0_i0_spells"

object oPC = GetItemActivator();
object oItem = GetItemActivated();
int iLevel = GetHitDice(oPC);
int iIntel = GetAbilityModifier(ABILITY_INTELLIGENCE , oPC);
int iMP = (10 + iLevel + iIntel) * 2;
int cMP;
int tMP = 0;
string MP = "MP";
int cTP;
string TP = "TP";
int cLP;
string LP = "LP";
string AL = "AL";
effect eTime = EffectTimeStop();
effect eVis1 = EffectVisualEffect(VFX_FNF_NATURES_BALANCE);
effect eVis2 = EffectVisualEffect(VFX_FNF_TIME_STOP);


void mana()
{
   int nCurrentHP = GetCurrentHitPoints(oPC);
   int nAL = GetLocalInt(oItem, AL);

   if (nCurrentHP > 1)
   {
       if (nAL == 3)
       {
          SendMessageToPC(oPC, "Autolife: Delta");
       }
       else if (nAL == 2)
       {
          SendMessageToPC(oPC, "Autolife: Beta");
       }
       else if (nAL == 1)
       {
          SendMessageToPC(oPC, "Autolife: Alpha");
       }
   }
   
   else if (nCurrentHP == 1)
   {
      if (nAL == 3)
      {
         SendMessageToPC(oPC, "Autolife: Delta");
         SetLocalInt(oItem, MP, iMP);
         ExecuteScript("healtime",oPC);
         ExecuteScript("shield",oPC);
         ExecuteScript("reflect",oPC);
         SetLocalInt(oItem, AL, 0);
         ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis1, oPC);
         ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis2, oPC);
         ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eTime, oPC, 30.0);
         DelayCommand(7.0, SetImmortal(oPC, FALSE));
      }
      else if (nAL == 2)
      {
         SendMessageToPC(oPC, "Autolife: Beta");
         SetLocalInt(oItem, MP, iMP);
         ExecuteScript("healtime",oPC);
         ExecuteScript("shield",oPC);
         ExecuteScript("reflect",oPC);
         SetLocalInt(oItem, AL, 0);
         ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis1, oPC);
         DelayCommand(7.0, SetImmortal(oPC, FALSE));
      }
      if (GetLocalInt(oItem, AL) == 1)
      {
         SendMessageToPC(oPC, "Autolife: Alpha");
         ExecuteScript("healtime",oPC);
         SetLocalInt(oItem, AL, 0);
         ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis1, oPC);
         DelayCommand(7.0, SetImmortal(oPC, FALSE));
      }
      
   }
   if (GetIsInCombat(oPC))
   {
      cTP = GetLocalInt(oItem, TP) + 1;
      SendMessageToPC(oPC, "TP: " + IntToString(cTP));
      DelayCommand(1.0, SetLocalInt(oItem, TP, cTP));
      int nLP = GetLocalInt(oItem, LP);
      if (nLP > 8)
      {
         SendMessageToPC(oPC, "Delta");
      }
      else if (nLP > 4 && nLP < 9)
      {
         SendMessageToPC(oPC, "Beta");
      }
      else if (nLP < 5)
      {
         SendMessageToPC(oPC, "Alpha");
      }
   } else {
      SendMessageToPC(oPC, "Time Out");
      SetLocalInt(oItem, TP, 0);
      SetLocalInt(oItem, LP, 0);
   }

   // if (tMP == 3)
   // {
   //  SendMessageToPC(oPC, "Mana System Deactivated");
   // }

   int nMP = GetLocalInt(oItem, MP);
   if (nMP < 1)
   {
      SetLocalInt(oItem, MP, 1);
      SendMessageToPC(oPC, "Mana System Initiated");
      DelayCommand(6.0, mana());
   }
   else if (nMP == iMP)
   {
      SendMessageToPC(oPC, "Mana at full capacity");
      tMP++;
      DelayCommand(6.0, mana());
   }
   else if (nMP > 0)
   {
      cMP = nMP + 3;
      SendMessageToPC(oPC, "MP: " + IntToString(cMP));
      DelayCommand(1.0, SetLocalInt(oItem, MP, cMP));
      DelayCommand(6.0, mana());
   }
}

void main()
{  
   SetLocalInt(oItem, TP, 0);
   SetLocalInt(oItem, LP, 0);
   mana();
}


               
               

               
            

Legacy_SokataKlasa

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Looping Variable System Help
« Reply #2 on: February 20, 2016, 09:40:12 pm »


               

That fixed it, thank you. I knew it would be because of some simple mistake I didn't realize, like not knowing that just declaring the strings wasn't enough. Thank you.