Author Topic: Issues while trying to import rest system from HCR  (Read 1995 times)

Legacy_neltymind

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« on: June 06, 2016, 09:51:55 am »


               

I am building my own version of the OC right now and I want to restrict resting a bit (basically take a away any healing from it so potions, healing kits and healing spells get far more important). Because my scripting abilities are nearly non existent, I decided to take the resting system from the HCR (http://neverwinterva...-v20-v31-addons) and maybe adapt it a little (if I manage to figure out how, that is). 


 


Sadly, the .erf file for importing the HCR into other modules seems to be broken (it has 0 bytes and cannot be unzipped), so I downloaded the module and exported all files that can be selected in the export dialogue and created a single .erf file that way.


 


Then I imported it into my custom OC module and set the rest event in Module Properties > Events to the rest script of HCR. While doing so, I got an error message that a lot of (probably all) .ncs files are missing. 


 


Ist this important? As far was I know .ncs files are just the compiled versions of .nss files and therefore should not be needed. Ist this correct? Will NWN create them automatically if I import .nss files or do I need to do something to make the scripts work?


 


Needles to say, it does not work in my custom OC module. Resting is no different than before.


 


Thank you for any help!



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #1 on: June 06, 2016, 08:57:01 pm »


               

The rest system is a complex set of scripts. It sounds like you only want a small part of it. Describe what you want and I will pull, clean and post it.



               
               

               
            

Legacy_neltymind

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #2 on: June 06, 2016, 10:00:18 pm »


               Thanks!


I actually want the part of the rest script which checks how many hp the PC, Henchmen, Familiars at the start of resting and reduces hp to this amount after resting is done.
               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #3 on: June 08, 2016, 06:56:22 pm »


               

oh, ok, get you something in a few hours



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #4 on: June 09, 2016, 04:59:24 am »


               

Here is a simple bit of code. Look it over and merge it into your existing script. The code is pretty simple. I didn't test it out, but it should work.



    if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
    {
        SetLocalInt(oPC, "HPStartRest", GetCurrentHitPoints(oPC));
    }
 
    if (nLastRestType == REST_EVENTTYPE_REST_FINISHED)
    {
        int iBeforeRestHP = GetLocalInt(oPC, "HPStartRest");
        int iCurrentHp = GetCurrentHitPoints(oPC);
        if(iCurrentHp > iBeforeRestHP)
            int iDamage = iCurrentHp-iBeforeRestHP;
            iDAmage -= GetHitDice(oPC);
            int iConBonus = GetAbilityModifier(ABILITY_CONSTITUTION, oPC);
            if(iConBonus > 0)
                iDamage -=iConBonus;
            if(iDamage >0)
            {
                effect eDamage = EffectDamage(nDam, DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_NORMAL);
                ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);
            }
        SetLocalInt(oPC, "HPStartRest", 0);
        
    }


               
               

               
            

Legacy_neltymind

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #5 on: June 09, 2016, 08:33:42 am »


               

Thank you very much!


 


I'll try this later on in my module.



               
               

               
            

Legacy_neltymind

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #6 on: June 09, 2016, 07:45:46 pm »


               

I think I did something wrong.


 


The script cannot compile. I get the following message:



9.06.2016 20:43:45: Error. 'hcr_rest' did not compile.
hcr_rest.nss(320): Error: NSC1020: Undeclared identifier "nLastRestType"
hcr_rest.nss(326): Error: NSC1020: Undeclared identifier "iDAmage"
hcr_rest.nss(329): Error: NSC1020: Undeclared identifier "iDamage"
hcr_rest.nss(330): Error: NSC1020: Undeclared identifier "iDamage"
hcr_rest.nss(332): Error: NSC1020: Undeclared identifier "nDam"
hcr_rest.nss(332): Error: NSC1007: Required argument "nDamageAmount" missing in call to "EffectDamage"
Compilation aborted with errors.

               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #7 on: June 10, 2016, 01:57:09 am »


               

Post your rest script and I will take a look. What I provided did compile so something else must be off.



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #8 on: June 10, 2016, 02:23:12 am »


               

No... the code you posted has some issues I'm afraid. Look at it again. nLastRestType is not defined.  iDamage is spelled iDAmage once. You need brackets opening at if(iCurrentHp > iBeforeRestHP)  and closing before the SetLocalInt, and you set iDamage but use the undefined nDam variable in the EffactDamage call.     Are you sure it compiled '<img'>



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #9 on: June 10, 2016, 03:20:33 am »


               

