MoonSweets Posted January 5, 2014 Share Posted January 5, 2014 (edited) [sOLVED] Hello, I'm very new to scripting, and really not a programmer at heart, and I would need some help with a simple script. What I want to do, is to add items to the player's inventory when reading a note, but only once (so the player can't read the note again and again to get unlimited samples of these items). I've managed to successfully write these lines: Scriptname EBMGetBooks01 extends ObjectReference {Get the books to put in shelf} Book Property EBMOblivionStreams Auto Book Property EBMWelkynd Auto Event OnRead() Game.GetPlayer().AddItem(EBMOblivionStreams, 1) Game.GetPlayer().AddItem(EBMWelkynd, 1) EndEvent I have no idea of what to do to make the script stop once for all at the end, and never play again. I'm sure there must be something rather simple to do, though. I considered testing the content of the player's inventory, but then they would just have to drop the books, or store them anywhere so be able to activate the script again, and those books are not meant to be unique anyway. I'm considering the possibility of making this a quest, and set stages to know what the player did to set stages, like:The player read the note and got the books : set stage to 20 But if there would be another way to do it, lighter, simpler, I would greatly appreciate any idea. Edited January 5, 2014 by MoonSweets Link to comment Share on other sites More sharing options...
FiftyTifty Posted January 5, 2014 Share Posted January 5, 2014 (edited) This is where states come in handy. You can think of these (metaphorically) as a container; the part of a script in one state can be seperated from another state, as demonstrated below. Placing "Auto" before the State command will make that state the beginning state; the state which the script starts with. Scriptname EBMGetBooks01 extends ObjectReference {Get the books to put in shelf} Book Property EBMOblivionStreams Auto Book Property EBMWelkynd Auto Auto State DoOnceState Event OnRead() Game.GetPlayer().AddItem(EBMOblivionStreams, 1) Game.GetPlayer().AddItem(EBMWelkynd, 1) GoToState ("DoNothingState") EndEvent EndState State DoNothingState EndState Spaced out the code for easier reading. Edited January 5, 2014 by FiftyTifty Link to comment Share on other sites More sharing options...
MoonSweets Posted January 5, 2014 Author Share Posted January 5, 2014 By Akatosh it works so perfectly! No more looping, you broke the dragon with those lines, this is so wonderful!Thank you very much for your wisdom, my friend! Julianos shines upon you! It would have taken me forever to figure this out on my own. Link to comment Share on other sites More sharing options...
FiftyTifty Posted January 5, 2014 Share Posted January 5, 2014 That will be an arm, one leg and a half dead goat. DIDDY MAO! Link to comment Share on other sites More sharing options...
Xander9009 Posted January 7, 2014 Share Posted January 7, 2014 An alternative which would come in handle if you have any functions (because if you have a function that shouldn't do something, then you have to declare the function in the new state) would be a simple boolean DoOnce. It's simpler than states. Scriptname EBMGetBooks01 extends ObjectReference {Get the books to put in shelf} Book Property EBMOblivionStreams Auto Book Property EBMWelkynd Auto Bool DoOnce Event OnRead() If !DoOnce ;Explained below* Game.GetPlayer().AddItem(EBMOblivionStreams, 1) Game.GetPlayer().AddItem(EBMWelkynd, 1) DoOnce = True EndIf EndEvent *DoOnce above started out false by default, and the ! means not, so this means simply "If not DoOnce" which translates to "If DoOnce is not true" Link to comment Share on other sites More sharing options...
FiftyTifty Posted January 7, 2014 Share Posted January 7, 2014 States won't continue to wait for the event to occur; this is a boon to performance. Every little bit helps. Link to comment Share on other sites More sharing options...
Xander9009 Posted January 7, 2014 Share Posted January 7, 2014 I've never really noticed any performance issues related to events waiting to be triggered, but I've also not really paid attention to it. I knew how states worked for functions, but not for events. So, while functions can be called from the default blank state if they don't exist in the current state, events that don't exist in the current state are simply completely ignored? Doesn't really make sense to have it work like that, but at least it's useful for situations like this. I prefer using variables to control what's going on, but it becomes an issue I'll have to keep that in mind. Link to comment Share on other sites More sharing options...
Recommended Posts