Aller au contenu

Photo

Issues while trying to import rest system from HCR


  • Veuillez vous connecter pour répondre
15 réponses à ce sujet

#1
neltymind

neltymind
  • Members
  • 23 messages

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!



#2
KMdS!

KMdS!
  • Members
  • 189 messages

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.



#3
neltymind

neltymind
  • Members
  • 23 messages
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.

#4
KMdS!

KMdS!
  • Members
  • 189 messages

oh, ok, get you something in a few hours



#5
KMdS!

KMdS!
  • Members
  • 189 messages

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);
        
    }


#6
neltymind

neltymind
  • Members
  • 23 messages

Thank you very much!

 

I'll try this later on in my module.



#7
neltymind

neltymind
  • Members
  • 23 messages

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.


#8
KMdS!

KMdS!
  • Members
  • 189 messages

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



#9
meaglyn

meaglyn
  • Members
  • 804 messages

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 ;)



#10
KMdS!

KMdS!
  • Members
  • 189 messages

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);
    }
}


#11
neltymind

neltymind
  • Members
  • 23 messages

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.



#12
KMdS!

KMdS!
  • Members
  • 189 messages

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.



#13
neltymind

neltymind
  • Members
  • 23 messages

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?



#14
KMdS!

KMdS!
  • Members
  • 189 messages

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.



#15
neltymind

neltymind
  • Members
  • 23 messages

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.



#16
KMdS!

KMdS!
  • Members
  • 189 messages

hehe, I see, yes, w/o a rest timer to restrict rest times, the HCR rest recovery alone would not accomplish your goal.

 

If your goal is to remove all rest healing, this is what you'll want

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

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

    if (GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED || GetLastRestEventType() == REST_EVENTTYPE_REST_CANCELLED)
    {
        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);
    }
}

This should strip them to pre-rest levels no mater what. I didn't remove the undesired code, only commented out the code,  so that you could implement it at some other date if so desired.