BioWare Forums: View Post For Code Display


You are viewing a single post. Please do not take this post out of context.
Read the full topic: Post Working Scripts Here

Author Sticky: Post Working Scripts Here
Milamber-POL Posted: Tuesday, 23 July 08:35PM
Here is the code that I put together for the Blacksmith who makes items for the PC. I grew frustrated with trying to mod the script that Marrok used in the Single Player Module in Chapter 1 so I started working on my own. Again I apologize for the script being somewhat combersome, I am not fluent in C (They only taught us how to program in FORTRAN back when I was in college). I don't know the syntax of things that might make this more fluid, but perhaps a C person can help out. The script here works for two items, but I have expanded it to over 30 in my module without errors.

In the smiths "OnConversation" event put the following script at the end of the default, I don't know if you need the default, but I was not about to mess with it yet.

NWScript:
///////////////////////////////
// Smith Item Creation Script 
// By Milamber-POL
// Dated 7/22/02
// OnConversation (Smith)
//////////////////////////////
    SetLocalString(OBJECT_SELF,"NW_L_MYFORGE","M1Q1CForge");
    object oContainer = GetObjectByTag(GetLocalString(OBJECT_SELF,"NW_L_MYFORGE"));
//  Get the two items off the forge.
//  Might want to verify that there are at least two items
//  and not more than two (ADD at a later date)
    object oItem1 =  GetFirstItemInInventory(oContainer);
    object oItem2 =  GetNextItemInInventory(oContainer);
    string sReagent1;
    string sReagent2;
//  Make it so that at least one of the two items is a "component"
//  In otherwords it is of the GEM or MISC base type.
//  For convienience we will always make sReagent1 the component
//  sReagent2 can be whatever else we want, just reference by TAG
{
    int nBaseType = GetBaseItemType(oItem1);
    if  (
        (nBaseType == BASE_ITEM_GEM)    ||
        (nBaseType == BASE_ITEM_MISCLARGE) ||  (nBaseType == BASE_ITEM_MISCMEDIUM) ||
        (nBaseType == BASE_ITEM_MISCTALL) ||  (nBaseType == BASE_ITEM_MISCSMALL)  ||
        (nBaseType == BASE_ITEM_MISCTHIN)
        )
      {
      sReagent1 = GetTag(oItem1);
      sReagent2 = GetTag(oItem2);
      }
    else
      {
      sReagent1 = GetTag(oItem2);
      sReagent2 = GetTag(oItem1);
      }
}
// Check for a Valid Combo of items on the forge and assign a Number to the combo
// The number will be used in the conversation with the smith to identify which item
// he can make.  Downfall here is the item recipe here must match the one in the creation
// file, there must be a better way to do this.
 {
    // Item #1 Burning Blade Long Sword with +2 Fire Damage
    // Requires non-unique Longsword (i.e. non-magical or +1, +2, or +3)
    // Requires Fire Opal
    // Costs 500 gold
    if (
       ((sReagent1 == "NW_IT_GEM009") && (sReagent2 == "NW_WSWLS001"))  ||
       ((sReagent1 == "NW_IT_GEM009") && (sReagent2 == "NW_WSWMLS002"))  ||
       ((sReagent1 == "NW_IT_GEM009") && (sReagent2 == "NW_WSWMLS010"))  ||
       ((sReagent1 == "NW_IT_GEM009") && (sReagent2 == "NW_WSWMLS012"))
       )
    {
        SetLocalInt(OBJECT_SELF, "VALID_COMBO", TRUE);
        SetLocalString(OBJECT_SELF, "REAGENT_1", sReagent1);
        SetLocalString(OBJECT_SELF, "REAGENT_2", sReagent2);
        SetLocalString(OBJECT_SELF, "REWARD", "BURNBLADE_LS");  // Custom Item I made
        SetLocalInt(OBJECT_SELF, "ITEM_COST", 500);
        SetLocalInt(OBJECT_SELF, "ORDER_UP", 1);
    }
    else if  ((sReagent1 == "NW_IT_GEM009") && (sReagent2 == "BURNBLADE_LS"))
    {
        SetLocalInt(OBJECT_SELF, "VALID_COMBO", TRUE);
        SetLocalString(OBJECT_SELF, "REAGENT_1", sReagent1);
        SetLocalString(OBJECT_SELF, "REAGENT_2", sReagent2);
        SetLocalString(OBJECT_SELF, "REWARD", "NW_WSWMLS005");
        SetLocalInt(OBJECT_SELF, "ITEM_COST", 1000);
        SetLocalInt(OBJECT_SELF, "ORDER_UP", 2);
    }
    else
    {
        SetLocalInt(OBJECT_SELF, "VALID_COMBO", FALSE);
    }
 }
    SetCustomToken(5575, IntToString(GetLocalInt(OBJECT_SELF, "ITEM_COST")));
}



