Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Dark Dreams of Furiae - a new module for NWN:EE! Buy now
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

Persistent Minimap with GetTileExplored & SetTileExplored

HimmelweissHimmelweiss Member Posts: 72
edited February 2019 in Builders - Scripting
So, yesterday i was bored and played arround with the functions GetTileExplored & SetTileExplored so i am justly simply sharing it here.

Script is supposed to run for the Events "Area OnEnter/OnExit" and "Module OnPlayerRest".
So it saves the minimap vision/fogofwar state of the current area to the bio db on every area enter/exit and player rest.

Take/use it at your own risk because it was just a quick test, didn't really run an super hard test cycle with it.

const string MINIMAP_DB = "minimap_db"; void main() { object oArea = OBJECT_SELF; object oPC = GetEnteringObject(); if (oPC == OBJECT_INVALID) oPC = GetExitingObject(); if (oPC == OBJECT_INVALID) { oPC = GetLastPCRested(); oArea = GetArea(oPC); } if(!GetIsPC(oPC)) return; int iAreaHeight = GetAreaSize(AREA_HEIGHT, oArea); int iAreaWidth = GetAreaSize(AREA_WIDTH, oArea); string sAreaResRef = GetResRef(oArea); string sMap = GetCampaignString(MINIMAP_DB, sAreaResRef, oPC); string sX; string sY; struct sStringTokenizer stTok = GetStringTokenizer(sMap, ","); while (HasMoreTokens(stTok)) { stTok = AdvanceToNextToken(stTok); sX = GetNextToken(stTok); stTok = AdvanceToNextToken(stTok); sY = GetNextToken(stTok); SetTileExplored(oPC, oArea, StringToInt(sX), StringToInt(sY), 1); //SendMessageToPC(oPC, "explored sX: " + sX + " / sY: " + sY); } sMap=""; int x; int y; for (x = 0; x < iAreaWidth; x++) { for (y = 0; y < iAreaHeight; y++) { if (GetTileExplored(oPC, oArea, x, y)) { sMap += IntToString(x)+","+IntToString(y)+","; } } } SetCampaignString(MINIMAP_DB, sAreaResRef, sMap, oPC); }

Post edited by Himmelweiss on
dunahanTerrorble

Comments

  • DonnieEwaldDonnieEwald Member Posts: 4
    I don't know if anyone else is using this code, but your snippet above was enough for me (a total NWN scripting newbie) to implement on our test server. We'll shake it a little to see if we have any problems before moving to the live server, but wanted to share that I am thankful for this quality of life improvement!

    dunahan
  • TarotRedhandTarotRedhand Member Posts: 1,066
    edited June 2020
    If anyone else is having trouble understanding the above code, here it is properly formatted -
    const string MINIMAP_DB = "minimap_db";
    
    void main()
    {
        object oArea = OBJECT_SELF;
        object oPC = GetEnteringObject();
    
        if(oPC == OBJECT_INVALID)
            oPC = GetExitingObject();
    
        if(oPC == OBJECT_INVALID)
        {
            oPC = GetLastPCRested();
            oArea = GetArea(oPC);
        }
    
        if(!GetIsPC(oPC))
            return;
    
        int iAreaHeight = GetAreaSize(AREA_HEIGHT, oArea);
        int iAreaWidth = GetAreaSize(AREA_WIDTH, oArea);
        string sAreaResRef = GetResRef(oArea);
        string sMap = GetCampaignString(MINIMAP_DB, sAreaResRef, oPC);
        string sX;
        string sY;
        struct sStringTokenizer stTok = GetStringTokenizer(sMap, ",");
    
        while(HasMoreTokens(stTok))
        {
            stTok = AdvanceToNextToken(stTok);
            sX = GetNextToken(stTok);
            stTok = AdvanceToNextToken(stTok);
            sY = GetNextToken(stTok);
            SetTileExplored(oPC, oArea, StringToInt(sX), StringToInt(sY), 1); 
    
            //SendMessageToPC(oPC, "explored sX: " + sX + " / sY: " + sY);
        }
    
        sMap = "";
    
        int x;
        int y;
    
        for(x = 0; x < iAreaWidth; x++)
            for (y = 0; y < iAreaHeight; y++)
                if(GetTileExplored(oPC, oArea, x, y))
                    sMap += IntToString(x) + "," + IntToString(y) + ",";
    
        SetCampaignString(MINIMAP_DB, sAreaResRef, sMap, oPC);
    }
    

    I removed a few extraneous braces and made the layout of a few of the lines consistent with the rest of the code.

    TR

    dunahanTerrorble
  • DonnieEwaldDonnieEwald Member Posts: 4
    edited July 2020
    This works well and it's much appreciated!

    Post edited by DonnieEwald on
Sign In or Register to comment.