Jump to content

Papyrus - Adding a script to every single object of a single type


DarkWolfModding

Recommended Posts

How would you have a script be applied to every type of the same item in the game Is it possible? Is it easy to do?

 

For example:

lets say I have a script that changes the weight of every item in a category (like Crafting Materials or food, which could possibly be done by checking the object for a keyword) to 0 without having to attach the script to each object.

Link to comment
Share on other sites

An array.

 

Let's say for example, you wanna enable every Xmarker in a specific room, and lets say there are 10 of them in there

 
ObjectReference[] property myXmarkerArray auto
 
 
Function MyArray()
 
Int i = myXmarkerArray.length
 
While i
        i -= 1
        myXmarkerArray[i].enable()
EndWhile
 
EndFunction

This doubles as a convenience function so you can change the type to whatever category you want. Like if you wanna do something to potions, just change the array type to potion.

Edited by Terra Nova
Link to comment
Share on other sites

Weight only really matters for the player. Maybe perhaps for followers and/or pack mules.

 

An array is fine, but they are limited to a max of 128 entries. You could use a formlist but you'd need to pre-fill that, then you have mod & dlc compatibility to deal with.

 

Easiest solution is to simply let the player change the weight as they come across it.

 

A start game enabled quest

A player alias

And a script on the player alias.

 

You'd use the OnItemAdded event

You'd check akBaseItem for weight & anything else such as item type

If the weight were greater than 0, change the weight.

At the same time, add the item to a formlist that starts out empty.

 

Weight changes aren't retained across saves so you have to reset them again on each game load

You'd use the OnPlayerLoadGame event

You'd loop through the formlist and reset each item's weight to 0

 

If you wanted to zero the weight of items added to followers as well, you could create an alias that points to the current follower and apply the OnItemAdded event on their alias script. But they can't run the OnPlayerLoadGame event so you'd need to reset those weights on the player alias script too.

Link to comment
Share on other sites

..The average modder is never going to need all 128 elements in an array, and besides, if you need more than that, you can break it up into two arrays. Formlists also have their own limitations, and are much slower than arrays.

 

And yes you can use a Quest script. Quest scripts are the "go to" form for holding functions and storing values.

Link to comment
Share on other sites

True it is unlikely that you would need all 128 elements of an array, but for a mod like the OP describes you have the problem that you never know what the end user is going to do. Between just two mods that I have that add new crafting supplies (Complete Crafting Overhaul and Immersive Armors) there are more than a dozen new skins, ingots, ores, carapaces, and whathaveyou for crafting. Other mods add even more items, some even specialize in nothing but adding more crafting items. The right kind of player could easily exceed the number of items in an array. Arrays have other limitations as well that in my opinon make them a poor choice for this type of mod. This is exactly the kind of thing that formlists are for. You might as well use them.
Link to comment
Share on other sites

  • Recently Browsing   0 members

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