Author Topic: Changing core stats via nwscript  (Read 1274 times)

Legacy_MrWakka

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Changing core stats via nwscript
« on: December 03, 2014, 11:43:48 am »


               

So I recently felt a wave of nostalgia, and thought about doing a little nwn work. I had an idea for some custom systems, and it has been so long I only vaguely remember what is possible with nwscript. At the time I played nwn I didn't know much of anything of scripting, so I only have a few memories of what I had seen done to go on.


 


Is it possible to have a script alter, permanently, a characters BAB, either in vanilla nwn, or through the use of NWNX, which I seem to recall opened up some additional script functions. And for the same reason, would it be possible to alter character attributes and hp in a similar fashion?


 


Why? Well, for some reason after reading an old wiki for a pw project I was a builder on I kind of got the urge to take a stab at creating a custom system that would apply permanent bonuses. If a character took damage, add that to a variable, and at certain milestones he might gain a permanent bonus +2 hp or the like.


 


But before I get into digging out my old disks and reinstalling I wanted to check if anyone could tell me if I would just be wasting my time on the matter.


               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #1 on: December 03, 2014, 02:45:40 pm »


               

check this



               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #2 on: December 03, 2014, 03:01:09 pm »


               

If you just need the functions to change BAB, hit points, abilities scores, skills, etc - the nwn_funcs provides that. Here's the BAB function, for example:


 


// Sets the Base Attack Bonus Override of oObject to iBaB
// If BAB Override is greater than zero GetBaseAttackBonus will return this instead
// The original BAB can be restored by setting the BAB Override to zero
// The range of iBab is 0 to 254
// Unfortunately this is not a permanent setting as the game calculates the BaB every time a player logs in
void NWNXFuncs_SetBaseAttackBonusOverride(object oCreature, int iBaB)


               
               

               
            

Legacy_MrWakka

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #3 on: December 03, 2014, 05:29:01 pm »


               

Using those, would either of them grant the additional attacks from bab, or is that hard coded?



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #4 on: December 03, 2014, 05:46:52 pm »


               

The APR for BAB is the command SetBaseAttackBonus() (oddly it sets the APR, not the attack bonus).  See also, RestoreBaseAttackBonus() for restoring the APR back to normal.



               
               

               
            

Legacy_MrWakka

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #5 on: December 03, 2014, 10:58:39 pm »


               

So would you set it to 6 for two, or would that result in 6 attacks per round?



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #6 on: December 05, 2014, 04:42:10 pm »


               

Setting SetBaseAttackBonus() to 6 is 6 APR.



               
               

               
            

Legacy_MrWakka

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #7 on: December 06, 2014, 05:34:17 pm »


               

Thanks, I hope to report back some success eventually, it has been very illuminating.



               
               

               
            

Legacy_MrWakka

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #8 on: December 08, 2014, 05:34:59 pm »


               

Alright, I got things reinstalled and started typing away, and quickly hit my first stumbling block, and it is probably simple, but I am so out of practice I am not sure what the issue is.



if (GetIsPC(oPC)&&!GetLocalInt(oPC, "UMBRAL_NEW"))
    {
        NWNXFuncs_SetAbilityScore(oPC, int ABILITY_STRENGTH, int 10, FALSE);
        NWNXFuncs_SetAbilityScore(oPC, int ABILITY_DEXTERITY, int 10, FALSE);
        NWNXFuncs_SetAbilityScore(oPC, int ABILITY_CONSTITUTION, int 10, TRUE);
        NWNXFuncs_SetAbilityScore(oPC, int ABILITY_INTELLIGENCE, int 10, FALSE);
        NWNXFuncs_SetAbilityScore(oPC, int ABILITY_WISDOM, int 10, FALSE);
        NWNXFuncs_SetAbilityScore(oPC, int ABILITY_CHARISMA, int 10, FALSE);
        NWNXFuncs_ModSavingThrowBonus(oPC, SAVING_THROW_ALL, int 0);
        NWNXFuncs_SetMaxHitPoints(oPC, int 10);
        NWNXFuncs_RemoveAllFeats(oPC, TRUE);
        NWNXFuncs_SetBaseAttackBonusOverride(oPC, int 0);
        SetLocalInt(oPC, "BAB", 0)
        NWNXFuncs_RemoveAllSpells(oPC, CLASS_TYPE_SORCERER, int 0, int 9, FALSE);
        SetLocalInt(oPC, "UMBRAL_NEW", 1);
    }

oPC is defined earlier in the script, but NWNXFuncs_SetAbilityScore(oPC, int ABILITY_STRENGTH, int 10, FALSE); is returning an error of unknown state in the compiler.


Anyone able to let me know how I screwed up?


 


And as an aside, is there anyway for a creature to tell what it died from? Physical vs spell?



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #9 on: December 08, 2014, 07:22:49 pm »


               

You need to take out all those "int" keywords in your calls to those functions.



               
               

               
            

Legacy_MrWakka

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #10 on: December 09, 2014, 12:02:50 am »


               

Now I feel silly, thank you for the help!



               
               

               
            

Legacy_MrWakka

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #11 on: December 09, 2014, 06:55:01 am »


               

Back again, and everything is mostly working, except my attempts to set a new max HP. The script compiles, and everything seems to work as it should at the moment when I log in, except for the hit points.


 


