Jump to content

Random item from formlist


gerg357

Recommended Posts

int n = MyFormList.GetSize() - 1
n = utility.RandomInt(0, n)
(game.GetPlayer()).AddItem(MyFormList.GetAt(n))

hey thanks pretty simple i thought it woulda been a longer code :D got a question i know int n is integer and i know n = utility.RandomInt(0, n) gets random value from 0 to ever how many forms is in the list and i know the last line gives the item ... my question is int n is this pretty much making the variable n an integer?? like converting it? reason im asking int n looks like a variable and n looks like a variable just little confused on why there is two and in last time it only uses the n... im guessing its converting n to a integer? thanks again for all the help thats awesome

Link to comment
Share on other sites

g

 

 

int n = MyFormList.GetSize() - 1
n = utility.RandomInt(0, n)
(game.GetPlayer()).AddItem(MyFormList.GetAt(n))

hey thanks pretty simple i thought it woulda been a longer code :D got a question i know int n is integer and i know n = utility.RandomInt(0, n) gets random value from 0 to ever how many forms is in the list and i know the last line gives the item ... my question is int n is this pretty much making the variable n an integer?? like converting it? reason im asking int n looks like a variable and n looks like a variable just little confused on why there is two and in last time it only uses the n... im guessing its converting n to a integer? thanks again for all the help thats awesome

 

gotcha thanks i think i get it now :)

Link to comment
Share on other sites

Leveled lists are already randomized to a degree because they are based upon the player's level. But if you want to try...

 

Requires SKSE

LeveledItem Property myLI Auto
Actor Property PlayerRef Auto

;some event
int n = myLI.GetNumForms() - 1
n = Utility.RandomInt(0,n)
PlayerRef.AddItem(myLI.GetNthForm(n))

You could use the same with LeveledActor and LeveledSpell, just change the property type accordingly. And probably change how you put it into the game. Don't think it is wise to use AddItem with an actor or spell. :P

Link to comment
Share on other sites

There's no need to get a random entry on a leveled list. Even if all of the levels are set to 1, the game will only select one item randomly from the list.

 

So IsharaMeradin's script above will produce exactly the same result as

LeveledItem Property myLI Auto
Actor Property PlayerRef Auto

;some event
PlayerRef.AddItem(myLI)
Edited by lofgren
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...