logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Legendary Level System & nwnx_funcs

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
scarface



Joined: 12 Jun 2005
Posts: 94
Location: Sweden

PostPosted: Thu Mar 05, 2009 16:25    Post subject: Legendary Level System & nwnx_funcs Reply with quote

I've tried to convert over Funky's LL system to work with Acos nwnx_funcs, and for the most part I've got it working how I want, however there seems to be some bugs in Z-Dialog system, or I am missing something, but 2 days straight I cannot figure it out.

This is what I have so far:

Code:
#include "zdlg_include_i"
#include "hgll_func_inc"

// lists
const string LIST_PAGE_SKILLS       = "ll_page_skills";
const string LIST_PAGE_FEATS        = "ll_page_feats";
const string LIST_PAGE_ABILITIES    = "ll_page_abilities";
const string LIST_PAGE_END          = "ll_page_end";

// pages
const int PAGE_SKILLS               = 0;
const int PAGE_FEATS                = 1;
const int PAGE_ABILITIES            = 2;
const int PAGE_END                  = 3;

void SF_CleanUp();

int GetAbilityFromGreaterFeat(int nFeat);

void SF_Init()
{
    // run cleanup function
    SF_CleanUp();

    object oPC = GetPcDlgSpeaker();

    // setup initial skills page
    int nSkill;
    int nIndex;
    string sCrossClass;
    for (nSkill = 0; nSkill < 27; nSkill ++)
    {
        if (GetIsSkillAvailable(oPC, nSkill) == 1)
        {
            if (GetCostOfSkill(GetControlClass(oPC), nSkill) == 2)
            {
                sCrossClass = " [Cross-Class]";
            }
            else
            {
                sCrossClass = "";
            }
            nIndex = AddStringElement(GetNameOfSkill(nSkill) + sCrossClass, LIST_PAGE_SKILLS, oPC );
            ReplaceIntElement(nIndex - 1, nSkill, LIST_PAGE_SKILLS, oPC);
        }
    }
    // setup abilities page if necessary
    if (GetGainsFeatOnLevelUp(oPC) == 1)
    {
        AddStringElement("Strength", LIST_PAGE_ABILITIES, oPC );
        ReplaceIntElement(0, ABILITY_STRENGTH, LIST_PAGE_ABILITIES, oPC);
        AddStringElement("Dexterity", LIST_PAGE_ABILITIES, oPC );
        ReplaceIntElement(1, ABILITY_DEXTERITY, LIST_PAGE_ABILITIES, oPC);
        AddStringElement("Constitution", LIST_PAGE_ABILITIES, oPC );
        ReplaceIntElement(2, ABILITY_CONSTITUTION, LIST_PAGE_ABILITIES, oPC);
        AddStringElement("Intelligence", LIST_PAGE_ABILITIES, oPC );
        ReplaceIntElement(3, ABILITY_INTELLIGENCE, LIST_PAGE_ABILITIES, oPC);
        AddStringElement("Wisdom", LIST_PAGE_ABILITIES, oPC );
        ReplaceIntElement(4, ABILITY_WISDOM, LIST_PAGE_ABILITIES, oPC);
        AddStringElement("Charisma", LIST_PAGE_ABILITIES, oPC );
        ReplaceIntElement(5, ABILITY_CHARISMA, LIST_PAGE_ABILITIES, oPC);
    }
    // setup feats page if necessary
    if (GetGainsFeatOnLevelUp(oPC) == 1)
    {
        DelayCommand(0.2, ExecuteScript("hgll_featlist_01", oPC));
        DelayCommand(0.4, ExecuteScript("hgll_featlist_02", oPC));
        DelayCommand(0.6, ExecuteScript("hgll_featlist_03", oPC));
        DelayCommand(0.8, ExecuteScript("hgll_featlist_04", oPC));
        DelayCommand(1.0, ExecuteScript("hgll_featlist_05", oPC));
        DelayCommand(1.2, ExecuteScript("hgll_featlist_06", oPC));
        DelayCommand(1.4, ExecuteScript("hgll_featlist_07", oPC));
        DelayCommand(1.6, ExecuteScript("hgll_featlist_08", oPC));
        DelayCommand(1.8, ExecuteScript("hgll_featlist_09", oPC));
        DelayCommand(2.0, ExecuteScript("hgll_featlist_10", oPC));
        DelayCommand(2.2, ExecuteScript("hgll_featlist_11", oPC));
    }
    // set ennd rage responses
    AddStringElement("Accept", LIST_PAGE_END, oPC );
    AddStringElement("Cancel", LIST_PAGE_END, oPC );
    // set initial page to display
    SetDlgPageInt(PAGE_SKILLS);
}

