Jump to content

[LE] How not to have the given materials hardcoded ?


Recommended Posts

Hi guys !

 

I recently published my first mod, in which, among other things, a blacksmith gives you the materials you need to forge some stuff (like 10 Iron daggers, or 5 Imperial Armor sets).

However I'm not really satisfied with how I'm handling it, and one of the things bothering me is that I have to manually calculate and script the resources the blacksmith gives you, which makes not not tied to the actual recipe (so if one day the Iron dagger recipe goes from 1 Iron ingot & 1 Leather strip to 50 Ebony ingot and 3 Troll skulls, the blacksmith will still give you 10 ingots & 10 strips). That way my mod will be easier to maintain, while making it far more compatible with other mods (mainly those which change the recipes of the weapons and armors you can craft).

Is there a way to go around it ?

Basically what I'd like to do is :

- Get the recipe of an item

- Get the list of materials needed

- See how much of these the blacksmith should give you

- And finally get the materials you require

 

I must say that my modding experience is quite limited, so if what I'd like to have is possible, it would be very cool if you could explain it to me with enough details so I can fully understand how it works ^^

 

Have a nice day !

Link to comment
Share on other sites

SKSE has added functions to the ConstructibleObject script. These functions would allow you to obtain the ingredients of a particular recipe as well as the quantity of those ingredients. However, you have to know what recipe you want to work with ahead of time as there are no functions to obtain the recipe for a given item.

 

Something like (non-tested snippet):

 

 

ConstrucibleObject Property MyRecipe Auto
Actor Property PlayerRef Auto
 
;some function or event
Int Index = 0
While Index < MyRecipe.GetNumIngredients() ;loops through all items making up the recipe
  Form Entry = MyRecipe.GetNthIngredient(Index) ;gets item
  Int Num = MyRecipe.GetNthIngredientQuantity(Index) ;gets quantity of item
  PlayerRef.AddItem(Entry,Num)
  Index += 1
EndWhile

 

 

 

Link to comment
Share on other sites

Like IsharaMeradin said there is no way to get a recipe to an item. The reason being that there can be multiple recipes for a single item. Prime example is "Leather". You can have many different hides that make leather in different quantities. There's no papyrus function to specify "Leather" and get a list of recipes that make it. However also like IsharaMeradin said you could use the SKSE function with a property pointing to the constructible recipe record that you choose, and then use the code provided as a base for your add materials script. Of course the key point being that your mod will now require SKSE to function. This may or may not be an acceptable limitation.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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