Author Topic: How to increment stats by script?  (Read 325 times)

Legacy_LastBard

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +0/-0
How to increment stats by script?
« on: July 08, 2015, 09:09:12 pm »


               

Hi guys and thanks for your time anyway.


The question is: how can I add a bonus on str, or dex, or other stat by script?


Not a green bonus, but a white permanent increment.


I know there is a system that use Leto (or something like that) to increment the stats in game, not by edit the file bic outside NWN.


Can you help me about a system like that?


Thank you again guys, best regards...


 


Angel



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
How to increment stats by script?
« Reply #1 on: July 08, 2015, 09:29:15 pm »


               

You're probably thinking about LetoScript... which works but I found it to be a headache personally. Plus as I understand you have to boot the player and make them log back in with each change.


 


You can use NWNX_funcs to alter player statistics in game without resorting to having to log the players off. You will need to run NWNX to use it, but I've used it awhile and it works great. 


 


I guess the only real question is... are you making a single player module, or a multiplayer server? I don't know of a way to do it without NWNX support in a multiplayer environment. 



               
               

               
            

Legacy_LastBard

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +0/-0
How to increment stats by script?
« Reply #2 on: July 08, 2015, 10:18:54 pm »


               

Thanks Mad Poet, I use NWNX and i need the system for a multiplayer server. What I have to use specifically?



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
How to increment stats by script?
« Reply #3 on: July 08, 2015, 10:38:40 pm »


               

Setup is rather simple if you already have NWNX going. Find the NWNX.ini file and add the lines indicated in the readme file in the download. Copy the DLL file to your NWN root folder, and then import the NSS files into your module. I just copy/paste the contents into the script editor and name appropriately. Make sure to do a full recompile when playing with include files.


 


Then all you have to do to access the NWNX_funcs functions is add this to the top of the script:



#include "nwnx_funcs"

Save, and then look around for what functions you need.


 


The one to mod ability scores is NWNXFuncs_ModAbilityScore



               
               

               
            

Legacy_LastBard

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +0/-0
How to increment stats by script?
« Reply #4 on: July 09, 2015, 07:49:52 am »


               

Thanks again Mad Poet. If I want to increment STR of 2 point, by conversation, what I have to write exactly?

I'm sorry, I'm really bad with scripts. '<img'>



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
How to increment stats by script?
« Reply #5 on: July 09, 2015, 08:33:33 am »


               

Quick tutorial: I'm pretty layman so don't take this to a C++ class or anything. Teacher would probably laugh.


 


If you ever want to see how to use a function almost all of them have some level of description attached to them. On the right side of the script editor you can see four buttons. Make sure 'Function' is pressed down. Then type the function in the search box you want to look up. You should be able to access any functions that are with NWN, and any that are part of any 'Include' files that your script uses. So open the 'nwnx_funcs' script and type 'NWNXFuncs' in the search box, and then select a function from the list that populates. On the bottom of the screen in that big box where the error message hounds me (GRR!) you will see a bit of a description of the function. Some are REALLY well documented. Others... not so much. If you know what your reading it makes it a lot easier.


 


Here is what NWNXFuncs_ModAbilityScore says:


 




// Changes a base ability score iAbility (ABILITY_STRENGTH, ABILITY_DEXTERITY, etc) by iValue
void NWNXFuncs_ModAbilityScore(object oCreature, int iAbility, int iValue, int bAdjustCurrentHitPoints = 1)

The // basically means this is information for scripters, and has nothing to do with the script when it compiles. In this case it's a pretty straight forward description on what this function is.


 


void : There is a lot more that goes into it, especially about not returning data, but for our purposes it just indicates that this does something rather than define something. Those are other things, like object, int, vector and such... but irrelevant for the moment.


 


NWNXFuncs_ModAbilityScore : This is what you type to call the function. Probably a more technical term for it, but I just call it the function 'Name'.


 


(       )  : Everything in here helps tell the NWNXFuncs_ModAbilityScore what it is supposed to do. It's all the variables and other nonsense that you use to define EXACTLY what to do.


 


object oCreature : This indicates to the function what object this should apply to. Objects can be just about anything, but for this function its really for creatures. I mean placeables don't have ability scores anyway...


 


int iAbility : This indicates the ability score you want to change. There are two types of integers for all intents and purposes, again I'm pretty layman here. There are numbers like 1, 2, -5... whatever. Then there are constants, like ABILITY_STRENGTH, which really indicate a number but are easier to remember then trying to memorize a bunch of freaking numbers.


 


int iValue : Another integer. This one describes how much change you want to happen. This will be a number, like 1, 2, 3, -1... etc etc


 


int bAdjustCurrentHitPoints = 1 : This is a bit trickier because it's not exactly clear by the description. However if you look up NWNXFuncs_SetAbilityScore you find a description.



// bAdjustCurrentHitPoints is only used when Constitution is set: if false a potential increase in hitpoints
// will only affect oCreature's maximum hit points. The missing hit points can be regained the normal way: resting,
// healing, regeneration, etc.

That makes more sense now. If you are changing Constitution scores you will want to set this to 1 to affect the players current hit points, otherwise set it to 0 to only affect maximum hit points. Remember, for the most part 1 is TRUE, 0 is FALSE. You could actually write 'TRUE' in there if you want if its easier for you.


 


So reading this description you can write your function in. First you'll want to get your object, which I'm going to assume is the player entering the server. You can do this with:



object oPC = GetEnteringObject();

object: defines what kind of data this returns. 


 


oPC : o for object type, PC for player character. The name isn't that important. You could write 'ScrubbyPants' and come to the same effect. oPC is just used often because it is clear to read.


 


= GetEnteringObject();  : This means that you are getting the object that is entering.


 


In english...


 


Get the object that enters and name it oPC


 


Then write your onEnter script.



#include "nwnx_funcs"

void main()
{

object oPC = GetEnteringObject();

NWNXFuncs_ModAbilityScore(oPC, ABILITY_STRENGTH, 2, 0);


Reading the NWNX function in english: Modify the ability score of strength by 2 points on the object named oPC. Do not affect current hit points.


 


For a conversation like you indicate all you have to do is change how you get the player as an object. NWN has a real easy way to do this. It's  GetPCSpeaker.



#include "nwnx_funcs"

void main()
{

object oPC = GetPCSpeaker();

NWNXFuncs_ModAbilityScore(oPC, ABILITY_STRENGTH, 2, 0);

}

See the difference? 


 


Now on another note I would be careful sticking this in a conversation as is. Player could potentially just repeat the conversation and keep modifying their strength up by two points, but I'm sure you can find a way around that.


 


Hope this helps!



               
               

               
            

Legacy_LastBard

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +0/-0
How to increment stats by script?
« Reply #6 on: July 10, 2015, 08:10:45 am »


               

Mad Poet, just a word: thanks!

You have explained to me in a perfectly way (also a perfectly mood), so thanks again.

I'll work well with all your suggestions. '<img'>



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
How to increment stats by script?
« Reply #7 on: July 10, 2015, 08:16:43 pm »


               

Not a problem. Glad I could help.