void SF_PageInit()
{
    object oPC = GetPcDlgSpeaker();
    // initiate page
    switch (GetDlgPageInt())
    {
        case PAGE_SKILLS:
        {
            SetDlgPrompt("Your Current Level: " + IntToString(CheckLegendaryLevel(oPC)) + "\n\nSkill Selection:\n\n<có  >Bug: You may have to press 'Previous' several times to bring you to the correct responses, we're working on the issue.</c>");
            SetDlgResponseList(LIST_PAGE_SKILLS, oPC);
            break;
        }
        case PAGE_FEATS:
        {
            SetDlgPrompt("Your Current Level: " + IntToString(CheckLegendaryLevel(oPC)) + "\n\nFeat Selection:\n\n<có  >Bug: You may have to press 'Previous' several times to bring you to the correct responses, we're working on the issue.</c>");
            SetDlgResponseList(LIST_PAGE_FEATS, oPC);
            break;
        }
        case PAGE_ABILITIES:
        {
            SetDlgPrompt("Your Current Level: " + IntToString(CheckLegendaryLevel(oPC)) + "\n\nAbility Selection:\n\n<có  >Bug: You may have to press 'Previous' several times to bring you to the correct responses, we're working on the issue.</c>");
            SetDlgResponseList(LIST_PAGE_ABILITIES, oPC);
            break;
        }
        case PAGE_END:
        {
            SetDlgPrompt("Your Current Level: " + IntToString(CheckLegendaryLevel(oPC)) + "\n\nLevel Up:\n\n<có  >Bug: You may have to press 'Previous' several times to bring you to the correct responses, we're working on the issue.</c>");
            SetDlgResponseList(LIST_PAGE_END, oPC);
            break;
        }
    }
}