Now put the following in the conversation with the smith whenever he has agreed to make the item. I have included a few checks at the end of this post that verify the PC can pay for the item, and that a valid combo exists on the forge.

NWScript:
///////////////////////////////
// Smith Item Creation Script 
// By Milamber-POL
// Dated 7/22/02
//
//////////////////////////////
//:://////////////////////////
//:: FileName MakeItBrother
//:://////////////////////////
void create_item()
{
    SetLocalString(OBJECT_SELF,"NW_L_MYFORGE","M1Q1CForge");
    object oContainer = GetObjectByTag(GetLocalString(OBJECT_SELF,"NW_L_MYFORGE"));
/* 
 * The following actions are performed for each item creation, it would be easy to
 * make custom visual effects for each item type, by moving these back into the
 * main portion of the code in the logical block.   For simplicity I left them here.
*/
    DestroyObject(GetItemPossessedBy(oContainer,GetLocalString(OBJECT_SELF, "REAGENT_1")));
    DestroyObject(GetItemPossessedBy(oContainer,GetLocalString(OBJECT_SELF, "REAGENT_2")));
    CreateItemOnObject(GetLocalString(OBJECT_SELF, "REWARD") ,oContainer);
    TakeGoldFromCreature(GetLocalInt(OBJECT_SELF, "ITEM_COST"), GetPCSpeaker(), TRUE);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_MAGICAL_VISION), OBJECT_SELF);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_AC_BONUS),oContainer);
}

void main()
{
   // Combo Requires Magic Sword and Fire Opal == Burning Blade
   // Cost == 500 gp
   // Need to add a script that checks to make sure the PC has the gold
   if((GetLocalInt(OBJECT_SELF, "ORDER_UP") == 1))
   {
        create_item();
   }
   // Combo Requires Burning Blade (See Above) and a Fire Opal == Flame Tounge
   // Cost == 1000 gp
   // Need to add a script that checks to make sure the PC has the gold
   else if((GetLocalInt(OBJECT_SELF, "ORDER_UP") == 2))
   {
        create_item();
   }
   // Not really sure what should happen if the right items are not
   // present, possibly a random chance the smith destroys one???
   else
   {
    // left blank for the moment
   }
}


A couple of other scripts to include in the conversation are conditional checks for the combo being valid (i.e. Listed in the OnConversation event script)

NWScript:
int StartingConditional()
{
    // Inspect local variables
    if((GetLocalInt(OBJECT_SELF, "ORDER_UP") == 1))
        return TRUE;
    else
        return FALSE;
}


And one for making sure the PC can pay for the item


NWScript:
int StartingConditional()
{
    int iResult;
    iResult =GetGold(GetPCSpeaker()) >= GetLocalInt(OBJECT_SELF, "ITEM_COST");
    return iResult;
}


One more note, I made a custom item called the burning blade to test and make sure custom items work with the creation, so you will need to change that or make an item with that name before you drop and go with the script. I know this script can be improved on, but for now it works.

Milamber-POL
Paladins of Light
www.pofl.org

This post taken from the BioWare Forums
Powered by BioBoards Version 2.05.010
Please read our Copyright and Trademark Information