Incudust Posted March 28, 2022 Share Posted March 28, 2022 This is to the pro modders out there. I have a problem with my script which adds a "token" to my character that grants health regen when health is at a certain level. ex, at 300 health, a token is added for 3 health regen. if my health goes down to 200, the 3 health regen token is unequipped and removed, and a 2 health regen token is added and equipped. the mod works in all except for the fact that when a token is added with additemNS and equipitem silent, multiple copies of the token are added to my character until my frame rate starts dropping. im using the idoOnce and ser iDoOnce commands but still have trouble because depending on health levels the tokens get switched so iDoOnce maight be a deteiment. how can i prevent an item from being added over and over again while using additemNS? Link to comment Share on other sites More sharing options...
RomanR Posted March 28, 2022 Share Posted March 28, 2022 You can use GetItemCount command in this manner: if health <= 300 && player.GetItemCount (my_token) == 0 player.AddItemNS (my_token) 1 player.EquipItemNS (my_token) ;remove all other tokens after this ... endif Link to comment Share on other sites More sharing options...
DrakeTheDragon Posted March 29, 2022 Share Posted March 29, 2022 And in all cases it will definitely help in diagnosing when seeing your actual script. Link to comment Share on other sites More sharing options...
Pellape Posted April 16, 2022 Share Posted April 16, 2022 (edited) You added your script as a ObjectSCR to an object. Adding scripts to objects in GameMode is dangerous as the script will run Everey frame and I bet you got 30 tokens a second inside your inventory. Add the scipt to a button, CHange GameMode to OnActivate Or Add it isnside a DoOnce... Short DoOnce Begin GameMode If ( DoOnce == 0 ) player.additem <yourtoken> 1 Set DoOnce to 1 EndIf END To keep up the high performance in game, add objectScripts as rarely as possible. Add:SpellsQuestScrptsFuntionsNever Object scripts, which are the bloody default in TES and therefor all use them and clutter up the performance as well... Damn... I have done that a lot myself and learned the hard way Edited April 16, 2022 by Pellape Link to comment Share on other sites More sharing options...
Incudust Posted April 17, 2022 Author Share Posted April 17, 2022 thx guys i actually figured it out a few weeks or so back, the trick was to add all of my various health regen tokens all at once after the birthsign is chosen, where then they sit in my inventory until the parameters are met for them to be equipped/unequiped as necessary. when i was using the i do once commands to add/remove the tokens to the player inventory every time the parameters were met, i was getting insane amounts of tokens per second because i do once doesnt work if you put other add item commands afterwards it seems. any way the script is working well now Link to comment Share on other sites More sharing options...
Pellape Posted April 17, 2022 Share Posted April 17, 2022 (edited) This is not important at all, so see it as some curiosa, nothing else but it is still good to know if you make more scripts as you are getting there, no doubt and I help you when ever I can. This is not pedagogic though but all programs work this way: DO Once or DoOnce is not a command nor function. It is a Variable :D It is something you can call anything.... Variables is what hold the data, as it holds 1 or 0 in this case and open and close the door in your script in this specific case. A command do something with the variables you add so you can call a variable Hamster if you want as you declare the variable with short in this case to hold numbers. They are mostly depended on each others.... :wink: The number of variables is therefor Endless, as you make one up when you need one, well as long as your comp have RAM for it. :smile: Short Hamster If ( Hamster == 0 ) Additem blablaObjID 1 Set Hamster to 1 EndIf If and variables and + (add) was the first thing that made a comp to work at all. Without them, we would never have computers. A CPU cannot calculate anything else than add by the way, well + really and it holds the stuff it needs to calculate in variables, no where else, all other ways to calculate is faked add, it is a bit complicated for a CPU to do it really but it works anyway... :wink: Then it present the result from the variables, hopefully, as long as it is not 42. x, y and z from school maths are variables. Something we store values in.Well. Very very good you got it sorted out in the end. :D I really got the same problem in my first script I made 2004 in Morrowind as all programs normally have a beginning and an end and that is how we think as well. If we want it to repeat, we will code it to repeat as we do not want it to autorepeat really. not this specific script at least. What I did not know, from start was that GameMode runs every frame as well and so does MenuMode. Begin GameMode or begin MenuMode All other ways to use begin in any tes game needs you as a player to do something, use a button or a spell or die: Begin OnDeath as that will only run ones as you cannot die twice, well James Bond did die twice in the film You only live twice from 1967 but all others will not. The target you killed will stay dead if you do not cheat and ress it. ;) Here is a list of all ways to use Begin in TES scripting. Edited April 17, 2022 by Pellape Link to comment Share on other sites More sharing options...
Recommended Posts