That is weird, I remember fixing all those things......


 


Ha!! I see what I did, posted the copy in my text editor and not the toolset.......WOW, silly me! ':wub:'  ':wub:'  ':wub:'  


 


I own a bakery and worked on this while at work, took care of it in between baking, taking orders, phone calls....


 


Here is he correct version



void main()
{
    object oPC = GetLastPCRested();

    if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
    {
        SetLocalInt(oPC, "HPStartRest", GetCurrentHitPoints(oPC));
    }

    if (GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED)
    {
        int iBeforeRestHP = GetLocalInt(oPC, "HPStartRest");
        int iCurrentHp = GetCurrentHitPoints(oPC);
        if(iCurrentHp > iBeforeRestHP)
        {
            int iDamage = iCurrentHp-iBeforeRestHP;
            iDamage -= GetHitDice(oPC);
            int iConBonus = GetAbilityModifier(ABILITY_CONSTITUTION, oPC);
            if(iConBonus > 0)
                iDamage -=iConBonus;
            if(iDamage >0)
            {
                effect eDamage = EffectDamage(iDamage, DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_NORMAL);
                ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);
            }
        }
        SetLocalInt(oPC, "HPStartRest", 0);
    }
}


               
               

               
            

Legacy_neltymind

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #10 on: June 10, 2016, 08:52:22 am »


               

Haha, good to see I am not the only one making mistakes like this from time to time.


 


And thanks a bunch for helping me out although you are obviously pretty busy.


 


BTW: Do you have any idea why my attempt to import everything from the HCR base module produced errors and did not work? I'd like to understand so I don't need to ask if I try something similar next time.



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #11 on: June 10, 2016, 04:30:23 pm »


               

Much of the HCR is entwined and a bit tangled as with any project code.. Unless you can read code and take time to understand what is there it is very easy to miss apply the code when you try to strip sections of it. While this practice is part of the learning curve, heck I did it back when.....it is best to try to understand what is being done in the code, then write what you want for yourself. In the mean time, keep asking when you can't seem to get it right, you will in time. We here are willing to help when asked.



               
               

               
            

Legacy_neltymind

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #12 on: June 12, 2016, 04:01:28 pm »


               

I supposed I must continue my questions. Something with the script is not quite right. While there is no magical damage applied if resting with less than full hitpoints, the amount is not correct. 


 


I tested it with a character who had lost 6 hit points in total. The script only applied a damage of 4 hit points after resting. 


 


Another test with 4 missing hit points led to a damage of 1 hit points being applied after resting.


 


Any ideas?



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #13 on: June 12, 2016, 05:03:11 pm »


               

Let's go through the logic of the code...The rest script has three events Starting, completed and cancelled. The each event fires the script so the script fires at least two times per rest.


 


First it stores the hit points of the player resting when they start resting as a local variable on the player.....


 


When the rest is complete:


    Gets the difference between the rested hit points, which by normal BW coding is fully recovered, and the pre rest hit points.


    if the current hit points are greater than the pre rest hit points


          sets damage variable to the difference.


          retrieves the hit dice of the pc and reduces the damage variable by that amount


          if the pc has a constitution bonus, reduces damage variable by that amount


          if the damage stored is a positive number greater than 0, since the damage could be a negative number if level plus con bonus may be more than damage difference, apply the damage to the player...


 


I see no error in logic......Were they the same pc, were they the same sevel and had the same con bonus? Did they have equiped con bonus items? These can affect the amount of damage done to a pc to set hit points after rest.


 


Btw, I don't remember if cancelling rest does a partial heal on pc,s. Test it and if it does, I need to modify code for that possible exploit. Let me know.



               
               

               
            

Legacy_neltymind

  • Newbie
  • *
  • Posts: 42
  • Karma: +0/-0
Issues while trying to import rest system from HCR
« Reply #14 on: June 12, 2016, 05:23:58 pm »


               

Thanks for the walktrough to the script!


 




          retrieves the hit dice of the pc and reduces the damage variable by that amount


          if the pc has a constitution bonus, reduces damage variable by that amount


         




 


That was the part of the script I did neither expect nor understand. Deleting this part led to the result I hoped for. If I apply any bonus from constitution or reduce the amount of damage done somehow, the player just needs to rest repeatedly to fully heal. So this only makes sense if combined with a script which prevents the player from resting repeatedly.


 


I'll look into the matter of cancelled rests.