Creating custom item on random NPC help?

Here’s what I’m looking to do, I would like a custom item( ex. key) to be created in inventory of one of four NPCs either by trigger or on enter area randomly as to add to the replay-ability of my project. I’ve seen tutorials on random scripting but haven’t found any to what I’m trying to explain here. As always thanks in advance!

The key is the function Random(4) which returns a random integer in the range 0-3.

You could use it, for example, in a switch statement, each case 0-3 assigning one of the four NPC’s tags to a string.

Likewise, a switch based on a Random() number could be used to assign the item resref to another string.

Then you’d CreateItemOnObject using the two strings made above.

You might want some more rules. For example, maybe this only happens once per PC, in which case you’d set a local int on the PC the first time, and abandon subsequent attempts if the flag was already set. You get the general idea.

1 Like

Thanks Proleric very much! Your reply triggered a memory on a script I compiled years ago. I have it now in my current project. Thanks again!

1 Like