NWN2 Scripting

This forum is for general discussion and open to all. If there is anything you wish to talk about with the Chosen then this is the place to do it. Please limit the use of this forum to out of character discussions. For in character roleplaying please use the Free Form Roleplaying forum.

Moderators: Shir'le E. Illios, Bhaern Quel

Post Reply
DragonMind
Maid
Maid
Posts: 127
Joined: Wed Jan 09, 2008 2:35 pm
Location: Denmark

NWN2 Scripting

Post by DragonMind »

Anyone that knows how in the nine hells you attach scripts to certains items/objects and/or event tied to items/objects?

...In this way creating areas gets much more fun, than just being able to create a dull area where nothing happens.
User avatar
Shir'le E. Illios
High Priestess
High Priestess
Posts: 2352
Joined: Mon Feb 13, 2006 9:51 pm
Location: Eilistraee.com
Contact:

Post by Shir'le E. Illios »

That depends on what you mean with "items/objects". Do you mean the items players get in their inventory or placeables objects? In the first case you use module events (every time a player uses an "special power" on an item the "On Use Item" module event triggers where you can get the tag for the item and all that). In the case of placeables it's even easier as each placeable has its own set of events that you can directly attach scripts to.

I hope this is helpful; it can be hard to explain things particularly if you don't know the level of knowledge you have or what exactly you're trying to do. But if you give a specific example of what you're trying to accomplish then it's easier to point you in the right direction.

Also, while I'm more than happy to help you out here, you might also want to consider going to the [url=http://nwn2forums.bioware.com/forums/vi ... 4:1acablrt]Official Scripting help forum[/url:1acablrt] and ask help from the people there. That way you don't have to wait for one person to help you as there's a lot of technically able people there to help you out. :)


Love -x-x-x-

Shir'le
F'sarn natha tithaur wun l'su'aco.

-= Shir'le E. Illios =-
Chosen of Eilistraee
DragonMind
Maid
Maid
Posts: 127
Joined: Wed Jan 09, 2008 2:35 pm
Location: Denmark

Post by DragonMind »

I will tell about 2 examples I thought about, the first greatly inspired by the known "boss fights" in some games.

1)
when a creature reaches(or passes) a specific amount of health, a scripting event should be triggered, this script should do stuff, tha could be: forcing creature to cast spell, spawn mobs, move or spawn objects/obstacles (barrels, book cases, statues...) etc.

2)
Another thing I thought about is doors being locked/unlocked, by putting into and taking stuff from, a container (barrel, chest...)
Ix'Chimalxochitzin
Regular
Posts: 284
Joined: Tue Nov 13, 2007 1:28 am

Post by Ix'Chimalxochitzin »

How about giving said creature a lesser amount of health, and whern it dies use an OnDeath trigger (or whatever it's called, not a modder myself) that's generally used for 'last word' style dialogue?

Corpse vanishes (teleported to become a corpse in some far away, unreachable place, or removed altogether) and is instantly replaced by a second version. After that, round two could begin. Could even give him all new spells to fling about as well given that he's effectively another npc now, rping it as having the boss take the heroes more seriously.

Anyway, just tossing out ideas, no clue on whether or not it can be done.
Image
-----
"Watch your step... If you fall, you'll damage the floor."
DragonMind
Maid
Maid
Posts: 127
Joined: Wed Jan 09, 2008 2:35 pm
Location: Denmark

Post by DragonMind »

I am almost sure it can be done, but how, and where to attach such a script I don't know.

But thank you for your idea Ix :)
User avatar
Shir'le E. Illios
High Priestess
High Priestess
Posts: 2352
Joined: Mon Feb 13, 2006 9:51 pm
Location: Eilistraee.com
Contact:

Post by Shir'le E. Illios »

First off, let me give you a great scripting resource: [url=http://nwn1.nwn2lexicon.com/:1avfraui]NWN Lexicon[/url:1avfraui].

It's for NWN1 scripting, but almost everything also still applies to NWN2 (and as I understand it they're working on a version specific to NWN2). Particularly the simpler examples you mentioned you should be able to do with that resource.

Anyway, on to the examples. I'm doing things mostly from memory here so might not be 100% accurate, but should be close enough to follow I hope.


[quote="DragonMind":1avfraui]1)
when a creature reaches(or passes) a specific amount of health, a scripting event should be triggered, this script should do stuff, tha could be: forcing creature to cast spell, spawn mobs, move or spawn objects/obstacles (barrels, book cases, statues...) etc.[/quote:1avfraui]
Create have an On Damage even that you can put a script in. In this script you can then check how many hitpoints the creature has left and if that fits your criteria (is equal to or smaller than the specific amount) then you can fire another script (ExecuteScript function) that could do all kinds of stuff.

Some slightly more advanced stuff to make it even neater...

You could put that specific amount as a variable on the creature and then use GetLocal... to read the value when checking. This way it's easy to change the value without having to recompile and you could use the same script for various creatures even if they have different amounts to react to.

You could also base the name of the script to fire on a variable you set on the creature. Again this helps with making the script usable in multiple situations; then whenever you want something to happen when a creature reaches a certain number of hitpoints you could use the same base script and just set different variables on the creature for different actions taken. Heck, you could even use scripts to dynamically modify these values to get a chain of events (do one thing when under 50 HP, another when under 20, etc, etc).

Anyway, probably best start with the basis. ;)


[quote="DragonMind":1avfraui]2)
Another thing I thought about is doors being locked/unlocked, by putting into and taking stuff from, a container (barrel, chest...)[/quote:1avfraui]
As I recall placeables have an "On Close" event or such. This is generally a good place to check the contents of the container (since the player likely just altered it). Go through the inventory on this script and see what items are in it (and which are not). Then when the right item(s) are in it you can either call another script from it or just directly lock/unlock the door and such.

And again a slightly more advanced use here is using the variables on the container to do things like change the tag of the item it checks, change the tag of the door it unlocks, etc. Write one script and use it in a dozen different places. ;)


I hope that helps.


Love -x-x-x-

Shir'le
F'sarn natha tithaur wun l'su'aco.

-= Shir'le E. Illios =-
Chosen of Eilistraee
DragonMind
Maid
Maid
Posts: 127
Joined: Wed Jan 09, 2008 2:35 pm
Location: Denmark

Post by DragonMind »

Thank you Shir'le, but the actual scripting is not really a problem,
it's how you attach scripts and everything thats tied to that.

I know how you do in NWN1, but that's not gonna help me very much,
as it's far from that way it works in NWN2 toolset *LOL*

thus in theory in NWN1 I could easily make the examples I described,
NWN2 just confuses me with the way they attach, or should I say DO NOT attach scripts, as they did in NWN1.
DragonMind
Maid
Maid
Posts: 127
Joined: Wed Jan 09, 2008 2:35 pm
Location: Denmark

Post by DragonMind »

They seem to have changed the way scripts are attached, in a recent patch, since last I used the toolset and patchet NWN2.

Now I just got the problem with NWN2 toolset, that is very good at crashing, when I try out things...

Never let a creature be set to lvl100 = toolset crash *LOL*

That leads me to, how would you be able to raise a creatures max HP above what is allowed by their lvl?

...any suggestions, preferably the ones that you know work,
if any exists.
Post Reply