1. SPS Accounts:
    Do you find yourself coming back time after time? Do you appreciate the ongoing hard work to keep this community focused and successful in its mission? Please consider supporting us by upgrading to an SPS Account. Besides the warm and fuzzy feeling that comes from supporting a good cause, you'll also get a significant number of ever-expanding perks and benefits on the site and the forums. Click here to find out more.
    Dismiss Notice
Dismiss Notice
You are currently viewing Boards o' Magick as a guest, but you can register an account here. Registration is fast, easy and free. Once registered you will have access to search the forums, create and respond to threads, PM other members, upload screenshots and access many other features unavailable to guests.

BoM cultivates a friendly and welcoming atmosphere. We have been aiming for quality over quantity with our forums from their inception, and believe that this distinction is truly tangible and valued by our members. We'd love to have you join us today!

(If you have any problems with the registration process or your account login, please contact us. If you've forgotten your username or password, click here.)

Scripting Help - Hidden Holes

Discussion in 'Neverwinter Nights (Classic)' started by Rotku, Jul 10, 2005.

  1. Rotku

    Rotku I believe I can fly Veteran Pillars of Eternity SP Immortalizer (for helping immortalize Sorcerer's Place in the game!) New Server Contributor [2012] (for helping Sorcerer's Place lease a new, more powerful server!)

    Joined:
    Apr 13, 2003
    Messages:
    3,105
    Likes Received:
    35
    Okay. I've been working on a script (NB: I'm terrible at scripting! NWVault and script generators keep me alive, so making my own scripts is something new!) which well...

    A Persistant Storage script is used along with the Placeable hole, to allow PCs to store items.

    That's atleast what it's meant to do. It works as far as despawning the hole. When the hole is despawned, all the items are thrown out of the hole and left upon the ground, like if you smash a chest or something like that.

    What I need, if anyone knows how, is a way to either:
    • (1) Port the hole to a DM Area, and port it back, instead of spawning and destroying it. Or,
    • (2) Have another pChest in a DM Area where the items are saved to once the hole is closed, then the items are removed from the hole until it is opened. This way when it is destoried there'll be no inventory.
    Anyhelp would be greatly appriciated!


    Below are the scripts that I am using with this system.

    Trigger Scripts

    OnEnter:
    Code:
    void main()
    {
    
    object oPC = GetEnteringObject();
    
    if (!GetIsPC(oPC)) return;
    
    // This is what you want the DC to be,
        // just replace the 15 with what ever you want as the DC
    int nDC = 15;
    
        // get the skill bonus and assign it to nSkill
    int nSkill = GetSkillRank(SKILL_SPOT, oPC);
    
    // Checks if the PC has already found the hole before.
    if (GetLocalInt(oPC, "006_holefound1a")== 1) //Change this to the tage of the hole, with an 'a' at the end
       {
            //Get the Waypoint where the hole will spawn
       oTarget = GetWaypointByTag("WP_hole1");//This is the WP where the hole will spawn.  Change as needed.
    
       lTarget = GetLocation(oTarget);
             //Spawn the Hole at the WP
       CreateObject(OBJECT_TYPE_PLACEABLE, "006_hole1", lTarget); //This is the resref of the hole
          }
    
    
    //If they haven't, preform a skill check to see if they find the hole.
    //If the skill check is successful, follow the same as above, apart from where otherwise noted.
    else if((d20() + nSkill) >= nDC)
       {
         //Set a local variable so in future you don't have to search for the hole to find it.
       SetLocalInt(oPC, "006_holefound1a", 1);  //Change this to the tag of the hole Placeable, with an 'a' at the end
    
       oTarget = GetWaypointByTag("WP_hole1"); //This is the WP Tag, change it to the WP where you want the hole to spawn
    
       lTarget = GetLocation(oTarget);
    
       CreateObject(OBJECT_TYPE_PLACEABLE, "006_hole1", lTarget);
    //this it the hole Tag.  Change it to represent the placeable you want to spawn
    
       }
    }
    OnExit
    Code:
    void main()
    {
    
    object oPC = GetExitingObject();
    
    if (!GetIsPC(oPC)) return;
    
    object oTarget;
    oTarget = GetObjectByTag("006_hole1");
    
    DestroyObject(oTarget, 0.0);
    
    }
    Persistant Storage Scripts

    ngps_inc
    Code:
    // This script "ngps_inc" contains all of the storage handling logic.
    
    // void main(){}
    
    void ngpsInit(object oBox)
    {
        if (GetLocalInt(oBox, "ngps_loaded") < 1)
        {
            SetLocalInt(oBox, "ngps_loaded", 1);
            string sFile = "ngps_" + GetTag(GetArea(oBox)) + "_" + GetTag(oBox);
            int iSize = GetCampaignInt(sFile, "size");
            SetLocalInt(oBox, "ngps_size", iSize);
            location lLoc = GetLocation(oBox);
            int iIndex = 1;
            while (iIndex <= iSize)
            {
                RetrieveCampaignObject(sFile, "item" + IntToString(iIndex), lLoc, oBox);
                iIndex++;
            }
            object oItem = GetFirstItemInInventory(oBox);
            while (oItem != OBJECT_INVALID)
            {
                SetItemStackSize(oItem, GetLocalInt(oItem, "ngps_stack"));
                DeleteLocalInt(oItem, "ngps_stack");
                oItem = GetNextItemInInventory(oBox);
            }
            int iGold = GetCampaignInt(sFile, "gold");
            while (iGold > 50000)
            {
                CreateItemOnObject("nw_it_gold001", oBox, 50000);
                iGold -= 50000;
            }
            CreateItemOnObject("nw_it_gold001", oBox, iGold);
        }
    }
    
    void ngpsSaveGold(object oBox)
    {
        string sFile = "ngps_" + GetTag(GetArea(oBox)) + "_" + GetTag(oBox);
        int iGold = 0;
        object oItem = GetFirstItemInInventory(oBox);
        while (oItem != OBJECT_INVALID)
        {
            if (GetResRef(oItem) == "nw_it_gold001")
                iGold += GetItemStackSize(oItem);
            oItem = GetNextItemInInventory(oBox);
        }
        if ((iGold < 1) && (GetLocalInt(oBox, "ngps_size") < 1))
            DestroyCampaignDatabase(sFile);
        else
            SetCampaignInt(sFile, "gold", iGold);
    }
    
    void ngpsUpdate(object oBox, object oItem)
    {
        if ((GetResRef(oItem) != "nw_it_gold001") && (GetResRef(oItem) != ""))
        {
            string sFile = "ngps_" + GetTag(GetArea(oBox)) + "_" + GetTag(oBox);
            int iIndex = GetLocalInt(oItem, "ngps_index");
            SetLocalInt(oItem, "ngps_stack", GetItemStackSize(oItem));
            SetItemStackSize(oItem, 999999);
            StoreCampaignObject(sFile, "item" + IntToString(iIndex), oItem);
            SetItemStackSize(oItem, GetLocalInt(oItem, "ngps_stack"));
            DeleteLocalInt(oItem, "ngps_stack");
        }
    }
    
    void ngpsAdd(object oBox, object oItem)
    {
        if ((GetResRef(oItem) != "nw_it_gold001") && (GetResRef(oItem) != ""))
        {
            string sFile = "ngps_" + GetTag(GetArea(oBox)) + "_" + GetTag(oBox);
            int iSize = GetLocalInt(oBox, "ngps_size");
            iSize++;
            SetLocalInt(oItem, "ngps_index", iSize);
            ngpsUpdate(oBox, oItem);
            SetLocalInt(oBox, "ngps_size", iSize);
            SetCampaignInt(sFile, "size", iSize);
        }
    }
    
    void ngpsDelete(object oBox, object oItem)
    {
        if ((GetResRef(oItem) != "nw_it_gold001") && (GetResRef(oItem) != ""))
        {
            string sFile = "ngps_" + GetTag(GetArea(oBox)) + "_" + GetTag(oBox);
            int iSize = GetLocalInt(oBox, "ngps_size");
            int iIndex = GetLocalInt(oItem, "ngps_index");
    // Bioware bug get-around (begin)
    // The bug is that items loaded from a campaign database to
    // a container lose their local variables when removed.
            if (iIndex < 1)
            {
                while (iIndex <= iSize)
                {
                    iIndex++;
                    object oLastItem = GetFirstItemInInventory(oBox);
                    while (oLastItem != OBJECT_INVALID)
                    {
                        if (GetLocalInt(oLastItem, "ngps_index") == iIndex)
                            break;
                        oLastItem = GetNextItemInInventory(oBox);
                    }
                    if (oLastItem == OBJECT_INVALID)
                        break;
                }
            }
    // Bioware bug get-around (end)
            if (iIndex < iSize)
            {
                object oLastItem = GetFirstItemInInventory(oBox);
                while (oLastItem != OBJECT_INVALID)
                {
                    if (GetLocalInt(oLastItem, "ngps_index") == iSize)
                        break;
                    oLastItem = GetNextItemInInventory(oBox);
                }
                SetLocalInt(oLastItem, "ngps_index", iIndex);
                ngpsUpdate(oBox, oLastItem);
            }
            iSize--;
            if ((iSize < 1) && (GetCampaignInt(sFile, "gold") < 1))
            {
                SetLocalInt(oBox, "ngps_size", 0);
                DestroyCampaignDatabase(sFile);
            }
            else
            {
                SetLocalInt(oBox, "ngps_size", iSize);
                SetCampaignInt(sFile, "size", iSize);
            }
            DeleteLocalInt(oItem, "ngps_index");
        }
    }
    OnOpen
    Code:
    // This script "ngps_onopen" is called by a persistent container's
    // onopen event. Persistent containers require a tag unique to the
    // area.
    
    #include "ngps_inc"
    
    void main()
    {
        ngpsInit(OBJECT_SELF);
    }
    OnClose
    Code:
    // This script "ngps_onclose" is called by a persistent container's
    // onclose event. Persistent containers require a tag unique to the
    // area.
    
    #include "ngps_inc"
    
    void main()
    {
        ngpsSaveGold(OBJECT_SELF);
    }
    OnDeath
    Code:
    // This script "ngps_ondeath" is called by a persistent container's
    // ondeath event. Persistent containers require a tag unique to the
    // area.
    
    void main()
    {
        string sFile = "ngps_" + GetTag(GetArea(OBJECT_SELF)) + "_" + GetTag(OBJECT_SELF);
        DestroyCampaignDatabase(sFile);
    }
    OnDisturbed
    Code:
    // This script "ngps_ondisturbed" is called by a persistent container's
    // ondistrubed event. Persistent containers require a tag unique to the
    // area.
    
    #include "ngps_inc"
    
    void main()
    {
        object oPC = GetLastDisturbed();
        if (GetIsPC(oPC) || GetIsDM(oPC) || GetIsDMPossessed(oPC))
        {
            object oItem = GetInventoryDisturbItem();
            if (GetInventoryDisturbType() == INVENTORY_DISTURB_TYPE_ADDED)
                ngpsAdd(OBJECT_SELF, oItem);
            else
                ngpsDelete(OBJECT_SELF, oItem);
        }
    }
    [ July 10, 2005, 18:29: Message edited by: Blackthorne TA ]
     
    Last edited by a moderator: Dec 29, 2017
  2. Taza

    Taza Weird Modmaker Veteran

    Joined:
    Oct 23, 2002
    Messages:
    1,447
    Likes Received:
    25
    Those scripts seem invalid for the purpose.

    I think the DestroyCampaignDatabase() should SERIOUSLY not be there!

    I'll look more into it when I've digged up my scripting tools though.

    EDIT: Now I've finished studying it, and I need to ask for what purpose this script is needed for. The script overall isn't too smart though.

    [ July 10, 2005, 12:55: Message edited by: Taza ]
     
  3. Rotku

    Rotku I believe I can fly Veteran Pillars of Eternity SP Immortalizer (for helping immortalize Sorcerer's Place in the game!) New Server Contributor [2012] (for helping Sorcerer's Place lease a new, more powerful server!)

    Joined:
    Apr 13, 2003
    Messages:
    3,105
    Likes Received:
    35
    Well, the latter group of scripts are just the pStorage sripts that I was planning to add to the hole. They are the most reliable persistant storage that I've found. The first two are the ones that I've described at the top of my first post.
     
Sorcerer's Place is a project run entirely by fans and for fans. Maintaining Sorcerer's Place and a stable environment for all our hosted sites requires a substantial amount of our time and funds on a regular basis, so please consider supporting us to keep the site up & running smoothly. Thank you!

Sorcerers.net is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on amazon.com, amazon.ca and amazon.co.uk. Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.