void SF_PageSelect()
{
    object oPC = GetPcDlgSpeaker();
    int nSelection = GetDlgSelection();
    // handle page
    switch (GetDlgPageInt())
    {
        case PAGE_SKILLS:
        {
            // get the chosen skill and set as local
            int nSkill = GetIntElement(nSelection, LIST_PAGE_SKILLS, oPC);
            int nSkillRank = GetLocalInt(oPC, "skill_" + IntToString(nSkill));
            SetLocalInt(oPC, "skill_" + IntToString(nSkill), ++nSkillRank);
            int nSkillsLeft = GetLocalInt(oPC, "skills");
            nSkillsLeft -= GetCostOfSkill(GetControlClass(oPC), nSkill);
            SetLocalInt(oPC, "skills", nSkillsLeft);
            // check if we have any skills left
            if (nSkillsLeft < 1)
            {
                // if we get a feat for this level, set the page
                if (GetGainsFeatOnLevelUp(oPC) == 1)
                {
                    SetDlgPageInt(PAGE_FEATS);
                }
                // if we get an ability for this level, set the page
                else if (GetGainsStatOnLevelUp(oPC) == 1)
                {
                    SetDlgPageInt(PAGE_ABILITIES);
                }
                else // set end page
                {
                     SetDlgPageInt(PAGE_END);
                }
            }
            else // still have skill sleft
            {
                // delete current page list and make a new one
                DeleteList(LIST_PAGE_SKILLS, oPC);
                int nSkill;
                int nIndex;
                string sCrossClass;
                for (nSkill = 0; nSkill < 27; nSkill ++)
                {
                    if (GetIsSkillAvailable(oPC, nSkill) == 1)
                    {
                        if (GetCostOfSkill(GetControlClass(oPC), nSkill) == 2)
                        {
                            sCrossClass = " [Cross-Class]";
                        }
                        else
                        {
                            sCrossClass = "";
                        }
                        nIndex = AddStringElement(GetNameOfSkill(nSkill) + sCrossClass, LIST_PAGE_SKILLS, oPC );
                        ReplaceIntElement(nIndex - 1, nSkill, LIST_PAGE_SKILLS, oPC);
                    }
                }
                SetDlgPageInt(PAGE_SKILLS);
            }
            break;
        }
        case PAGE_FEATS:
        {
            // set selected feat as a local
            SetLocalInt(oPC, "feat", GetIntElement(nSelection, LIST_PAGE_FEATS, oPC));
            // if we have an ability for this level, set the page
            if (GetGainsStatOnLevelUp(oPC) == 1)
            {
                SetDlgPageInt(PAGE_ABILITIES);
            }
            else // set end page
            {
                SetDlgPageInt(PAGE_END);
            }
            // run page init again, because for some reason it doesn't fire
            // automatically from this selection handle and will cause the conv
            // to run the same page list again (even though I set a new one...)
            SF_PageInit();
            break;
        }
        case PAGE_ABILITIES:
        {
            // set chosen ability as local
            SetLocalInt(oPC, "ability", GetIntElement(nSelection, LIST_PAGE_ABILITIES, oPC));
            SetDlgPageInt(PAGE_END);
            break;
        }
        case PAGE_END:
        {
            // if we chose to accept..
            if (nSelection < 1)
            {
                // if we had chosen a ability, apply it
                if (GetGainsStatOnLevelUp(oPC) == 1)
                {
                    ModifyAbilityScore(oPC, GetLocalInt(oPC, "ability"), 1);
                    SendMessageToPC(oPC, "Adding Ability: " + GetNameOfAbility(GetLocalInt(oPC, "ability")));
                }
                // if we have chosen a fea, apply it
                if (GetGainsFeatOnLevelUp(oPC) == 1)
                {
                    int nFeat = GetLocalInt(oPC, "feat");
                    // check if the feat was an Epic Greater Ability Feat
                    int nAbility = GetAbilityFromGreaterFeat(nFeat);
                    // if it was, then apply the ability
                    if (nAbility >= 0)
                    {
                        SendMessageToPC(oPC, "Increasing Ability For Greater Feat  " + GetNameOfAbility(nAbility));
                        ModifyAbilityScore(oPC, nAbility, 1);
                    }
                    AddKnownFeat (oPC, nFeat);
                    SendMessageToPC(oPC, "Adding Feat: " + GetNameOfFeat(GetLocalInt(oPC, "feat")));
                }
                // apply skills that need to be
                int nSkill;
                int nSkillAdd;
                for (nSkill = 0; nSkill < 27; nSkill ++)
                {
                    nSkillAdd = GetLocalInt(oPC, "skill_" + IntToString(nSkill));
                    if (nSkillAdd)
                    {
                        ModifySkillRank (oPC, nSkill, nSkillAdd);
                        SendMessageToPC(oPC, "Adding Skill: " + GetNameOfSkill(nSkill));
                    }
                }
                // set hitpoints
                ModifyCurrentHitPoints (oPC, GetHitPointsGainedOnLevelUp(oPC));
                // set saves if necessary
                if (GetGainsSavesOnLevelUp(oPC) == 1)
                {
                    ModifySavingThrowBonus(oPC, SAVING_THROW_FORT, 1);
                    ModifySavingThrowBonus(oPC, SAVING_THROW_REFLEX, 1);
                    ModifySavingThrowBonus(oPC, SAVING_THROW_WILL, 1);
                }
                // get and set new level
                int nLevel = CheckLegendaryLevel(oPC);
                SetPCLootable (oPC, ++nLevel);
                ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_LIGHTNING_M), oPC);
                // end the dialog
                EndDlg();
                AssignCommand(oPC, ClearAllActions());
            }
            break;
        }
    }
}

