Author Topic: Random treasure script problem  (Read 450 times)

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Random treasure script problem
« on: June 12, 2013, 12:23:22 am »


               Hello all,
I've been using this script: http://nwn.wikia.com...Random_treasure
to generate random treasure in various chests in my module all this time. Everything worked perfectly fine.

However, when I tried doing another chest today and, out of my habit, tested it, I was surprised to find out that only items from the "trash" chest spawned and none from the "source chest", which contained the main items that could be found.

After testing it a bit more, I found out that actually items from source chest DO spawn but really rarely, which I don't understand, given that at least one item from the source chest always used to spawn when I used this system. I've also tested it on other chests that had already been placed before in the module and it's the same thing - sometimes the item will spawn, but pretty rarely, most often only items from trash chest will appear.

Could anyone tell me what's going on? I didn't change anything in the script. I tried building the module again, but it doesn't make a difference. No errors occur, either, when I build it.

Help is appreciated. '<img'>
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Random treasure script problem
« Reply #1 on: June 12, 2013, 12:37:21 am »


               Can't help without a script, sorry :/
               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Random treasure script problem
« Reply #2 on: June 12, 2013, 09:24:03 am »


               But I've provided the link to this script at the beginning of the post...

http://nwn.wikia.com...Random_treasure
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Random treasure script problem
« Reply #3 on: June 12, 2013, 02:59:50 pm »


               This line:
if(d3() > 1 ) MakeTreasure(sSourceChest,oThisChest);

states that treasure from the source chest has a 2/3 chance of appearing in a chest.  Junk loot appears in every chest with a 1/2 chance of two junk items appearing.  If your source chest contains things you might regard as junk, you could get rid of them or move them to the junk chest.  To ensure that the source chest always is used, simply remove the "if(d3() > 1)" condition from the above line.

EDIT: had accidentally typed 1/3 instead of 2/3
               
               

               


                     Modifié par WhiZard, 12 juin 2013 - 02:10 .
                     
                  


            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Random treasure script problem
« Reply #4 on: June 12, 2013, 03:01:23 pm »


               That script will only spawn something from the source chest 2/3 of the time. It won't do it all the time. So I think you may be misremembering the results from before. Or you were getting consistently lucky before.

Maybe you are getting unlucky now. If I recall, the pseudo-random number generation is based the state of  the area. Try changing something in the area or doing some things which use random numbers before you open the chest to get different pseudo-randomness.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Random treasure script problem
« Reply #5 on: June 12, 2013, 03:13:25 pm »


               

meaglyn wrote...

That script will only spawn something from the source chest 2/3 of the time. It won't do it all the time. So I think you may be misremembering the results from before. Or you were getting consistently lucky before.

Maybe you are getting unlucky now. If I recall, the pseudo-random number generation is based the state of  the area. Try changing something in the area or doing some things which use random numbers before you open the chest to get different pseudo-randomness.


The state of the area no longer matters.  A long time ago, it used to matter and one could anticipate the initial and latter calculations by area properties, but this was changed in an early patch.
               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Random treasure script problem
« Reply #6 on: June 12, 2013, 04:05:21 pm »


               Thanks a lot! '<img'>
It seems I really was just lucky before, good to know nothing was broken somehow. '<img'>
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Random treasure script problem
« Reply #7 on: June 12, 2013, 06:15:01 pm »


               That's a rather poorly written script, as it will loop through all of the items in the chest two times per use, which could cause some issues if it's ran frequently by multiple PCs, definitely...

I might suggest on first use run the inventory count of oChest, set the total count in a variable on the module, telling the counting function that it's been stored, so it doesn't have to loop again, it just pulls the variable from the module (at run time)...

Anyway, glad to see you are happy with the script, even though it's a 50/50 shot on one pull and a 2/3 shot on the other pull, seems like it's not really going to load much very often...  The junk pull should be 2/3 and the other pull should be catered to a specific %, e.g. 20% chance etc...

Also, it's a single shot chest, it will only ever spawn treasure one time, which is bad, so it should check two things, how long ago it was opened and who opened it, that way it reload the chest to a new user every X minutes apart, though a user may only spawn the treasure one time / module restart...

Anyway, if you are looking for a system with far more customization, then you can check out my 1.69 treasure system in the link below...

nwvault.ign.com/View.php
               
               

               


                     Modifié par _Guile, 12 juin 2013 - 05:18 .
                     
                  


            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Random treasure script problem
« Reply #8 on: June 12, 2013, 06:22:25 pm »


               

_Guile wrote...

That's a rather poorly written script, as it will loop through all of the items in the chest two times per use, which could cause some issues if it's ran frequently by multiple PCs, definitely...

I might suggest on first use run the inventory count of oChest, set the total count in a variable on the module, telling the counting function that it's been stored, so it doesn't have to loop again, it just pulls the variable from the module (at run time)...

Anyway, glad to see you are happy with the script, even though it's a 50/50 shot on one pull and a 2/3 shot on the other pull, seems like it's not really going to load much very often...  The junk pull should be 2/3 and the other pull should be catered to a specific %, e.g. 20% chance etc...

Also, it's a single shot chest, it will only ever spawn treasure one time, which is bad, so it should check two things, how long ago it was opened and who opened it, that way it reload the chest to a new user every X minutes apart, though a user may only spawn the treasure one time / module restart...

Anyway, if you are looking for a system with far more customization, then you can check out my 1.69 treasure system in the link below...

nwvault.ign.com/View.php


Thanks for the suggestion! Still, my module is not a PW, so there's no need to respawn items in the chest after X minutes and the script won't be run that often, either. I've already made too many chests to change the treasure system now, but I'll keep yours in mind if I ever start a new module. '<img'>
I'll just make it so that an item from source chest is spawned always instead of only 2/3 of the time.
               
               

               


                     Modifié par Grani, 12 juin 2013 - 05:23 .