Skip to content

NW_journal help (easy crafting system)

MorganZMorganZ Member Posts: 17
So i'm trying to figure out how this script should work.


What it does and how it works.

A player goes to a crafting station and puts items on it. The crafting station initiates a dialogue where the player selects what they want to craft. If they have placed enough fuel and material on the station and they pass the DC and dont roll a 1 they craft the item. If they fail the fuel is always consumed.

This goes on the crafting station's OnClose event. It's pretty standard but may be helpful to someone
void main()
{
    if ( GetFirstItemInInventory ( OBJECT_SELF ) == OBJECT_INVALID ) {
    SendMessageToPC ( GetLastUsedBy(), "Start by placing crafting materials on the station." ); }
    else
    ActionStartConversation ( GetLastUsedBy() );
}



This is the actual action script itself and is fired by the dialogue
//:: Created by: Baratan =======================================================
void main()
{
    // Define Variables
    object oPC = GetLastClosedBy(); // Player
    object oSelf = OBJECT_SELF; // Crafting Station

    string sCraft = GetLocalString ( OBJECT_SELF, "sCraft" ); // Get which craft from local variable
    string sFuel; // Tag of fuel item
    string sMat; // Tag of other material item
    string sItem; // Resref of item to craft

    int iSkill; // Which crafting skill being used
    int iRecipe = GetLocalInt( oPC, "NW_JOURNAL_ENTRY" + sCraft ); // Check PC journal for which recipe
    int nFuel; // Number of fuel items required
    int nMat; // Number of other material items required
    int nItem; // Number of items to craft
    int nStack; // Variable used when counting fuel and materials
    int nDC; // DC of crafting recipe

    // Special effect on success, I intend to replace this with an animation and sound effect appropriate to the activity being performed.
    effect eVFXRare = EffectVisualEffect( VFX_FNF_STRIKE_HOLY );
    
    // Define Recipes
    if ( iRecipe == 1 ) // [DC: 1] Bronze Arrow; 1 Bronze Ingot, 1 Coal Lump
    {
        iSkill = SKILL_CRAFT_WEAPON;
        nDC = 1;
        sMat = "BronzeIngot";
        nMat = 1;
        sFuel = "CoalLump";
        nFuel = 1;
        sItem = "bronzearrow";
        nItem = 99;
    }

    // Check for Fuel
    object oFuel = GetItemPossessedBy ( oSelf, sFuel );

    if ( oFuel == OBJECT_INVALID )
    {
        SendMessageToPC( oPC, "You need to place some fuel on the anvil." );
        return;
    }
    if ( GetItemStackSize( oFuel ) < nFuel )
    {
        SendMessageToPC( oPC, "You need more fuel!" );
        return;
    }

    // Check for Materials
    object oMat = GetItemPossessedBy ( oSelf, sMat );

    if ( oMat == OBJECT_INVALID )
    {
        SendMessageToPC( oPC, "You need to place materials on the anvil!" );
        return;
    }
    if ( GetItemStackSize( oMat ) < nMat )
    {
        SendMessageToPC( oPC, "You need more materials!" );
        return;
    }

    // Consume Fuel
    nStack = GetItemStackSize( oFuel );
    ApplyEffectToObject( DURATION_TYPE_INSTANT, eVFXRare, OBJECT_SELF );
    if ( nStack > nFuel )
    {
        SetItemStackSize( oFuel, nStack - nFuel );
    }
    else DestroyObject( oFuel );

    // Perform Skill Check
    int iRoll = d20(1);
    int iCheck = GetSkillRank ( iSkill, oPC, FALSE ) + iRoll;
    SendMessageToPC( oPC, "DC Check Roll: "+IntToString(iCheck)+" vs DC:"+IntToString(nDC) );
    if ( iRoll == 1 )
        {
        SendMessageToPC( oPC, "1 Rolled! Crafting Failed! Fuels consumed!" );
        return;
        }
    if ( nDC > iCheck )
        {
        SendMessageToPC( oPC, "Crafting Failed! Fuels consumed!" );
        return;
        }

    // Consume Materials
    nStack = GetItemStackSize( oMat );
    ApplyEffectToObject( DURATION_TYPE_INSTANT, eVFXRare, OBJECT_SELF );
    if ( nStack > nMat )
    {
        SetItemStackSize( oMat, nStack - nMat );
    }
    else DestroyObject( oMat );

    // Create Item
    SendMessageToPC( oPC, "Crafting Succeeded!" );
    CreateItemOnObject ( sItem, oSelf, nItem );
}


So as far as my (very low) knowledge let me understand: i need to create some kind of "recipes" in the pc journal. How does it works? Could someone help me scripting a sample and understanding where to place it?


Thanks for reading :)

Comments

  • ForSeriousForSerious Member Posts: 446
    Looks to me like they started it, but only made the one recipe for bronze arrow.
    So this script is dependent on another script (somewhere) that calls SetLocalInt(oPC, "NW_JOURNAL_ENTRY" + sCraft, <some int>); Maybe fired in the conversation? Makes sense:
    What will you craft?
    1. Arrow
    2. Bullet
    3. Dire Mace +20
    Then a script fires when you pick an option setting that int.

    This script will get big really fast if you actually start adding recipes. I would recommend changing it so that, in an include script, it sets
    int iSkill; // Which crafting skill being used
    int nFuel; // Number of fuel items required
    int nMat; // Number of other material items required
    int nItem; // Number of items to craft
    int nStack; // Variable used when counting fuel and materials
    int nDC; // DC of crafting recipe
    into local variables. So this include script would have one function called void PopulateRecipes(int iIndex);
    And well, I would call that function on the conversation option...
    Let me know if you like that idea and I can throw together an example for you.
  • MorganZMorganZ Member Posts: 17
    Sounds good to me! So basically we will use an ##include script in the carfting table conversation which will work for every kind of crafting table depenending on the variables we will place in the crafting table itself?

    Thank you!
  • ForSeriousForSerious Member Posts: 446
    Here's a incomplete example. I explain why in the read me.
  • ForSeriousForSerious Member Posts: 446
    edited June 2021
    Heh, it posted but popped up a little message that I'm not allowed to upload files in this category. Anyway, I sent you a PM.
Sign In or Register to comment.