Jump to content

[LE] Random Item from Formlist Script


Recommended Posts

Hi! I'm having a bit of trouble with getting a script to work. It's a script supposed to trigger at the end of a dialogue option to add a random item to the player's inventory from a Formlist I've made.
I've already looked up various solutions on Google and on the forums but with little luck, as I know extremely little scripting. :sad:

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
;NEXT FRAGMENT INDEX 3
Scriptname AAA_GordonGif_TIF__02005940 Extends TopicInfo Hidden

;BEGIN FRAGMENT Fragment_2
Function Fragment_2(ObjectReference akSpeakerRef)
Actor akSpeaker = akSpeakerRef as Actor
;BEGIN CODE
int n = GordonGiftCommon.GetSize() - 1
n = utility.RandomInt(0, n)
(game.GetPlayer()).AddItem(GordonGiftCommon.GetAt(n))
;END CODE
EndFunction
;END FRAGMENT

;END FRAGMENT CODE - Do not edit anything between this and the begin comment

FormList Property GordonGiftCommon Auto

 

 

 

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

 

 

This is the very little I've gotten so far from my research but it doesn't work.

Could anyone help me with such a script or maybe give me a little how-to? :smile:

Link to comment
Share on other sites

How many items are you talking about as potential rewards? If it's a number like say 3 for example, would it be easier to create three properties to act as pointers for your items, and then make an argument that is based on the random integer's your fragment generates as which item to give the player?

 

I don't have much experience with these kinds of scripts, well let's face it I stumble around in the dark and luck out most times, so aside of some conjecture, I can't really offer much, just figured if the bridge is out on one route, maybe there's a detour that will get you to where you need to be.

Link to comment
Share on other sites

How many items are you talking about as potential rewards? If it's a number like say 3 for example, would it be easier to create three properties to act as pointers for your items, and then make an argument that is based on the random integer's your fragment generates as which item to give the player?

 

I don't have much experience with these kinds of scripts, well let's face it I stumble around in the dark and luck out most times, so aside of some conjecture, I can't really offer much, just figured if the bridge is out on one route, maybe there's a detour that will get you to where you need to be.

The potential reward is literally any book in the game, which would make properties a painfully long task. :( But the insight is is appreciated for a future script.

Link to comment
Share on other sites

Did you fill in the property for the formlist?

I did.

 

Type: Formlist and then filled it in with my Formlist in properties.

 

Edit: I've tried the script on both an old and a new savegame. :/

Edited by Akarsil
Link to comment
Share on other sites

Does the fragment fire at all? Have you tried putting in a Debug.Trace() or Debug.Notification() line to check?

 

It does seem to fire alright, the debug message I put in does show up.

Link to comment
Share on other sites

 

Does the fragment fire at all? Have you tried putting in a Debug.Trace() or Debug.Notification() line to check?

 

It does seem to fire alright, the debug message I put in does show up.

 

 

Have you put in logging to see: 1. the length of the form list, 2. the value of n after getting a random number, 3. what form, if any, is retrieved from the formlist?

Link to comment
Share on other sites

 

 

Does the fragment fire at all? Have you tried putting in a Debug.Trace() or Debug.Notification() line to check?

 

It does seem to fire alright, the debug message I put in does show up.

 

 

Have you put in logging to see: 1. the length of the form list, 2. the value of n after getting a random number, 3. what form, if any, is retrieved from the formlist?

 

 

I know very little scripting .. I'm not certain how I'd do that. :(

Link to comment
Share on other sites

I know very little scripting .. I'm not certain how I'd do that. :sad:

 

 

Everybody's gotta start somewhere! Do you know how to use the debug log? It's very useful for stuff like this, since various runtime errors will can be spotted even without debug statements in your script itself (e.g. unfilled variables, out-of-bounds array accesses, stuff like that) and *with* debug statements can be used to see exactly what's going on with your script, complete with accurate timestamps.

 

Some example code:

;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
;NEXT FRAGMENT INDEX 3
Scriptname AAA_GordonGif_TIF__02005940 Extends TopicInfo Hidden

;BEGIN FRAGMENT Fragment_2
Function Fragment_2(ObjectReference akSpeakerRef)
Actor akSpeaker = akSpeakerRef as Actor
;BEGIN CODE
int n = GordonGiftCommon.GetSize() - 1
 
Debug.Trace("AKARSIL: List Length: " + n)

n = utility.RandomInt(0, n)
 
Debug.Trace("AKARSIL: Random: " + n)
 
Form newItem = GordonGiftCommon.GetAt(n)
 
Debug.Trace("AKARSIL: Form: " + newItem.GetName())

(game.GetPlayer()).AddItem(newForm)
;END CODE
EndFunction
;END FRAGMENT

;END FRAGMENT CODE - Do not edit anything between this and the begin comment

FormList Property GordonGiftCommon  Auto

(I assume your formlist actually has items in it?)

 

EDIT:

 

I should note however a simpler solution to this would be to create or use an existing LeveledItem list instead, which can be used in an AddItem call and will evaluate the leveled list at that time. This is how a lot of vanilla quest rewards are set up, for example.

Edited by foamyesque
Link to comment
Share on other sites

  • Recently Browsing   0 members

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