This is my oncliententer event script:



#include "nwnx_funcs"

void main()
{
    object oPC=GetEnteringObject();
    if (GetIsPC(oPC)&&!GetLocalInt(oPC, "UMBRAL_NEW"))
    {
        NWNXFuncs_SetAbilityScore(oPC, ABILITY_STRENGTH, 10, FALSE);
        NWNXFuncs_SetAbilityScore(oPC, ABILITY_DEXTERITY, 10, FALSE);
        NWNXFuncs_SetAbilityScore(oPC, ABILITY_CONSTITUTION, 10, TRUE);
        NWNXFuncs_SetAbilityScore(oPC, ABILITY_INTELLIGENCE, 10, FALSE);
        NWNXFuncs_SetAbilityScore(oPC, ABILITY_WISDOM, 10, FALSE);
        NWNXFuncs_SetAbilityScore(oPC, ABILITY_CHARISMA, 10, FALSE);
        NWNXFuncs_ModSavingThrowBonus(oPC, SAVING_THROW_ALL, 1);
        NWNXFuncs_SetCurrentHitPoints(oPC, 10);
        NWNXFuncs_SetMaxHitPoints(oPC, 10);
        NWNXFuncs_RemoveAllFeats(oPC, TRUE);
        NWNXFuncs_SetAllSkillsToZero(oPC);
        NWNXFuncs_SetBaseAttackBonusOverride(oPC, 1);
        SetLocalInt(oPC, "BAB", 1);
        NWNXFuncs_RemoveAllSpells(oPC, CLASS_TYPE_SORCERER, 0, 9, FALSE);
        SetLocalInt(oPC, "UMBRAL_NEW", 1);
    }
    else
    {
        int Current_BAB = GetLocalInt(oPC, "BAB");
        NWNXFuncs_SetBaseAttackBonusOverride(oPC, Current_BAB);
    }
}

It will set current hp to 10, even if that is above the current 'max', but the max doesn't seem to change. Am I using the function wrong? And if this one won't work, is there an alternative?


Ideally i'd like to be able to set it up so the user gains to their max HP over time by performing certain actions, though obviously this is just the initial script to make the player character a blank canvas that can then be expanded upon.



               
               

               
            

Legacy_MrWakka

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #12 on: December 10, 2014, 03:59:22 pm »


               

Not sure if anyone is interested, but I figured i'd share my findings as I went. Since I couldn't get the set max HP function to work I instead switched to a set HP by level function, which after some issues, namely that even if set to 0 you always get at least 1 hp per level, I got it to work.

NWNXFuncs_ModSavingThrowBonus(oPC, SAVING_THROW_ALL, 1); works to increase, but the Set function doesn't seem to eliminate gains from class levels. This should be somewhat solved once I edit the classes 2da, which was always my original intent anyway, though I was starting to hope I could avoid having an extra hak.


 


Overall progress continues, albeit it a bit slower rate than I hoped. Just got the system in to gain stat xp and increase BAB in. once I get it refined a bit and working how I want the other stats should be fairly easy, the biggest ones likely in terms of time will be the spell hooking for caster level XP. Then it is just creating the tasks and mini-games that will allow for increases in things like skills, and certain feats.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #13 on: December 10, 2014, 04:50:49 pm »


               

there is a server setting for setting max HP. not sure if that will help you, but you should be aware of it.



               
               

               
            

Legacy_MrWakka

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Changing core stats via nwscript
« Reply #14 on: December 10, 2014, 05:34:29 pm »


               

Yeah, that just sets the hp on level up from random to max. My goal was to alter a persons HP permanently. So for example a level 10 sorcerer might have 50 odd hp. The script would then change that, in this instance I was trying to set it to be 10 instead.


As it stands currently when a player logs in to my module they are checked to see if they are new, then if they are a sorcerer, and then leveled to 20, and a number of local variables are stored on the character for tracking a individualized xp on a stat by stat basis.


When they level, and then take a portal, they are then stripped to 20hp, their ability scores are each set to 10, BAB to 1, and all feats, spells and skill points are removed. (The leveling is required for the spell slots, should a player pursue a spellcasting career.)


 


From there forward certain actions earn them experience to specific things. Currently only melee and ranged combat are implemented, but whenever they inflict damage a variable is increased, representing experience towards a BAB increase. When the variable reaches a target number they are then granted a +1 to their current bab, and the total they need to reach the next stat increase is doubled. Certain stats will be tied together, such as 'combat' stats, so that by increasing one the cost to raise all of them goes up at the same time.


In this manner a person can increase BAB, or Caster Level, but an increase to either increases the cost for both to be advanced going forward. Example: It takes 100 xp for BAB 2, or CL 2, if you raise your BAB to 2, it will cost 200xp for BAB 3 or CL 2. You can choose to raise both slowly, or specialize in one.


 


Once the system is done a character could in theory, given enough time, max everything, but the increasing costs make that unlikely. All the stats will be increased through a relevant activity, spending time in a library might increase your lore skill, whereas collecting lumber might increase your strength and fortitude saves. Ideally I'll have enough activities to keep it interesting and varied.


Ultimately it replaces the class based system inherent in NWN, and instead turns it into something resembling a skill based system like you might find in morrowind, and for it to work being able to adjust a characters hit points is required, but i found a way around the issue i was having.