void SF_CleanUp()
{
    object oPC = GetPcDlgSpeaker();
    DeleteList(LIST_PAGE_ABILITIES, oPC);
    DeleteList(LIST_PAGE_FEATS, oPC);
    DeleteList(LIST_PAGE_SKILLS, oPC);
    DeleteList(LIST_PAGE_END, oPC);
    DeleteLocalInt(oPC, "ability");
    DeleteLocalInt(oPC, "feat");
    int n;
    for (n= 0; n < 27; n++)
    {
        DeleteLocalInt(oPC, "skill_" + IntToString(n));
    }
}
int GetAbilityFromGreaterFeat(int nFeat)
{
    switch (nFeat)
    {
        case 764: case 765: case 766: case 767: case 768:
        case 769: case 770: case 771: case 772: case 773:
            return ABILITY_CHARISMA;
        case 774: case 775: case 776: case 777: case 778:
        case 779: case 780: case 781: case 782: case 783:
            return ABILITY_CONSTITUTION;
        case 784: case 785: case 786: case 787: case 788:
        case 789: case 790: case 791 :case 792: case 793:
            return ABILITY_DEXTERITY;
        case 794: case 795: case 796: case 797: case 798:
        case 799: case 800: case 801: case 802: case 803:
            return ABILITY_INTELLIGENCE;
        case 804: case 805: case 806: case 807: case 808:
        case 809: case 810: case 811: case 812: case 813:
            return ABILITY_WISDOM;
        case 814: case 815: case 816: case 817: case 818:
        case 819: case 820: case 821: case 822: case 823:
            return ABILITY_CONSTITUTION;
    }
    return -1;
}

void main()
{
    switch(GetDlgEventType())
    {
        case DLG_INIT:
            SF_Init();
            break;
        case DLG_PAGE_INIT:
            SF_PageInit();
            break;
        case DLG_SELECTION:
            SF_PageSelect();
            break;
        case DLG_ABORT:
            SF_CleanUp();
            break;
        case DLG_END:
            SF_CleanUp();
            break;
    }
}


nwnx_funcs is called from within Funky's hgll_func_inc script.

The conversation has been completey re-written as you see, and the issue I'm having is when the conversation page list has more than 1 page (therefor automatically adding "Next" and "Previous"), when a new list of pages are loaded I'll still be on the same page ID even if the new list only has a single page, so for example, I take a feat that was on page 5, it then loads the ability page which is only a single page, but I'm still on page 5 which is now blank and only has "Previous" instead of being sent back to the first page, so I press "Previous" 5 times (each time giving me a blank page as it doesn't exist) and then finally I'm on the first page of the abilities list.

this is a reletively annoying problem, and it happens with any list.

I'm also having an issue with PageInit not firing on some responses, as you can see I've left a comment inthe script.

And last of all, sometimes the page will display a list (like skills or feats), but it will actually be the level up page where you should have to click accept ot cancel, yet it will list responses from the previous list but they do nothing, except the top 2 responses which will be listed as something they are not, when they should say "Accept", and "Cancel".

Can anyone offer assistance?
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Thu Mar 05, 2009 18:14    Post subject: Reply with quote

I am also having this problem. I'm still learning how to use it so I figured it was something I was doing.

Let me know if you find out a fix, Scarface. I'll do the same.
Back to top
View user's profile Send private message
scarface



Joined: 12 Jun 2005
Posts: 94
Location: Sweden

PostPosted: Thu Mar 05, 2009 18:38    Post subject: Reply with quote

