Where to begin with scripting?

Hello
To summarize my situation, I started modding NWN2 only recently, and only for my own usage at the moment (although the possibility of sharing some of my future work with friends exists). So far, I’ve managed by modifying tlk and 2da files, but I’m expecting something a bit more ambitious, and that means scripting.

The fact is that I’m not interested in creating a module, but in creating new classes, feats and spells.
I’ve looked at the guides on the vault and most of the content seems related to creating modules.

So, do you have any advice on the subject, a good tutorial to share or anything that can help me in this endeavor?

Thank you.

PS:I don’t have any experience in scripting, but I’m not afraid of learning. I don’t really want someone to do my scripting for me even if it’s simpler, 'cause I have a lot of things I want to do, and I can’t really put all of that on someone else’s back.

PPS: English isn’t my first language, so I may make mistakes now and then. Don’t hesitate to ask if you have a doubt about what I’m trying to tell you. Don’t botter being simple in your answer tho, I’m way better at reading than writing.

1 Like

first, check this out:

Advanced Script Compiler for NWN2

the package contains a plug-in for use in the toolset, as well as a standalone executable (for commandline/batchfile usage, if you want to roll that way)

 
second, scripting:

big topic. Scripts are written in a simplified c-like language that is proprietary to NwN and NwN2. Its usage between the two games is 90% identical, so tutorials for NwN can be used for NwN2 (by and large).

The NwN Lexicon.

I’ve written an intermediate level tutorial for NwN2 here.

but i believe there are many others. Just remember that NwN and NwN2 use the same fundamental language, so the nwn wiki can be as useful (sometimes more useful) than the nwn2 wiki.

There are of course caveats, and NwN2 contains bugs that can be frustrating. If in doubt pls ask a specific question.

 
Scriptfiles have extension .NSS and are ASCII textfiles much like any c-like language.
Once compiled, the bytecode is packed into a .NCS binary file that is run by the game-engine directly. It has the same filename as the .NSS file.

GUI-scripts have special considerations (and bugs) but are basically ordinary scripts. They are compiled on-the-fly by the game-engine (server-side) to prevent exploits.

 
scripting can be thought of in two parts

  • syntax etc
  • the functions and constants that are available for use

The syntax is, again, c-like but simple in comparison to c/c++/c#.

The functions that can be used are declared in a file called NwScript.nss <- that is your primary reference. The engine itself defines what those functions do (is hardcoded). That file can be found in your <install>/Data/scripts_X2.zip [ note: _X2 -> SoZ ]

There are thousands of predefined functions … becoming familiar with them is the biggest challenge when learning how to script. Again some of them have bugs or simply don’t work, having been left in from NwN1. (This gets to the history of NwN2 and is now well into the past.)

most Constants are also defined in NwScript.nss – many of them refer to the row# of 2da files, and you can define additional constants (either in script or by custom 2da row, etc)

 
 
enough for now ?

3 Likes

That should keep me occupied and pointed in the right direction, thanks.

3 Likes

@kevL_s is one of the most competent in this area on this website, and has helped me more times than I can even remember. Others you could ask if you need help with this are @travus, @Lance_Botelle, @CromFr and @4760 . All are very competent and experienced when it comes to this.

One thing I think you should download and check out to see how simple scripts are made is Lilac Soul’s Script Generator. It’s for NWN1, but since scripting is so similar between the two games (as kevL_s already pointed out) it’s very useful when it comes to simpler scripts, and it can also help you understand how things work (you can experiment with it and see how it writes things and learn that way):

https://neverwintervault.org/project/nwn1/other/tool/ls-tk-script-generator

Thanks for the informations andgalf.
I’ve already looked briefly at the Lilac Soul’s Script Generator, the fact that it seemed more oriented towards the creation of modules than the kind of things I’m interested in made me put it aside.
I’ll have another look, there is probably something to learn there.

1 Like

If you would prefer there is a downloadable version of the Lexicon in chm (windows compiled html help file) format too. Not knowing a great deal about NwN 2 scripting I don’t know how much use it will be to you.

TR

as you’re already familiar with .2da files and your goal is to eventually create new spells, open the spells.2da and look through the impactscript collumn. now choose a spell you know, note the name of its impact script and check that script either in the toolset or with a text editor (nwn2\data\scripts.zip).

try to make sense of what you read (knowing the spell will help), get used to how a script is built and look up what the different functions do. this should help you getting your feet wet.

next step would be to create your first simple script, like walking through a trigger to spawn an object.

2 Likes

I juste tried that and the results are… interesting. I just opened nw_s0_summon.NSS and, I may be wrong, but I think I found what looks like leftovers from NWN code (references to the animal domain, in this case*)

*In NWN, the animal domain switched the summoned monster for the one available with the next summon spell. Here, it appears that the code has been changed to have the same effect whether the caster has the animal domain or not, since the power of the domain changed in NWN2 :thinking:

i find it a good doc to have available for Nwn2. I use it to check event quirks etc. For example what GetLastsoandso() functs could be used …

it can also remind what to think about when coding in and around a particular function,

etc.

it’s only sorta accurate for nwn2 but it’s still my goto ref

yeh stuff like that is littered everywhere … keep yer head on the ball, and testing is essential:

// example debug
int goblins = 10;
SendMessageToPC(GetFirstPC(FALSE), "goblins= " + IntToString(goblins));

sends a message/information to the chatbox

Do you have any experience in programming in any language (no matter which?)

@Leo

All the info provided above is a great start.

If and when you are able to start tackling XML code, then you may want to take a look at my

https://neverwintervault.org/project/nwn2/other/gui/nwn2-xml-gui-coding-beginners

NOTE: You need a reasonable grasp of basic scripting first before jumping into this area.

These forums are also the best place to ask the community for help, who will generally respond as they have the time.

All the best.
Lance.

2 Likes

If not you may find that the four tutorials that I wrote (for NwN 1 but mostly still applicable for NwN 2 I have been told) of use (depending on how much you want know why you do things in scripting) -

Finally, I don’t know how much use it will be to you but there is also the NwN 1 Scripting FAQs (I’ll let @kevL_s tell you on that) -

Hope that is of use.

TR

2 Likes

Lots of interesting and useful answers here. Thanks everyone.

@Mmat I did a little bit of webdesign some years ago, so what I know is mostly oriented to that purpose (html, css, php - of those, php seems to be the nearest to what I see while looking at scripts), but I don’t remember much.

Well, I wouldn’t recommend NWN as plattform to learn the basics of programming. On the other hand: a special plattform often serves the motives to learn something.
I had a a look into Tarot_Redhands Tutorials. It seems to be a good point to start.

1 Like

Hi All,

For the record I am in the process of writing a tutorial in a similar fashion as my XML PDF that covers basic scripting. Whether it will be of any help to people only time will tell, but at least it will be presented in a way that hopes to give complete newbies some idea where to start and some basic understanding.

Anyway, we’ll see how it goes and I will post when done.

Cheers, Lance.

5 Likes

Hi All,

OK, Here it is …

https://neverwintervault.org/project/nwn2/other/scripting-tutorial-beginners-nwn2

Hopefully it will help some people.

Thanks, Lance.

3 Likes