Loot script; returning to previous lines, referring to the dead and spawning items

Hey folks.

I don’t even know where to start - it seems the more I learn the more questions I have.

  1. I want to use CR as a determining factor when it comes to the quantity and quality of loot drops. Is it possible to GetChallengeRating from a creature in its own OnDeath script? Or do I need to generate loot OnSpawn?

  2. I need a way to return to a previous point in the script by line number. I kinda just assumed this was possible, but I can’t find which command it is.

  3. Which command(s) to use to generate items? Non-stackables, stackables, gold, etc. NWN lexicon refers to CreateObjectVoid as well as CreateObject, for gp there is GiveGoldToCreature and I think there are also some commands for placing things in a given objects inventory, etc. I have too many choices and too little experience, so again, which command(s) to use to generate items?

Using 1.69.

Thanks for reading.

Have a great day. :smiley:

As a general rule of thumb, OnDeath is best avoided when there is a better alternative such as OnSpawn. Many commands still work, but some, such as Actions, fail because the creature is dead.

There is no “goto” in nwscript. There are 3 types of loop instead (do, for & while):

You can use “while” for everything if you like, “for” and “do” are just alternative syntax for convenience.

CreateItemOnObject is the most general function for giving inventory to creatures or containers.

You use CreateObject for an item when you want to spawn it on the ground.

Gold is a special case because there are a few glitches in the object handling functions. Rather than trying to remember what they are, it’s probably safer to use GiveGoldToCreature etc.

Thanks a lot for the information.

Looping seems like it will do what I wanted to do with a goto. What happens if a return; command is encountered inside the loop? Will it end script like normal or start loop over?

I used CR to determine EXP so I don’t see why you wouldn’t be able to use it to determine gear.

@Charles Read my Basics series. It is all explained in there.

The Decisions one covers loops, etc.


In the main body of a script, return stops the script.

In a function, return stops the current function, breaking out of any loops in that function. It immediately returns control to the code that called the function… Any loops in the calling code continue.

return; exits the function that the script is currently in. if it is in the main function ( void main() ) it stops the script.

break; will break a loop or control structure( in the case of a switch).
continue; will go back to the top of the loop.