Zunath wrote:
I am also having this problem. I'm still learning how to use it so I figured it was something I was doing.

Let me know if you find out a fix, Scarface. I'll do the same.


I use z-dialog for every conversation in my mod without problems (including an entire crafting system), I can't see how it's anything I'm doing wrong which is why I'm really confused and frsutrated, it just doesn't seem to like this script...
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Thu Mar 05, 2009 19:07    Post subject: Reply with quote

Think I figured it out. You need to use dlgDeactivatePreservePageNumberOnSelection() to keep it from happening.

Here's my chunk of code for an example:

Code:
void SkillsPageInit( )
{
    object oSpeakingPC = dlgGetSpeakingPC();
    string MSG_HEADER      = ColorTokenBlue() + "Skill Menu\n" + ColorTokenEnd() +
                             "Level: " + ColorTokenRed() + IntToString(SKL_GetLevel(dlgGetSpeakingPC())) + "\n" + ColorTokenEnd() +
                             "SP: " + ColorTokenRed() + IntToString(SKL_GetCurrentSP(dlgGetSpeakingPC()));
    string sColor = ColorTokenRed();
    string sEnd = ColorTokenEnd();
    dlgSetPrompt( MSG_HEADER );
    int iCount = 1;

    dlgDeactivatePreservePageNumberOnSelection();

    // Create a selection option for each skill
    for(iCount = 1; iCount <= SKL_NUMBER_OF_SKILLS; iCount++)
    {
        string sSkillName = SKL_GetSkillName(iCount) + " (";
        sSkillName = sSkillName + ColorTokenRed() + IntToString(SKL_GetSkillRank(oSpeakingPC, iCount)) + ColorTokenEnd() + ")";
        dlgAddResponseAction(RESPONSE_PAGE, sSkillName);
    }

    dlgActivateResetResponse( MSG_MAIN_MENU );
    dlgActivateEndResponse( MSG_QUIT );
}
Back to top
View user's profile Send private message
scarface



Joined: 12 Jun 2005
Posts: 94
Location: Sweden

PostPosted: Thu Mar 05, 2009 19:16    Post subject: Reply with quote

You must be using a completely different version than me, those functions do not exist in Z-Dialog.
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Thu Mar 05, 2009 19:22    Post subject: Reply with quote

Yeah, sorry. I'm using ZZ-Dialog actually.

That chunk of code has a bunch of functions I created for my purposes. I just wanted to show you how I used it.

Does Z-Dialog not have a function like this?

// Makes it so that on large response lists, the page number will reset
// automatically. onPageInit only!
void dlgDeactivatePreservePageNumberOnSelection( )
Back to top
View user's profile Send private message
scarface



Joined: 12 Jun 2005
Posts: 94
Location: Sweden

PostPosted: Thu Mar 05, 2009 19:31    Post subject: Reply with quote

Zunath wrote:
Yeah, sorry. I'm using ZZ-Dialog actually.

That chunk of code has a bunch of functions I created for my purposes. I just wanted to show you how I used it.

Does Z-Dialog not have a function like this?

// Makes it so that on large response lists, the page number will reset
// automatically. onPageInit only!
void dlgDeactivatePreservePageNumberOnSelection( )


No it doesn't.
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Thu Mar 05, 2009 19:35    Post subject: Reply with quote

I'm not sure then. Sad

Sorry I'm not more help.
Back to top
View user's profile Send private message
scarface



Joined: 12 Jun 2005
Posts: 94
Location: Sweden

PostPosted: Thu Mar 05, 2009 22:56    Post subject: Reply with quote

Zunath wrote:
I'm not sure then. Sad

Sorry I'm not more help.


Thanks to your advice I fixed it, without the need of the function you suggested.

I converted over to zz-dialog, works perfectly, so I guess theres a nasty bug in z-dialog, now on to converting all of my scripts to zz.
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Thu Mar 05, 2009 23:08    Post subject: Reply with quote

Glad to hear things worked out for you.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group