Jump to content
ℹ️ Intermittent Download History issues ×

How to change item values like weight with a script?


Recommended Posts

I want to change item values, e.g. the weight of a weapon, with a script. I have no experience with scripting and I don't know how to do it. I looked up what I think are usable functions in the CS Wiki and found the "SetWeight"-function. With that I wrote the following script to change the weight of the silver longsword (Object ID is 0002521F) from the original 28 to 2:

Scn ItemValueChangerScript

Short DoOnce

Begin GameMode

if DoOnce == 0

;Silver Longsword
SetWeight 2 0002521F

Set DoOnce to 1

Endif

End

I included the variable "DoOnce" and the if-part because I heard it is good practice (but I have no idea). The problem is that there is no change ingame (I activated the newly created esp), I have a silver longsword in my inventar with the same weight of 28, even after dropping and picking up again it stays at 28.

 

How can I make it work with a script?

 

I know I can easily change it with TES4Edit but I want to change it with a script.

Link to comment
Share on other sites

A couple things.

 

What type of script is this saved as? Quest, Object or Spell? There's a drop-down to select this either at the top or bottom of the script editor (depending on if using CS or CSE).

 

Then, depending on which type of script it is, it also needs to be assigned to something so it will actually run.

A quest script needs a quest to be assigned to and the quest needs to have "start game enabled" checked or be started during the game by other means.

A spell script needs to be assigned to a spell effect, which a spell of needs to be cast during game.

An object script needs to be assigned to an object and said object has to be within a cell with the player, of some actor of quite high processing priority otherwise, for it to run each frame.

Link to comment
Share on other sites

Thank you for your answer! It is saved as a Quest. And after your explanation that is the type I want, because I want that the weight is changed independent of spells I have to cast or cells I am in.

 

So I made a quest and called it ItemValueChangerQuest, set the priority to 60 (no idea what that implies, it was a suggestion from a tutorial I read) and made sure "start game enabled" is checked. There was also a drop-down menu for scripts, and I chose my script.

 

But what should I do now? There is still no difference ingame.

 

(btw I hope I use the syntax from the SetWeight-function correctly, but the CS doesn't give an error-message, so it should be ok)

 

 

Edit: Oh wait, it works! I think I didn't save the changes in the CS and just started the game. But after saving in CS and closing it I see the change ingame, hurra :D

 

Now I have a follow-up question: That way how I did it, is it the best method to accomplish my goal? My goal is eventually to be able to change the weight and value of (nearly) every item in the game through an .ini-file (how to accomplish that is a topic for another day). Won't my savefile get corrupted or the loading time unnecessarily bloated? Should I use an object- or spell-script instead? (I want to use a script instead of changing the values with TES4Edit because I heard it is better for mod-compatibility, is that even true?)

Edited by HealerOfThe4thDimension
Link to comment
Share on other sites

It is true if other mods are changing the stuff that you wanna change. Lets say Charley change the attack at a weapon from 20 to 22 and save it in mod a.esp and you change the weight at the same weapon from 18 to 14 and save that in mod b.esp and you run your mod after his, you will not only save the weight you did change as you will save the entire object and over write his attack change but if you script the change, then his attack setting will remain, with your weight setting. Maskar is doing exactly that everywhere in MOO as one example and I will do the same as much as possible as well.

 

Wrye Bash is good to combine level lists, if more than one mod adds stuff to the same ones, but I do not think it can make a new object with your and Charlies objects combined if you 2 made changes direct to that specific object but it is always good to make a Wrye Patch no matter what. I do hope others know more and I should know it as I used it for 17 years now... :/

 

A mod that I use that is supposed to only change some animations at some companions, over writes everything - AI, stats well everything, which is very disturbing. Well the animation is not working anyway so I will screw it. Wrye Patch do not work in this specific case.

 

A quest script runs every 5s so if you only want it to run ones, you can stop the quest with stopquest instead of letting it do a check every 5s if DoOnce is 1. I Usually do not set priority in my quests as they do what they are supposed to do anyway... :wink:

 

Sometimes I create a quest that is just a holder for variables that I use elsewhere, instead of making a global variable, which is very nasty and always unproper to do in any case, in any scripting or programming language, well... The quest will be able to provide and allow other running scripts to change the quest variables no matter if it is running or not it seems, which is just a tip from the coach in case you ever need a specific variable for more then 2 scripts... :wink:

Edited by Pellape
Link to comment
Share on other sites

Two things:

 

1) You don't need a DoOnce condition, in fact it is detrimental to your script. SetWeight, like the majority of OBSE functions like that works for the duration of game session and is not tied to a save file. The way you have your script right now, it will work once, but after saving and quitting the game it won't work anymore. What you want to use instead is GetGameRestarted condition.

 

