Author Topic: Help with "while" script please  (Read 311 times)

Legacy_bdtgazo

  • Jr. Member
  • **
  • Posts: 98
  • Karma: +0/-0
Help with "while" script please
« on: September 29, 2015, 02:43:09 am »


               


void main()
{

object oForge = OBJECT_SELF;
object oStorage = GetNearestObjectByTag("Forge_Date_Bank");
object oSlag = GetNearestObjectByTag("Slag_Gatherer");
object oPC = GetLastClosedBy();

int nCraft = GetLocalInt(oPC,"nCraft");
// This function counts up the total number of items in the first PC's inventory.  (The number of items in a stackable count toward the total)
int nItems = 0;
object oItem = GetFirstItemInInventory(oForge);
//string sRes = GetResRef(oItem);

while (GetIsObjectValid(oItem) == TRUE)
//if (sRes == "cold_iron_ore001")
    {
        //int nCraft = GetLocalInt(oStorage,"nCraft");
        //if (nCraft = 0)
           // {
            //SpeakString("You have started a Dark Iron recipe.  You need 5 more Dark Iron Ores to craft an item.");
            //SetLocalInt(oStorage,"nCraft",1);
            if (GetResRef(oItem)=="cold_iron_ore001")
                {
                    if (nCraft = 0)
                        {
                        SpeakString("You have started a Dark Iron recipe.  You need 5 more Dark Iron Ores to craft an item.");
                        SetLocalInt(oPC,"nCraft",1);
                        DestroyObject(oItem);
                        }
                    else if ((nCraft > 0) && (nCraft < 5))
                        {
                         int nRemainder = (5 - nCraft +1);
                         SpeakString("You have started a Dark Iron recipe.  You need " + IntToString(nRemainder) + "more Dark Iron Ores to craft an item.");
                         //SendMessageToPC(oMember, "Worgs left to kill: " + IntToString(nWorg2));
                         nCraft += 1;
                         SetLocalInt(oPC, "nCraft", nCraft);
                         DestroyObject(oItem);
                        }
                    else if (nCraft = 5)
                        {
                         //int nRemainder = (5 - nCraft +1);
                         SpeakString("You have finished a Dark Iron recipe.  You may collect the slag from the .");//need to name
                         //SendMessageToPC(oMember, "Worgs left to kill: " + IntToString(nWorg2));
                         SetLocalInt(oPC,"nCraft",80);
                         DestroyObject(oItem);
                         CreateItemOnObject("slag_dark", oSlag);
                        }
                    else if (nCraft > 5)
                        {
                         //int nRemainder = (5 - nCraft +1);
                         SpeakString("You have wasted some ore!");
                         //SendMessageToPC(oMember, "Worgs left to kill: " + IntToString(nWorg2));
                         //nCraft += 1;
                         DestroyObject(oItem);
                         }
                }  // end If cold_iron_ore001 (Dark Iron)

              else if (GetResRef(oItem)!="cold_iron_ore001")
                {
                    DestroyObject(oItem);
                }
               oItem = GetNextItemInInventory(oForge);
    } //end While Valid Object

//while (GetIsObjectValid(oItem) == TRUE)
   //{
     // nItems = nItems + GetNumStackedItems(oItem);

     // oItem = GetNextItemInInventory(GetFirstPC());
   //}


} //END OF VOID MAIN

Hi!


 


I'm currently reworking my forge system - I want to try using strings and parses for item upgrades - and I'm running into a problem on a script.  The following script almost works, but it is creating "slag_dark" after placing just 1 'cold_iron_ore' into the cauldron.


 


I'm trying to fix it so that the PC must place 5 ores into the cauldron, either all at once, or consecutively, before the bucket of slag is created (on another placeable). 


 


I tried to design the script to leave open the possibility for other ore types to be used in the cauldron (although I'm leaning towards a cauldron type for each type of ore). 


 


Anyways, 1 ore is creating 1 bucket of slag... I want 5 ores to be eaten before creating the bucket of slag.  I'm wondering if its just a delay that is required...  .  If anyone can fix this, please have a go.


 


Sorry script is above my request...


               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Help with "while" script please
« Reply #1 on: September 29, 2015, 03:41:36 am »


               

"nCraft = 0"  is an assignment statement. "nCraft == 0" is a comparison.  In this code you want to use comparisons in your if statements.  What's happening is you are setting nCraft to 0 in the first if, which itself evaluates to FALSE so does not fire. Because nCraft is 0 the inequality else if does not fire. Then later you are setting nCraft = 5 in the else if which evaluates to TRUE so you are executing that code as if there were 5 ores already. Try using the double == in both of those places.


               
               

               
            

Legacy_bdtgazo

  • Jr. Member
  • **
  • Posts: 98
  • Karma: +0/-0
Help with "while" script please
« Reply #2 on: September 29, 2015, 05:09:09 pm »


               

Okay, I'll give it a go.  Thanks meaglyn (I was crossing my fingers that you would be the one who responded '<img'> ).


 


Works as intended now!  Thanks!  Also fixed my math mistakes, lol.


 


Second script working too.  Now I delve into parsing strings for the first time.  Wish me luck.



               
               

               
            

Legacy_bdtgazo

  • Jr. Member
  • **
  • Posts: 98
  • Karma: +0/-0
Help with "while" script please
« Reply #3 on: October 21, 2015, 04:30:19 pm »


               

Forgot to update this.


 


If you have a gemming system for your mod, that allows gems to be set into weapons to upgrade them, you can use parsing to avoid having to set variables on all of your items.  The system I use just uses name changes to the weapon (like 'Crafted Dark Iron Greatsword' becomes 'Enchanted Dark Iron Greatsword') and parsing to determine if another gem can be added to the weapon.  If the weapon is at what you deem the limit for upgrades ('Uber Dark Iron Greatsword'), the PC cannot add any more gems to the item.


 


I use a forge and some other placeables, but this should be easy to switch to an onAcitivate script.


 


Thanks again Meaglyn.