gerg357 Posted August 13, 2016 Share Posted August 13, 2016 I was wondering what is the code for adding a random item from a formlist to players inventory is? Haven't found much luck online on that Link to comment Share on other sites More sharing options...
lofgren Posted August 13, 2016 Share Posted August 13, 2016 int n = MyFormList.GetSize() - 1 n = utility.RandomInt(0, n) (game.GetPlayer()).AddItem(MyFormList.GetAt(n)) Link to comment Share on other sites More sharing options...
gerg357 Posted August 13, 2016 Author Share Posted August 13, 2016 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 More sharing options...
IsharaMeradin Posted August 13, 2016 Share Posted August 13, 2016 In lofgren's example, 'int' is used to declare/define the type of variable that 'n' will be throughout the rest of the code. Thus 'int' is only needed once and only at the first use. Link to comment Share on other sites More sharing options...
gerg357 Posted August 15, 2016 Author Share Posted August 15, 2016 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 More sharing options...
gerg357 Posted August 16, 2016 Author Share Posted August 16, 2016 hey can this be used with leveled list? or is it just form list.. and if not how would i use it with a level list and what would the property be called?? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 16, 2016 Share Posted August 16, 2016 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 More sharing options...
lofgren Posted August 17, 2016 Share Posted August 17, 2016 (edited) 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 August 17, 2016 by lofgren Link to comment Share on other sites More sharing options...
gerg357 Posted August 17, 2016 Author Share Posted August 17, 2016 Still require skse? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 17, 2016 Share Posted August 17, 2016 Nope. SKSE was only needed for GetNumForms and GetNthForm. AddItem is a stock function. Link to comment Share on other sites More sharing options...
Recommended Posts