2) You should use EditorID, not FormID in scripts.

Link to comment
Share on other sites

One question I thought about when I woke up an hour ago is: Why do you wanna change the weight at the weapons in the first place?

 

To be able to carry more?

 

If you wanna be able to carry more, it is better to make changes to the player. There are several different mods that allows you to carry more, some less and some more and I use this one called Carry all you want and I never need to worry about what I have in my inventory, except when it takes very long time to open it, when it is extremely full but I do use spells when looting so I seldom open the inventory in the first place these days and I sort it with my new dynamic sorter, that now have 2300 items in its database. Well search for carry at Nexus mods if you wanna see alternatives and if this is your goal.

Link to comment
Share on other sites

Thank you for your answers!

 

1) You don't need a DoOnce condition, in fact it is detrimental to your script. SetWeight, like the majority of OBSE functions like that works for the duration of game session and is not tied to a save file. The way you have your script right now, it will work once, but after saving and quitting the game it won't work anymore. What you want to use instead is GetGameRestarted condition.

It's true, my script only worked once. I removed the DoOnce condition and now it works everytime. But why should I use the GetGameRestarted condition when it is working now? The CS Wiki says GetGameRestarted is used to reset or undo changes made by OBSE functions, but I don't want to revert my changes.

 

My script looks like this now (I'll use Editor ID's as of now)

Scn ItemValueChangerScript

Begin GameMode

;Silver Longsword
SetWeight 2 WeapSilverLongsword

End

I'd like to stop the quest with stopquest because it doesn't have to run every 5 seconds, only once. But I don't know the ID from my quest, how can I find it? I didn't find anything in the quest window.

 

One question I thought about when I woke up an hour ago is: Why do you wanna change the weight at the weapons in the first place?

In the beginning I didn't like the weight-ratio of some items, e.g. a Silver Longsword weighing nearly as much as an Iron Warhammer. But after staring at those numbers I think they are not that bad :sweat: But still, I want to learn proper scripting practice (as well as actual scripting).

Link to comment
Share on other sites

Stopping the quest will have the same problem as DoOnce condition, as I described above. Once the quest is stopped it is reflected in save file, and the quest will have to be started again with StartQuest command in order to work.

 

GetGameRestarted condition is recommended, so your script only makes changes once per game session. Without it, it will run continuously, which still accomplishes your goal, but puts unnecessary strain on scripting engine.

Link to comment
Share on other sites

That's a very good reason as any really. :D

 

If we look at real swords, I guess roman short swords and viking swords where very light weighted, well much lighter than a hammer for sure but the viking battle axes where also very light weighted to be able to be used as fast as possible. When the armor got better, the need of heavier weapons where required, like heavy maces and also heavier swords so a mid eval 2h sword where not light weighted for sure and the silver weapons do look more mid eval and do look heavier than steel weapons I think, almost as heavy as mid eval maces or hammers.

Link to comment
Share on other sites

My script looks like this now

Scn ItemValueChangerScript

Begin GameMode

if GetGameRestarted == 1

;Silver Longsword
SetWeight 2 WeapSilverLongsword

endif

End

And it works. If I understand it correctly, that script will change the weight from 28 to 2 once and then GetGameRestarted is always 0. Meaning that it is still checking GetGameRestarted every 5 seconds but because it will be 0 after the first time the strain on the scripting engine is minimal.

 

Alright I think that's it for the first step, thank you all!

 

 

Now I want to implement another thing: to be able to change the weight of that silver longsword through an .ini-file to change that easily (should I make another threat?)

The only thing I found regarding .ini-files was a threat from 2011, I tried to mimic the steps from there:

 

I created an empty .ini-file called "Item Value Changer.ini", put it in my Data folder next to my .esp and modified my script, it looks like this now

Scn ItemValueChangerScript

float WeapSilverLongswordWeight

Begin GameMode

if GetGameRestarted == 1

;Silver Longsword
SetWeight WeapSilverLongswordWeight WeapSilverLongsword

if (fileExists "Data\Item Value Changer.ini" == 1)
runBatchScript "Data\Item Value Changer.ini"

endif
endif

End

And in the .ini-file I wrote one line, "set ItemValueChangerScript.WeapSilverLongswordWeight to 2". But ingame the weight of the silver longsword is 0 (that means the float-variable doesn't get changed by the .ini-file). How can I make it work? In the threat from 2011 it says that the name in the ini file should be the name of the quest where my script is attached to. But there is no difference when I write "set ItemValueChangerQuest.WeapSilverLongswordWeight to 2".

Link to comment
Share on other sites

  • Recently Browsing   0 members

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