Crockeo Posted March 23, 2011 Share Posted March 23, 2011 My question is how I would run a script when the player enters the game. My goal is to add something to the player's inventory if they don't have it already when they start their game. If anyone would be able to help me that'd be great. Thank you. Link to comment Share on other sites More sharing options...
Xepha537 Posted March 24, 2011 Share Posted March 24, 2011 Hmmm... How about something along the lines of this: Create a new Quest. Give it a name - "AddSomethingQuest" and tick the "Start game enabled" box. Hit the Ok button. Write a script along the lines of: Scriptname AddSomethingQuestScript Begin GameMode if player.GetItemCount Something == 0 player.AddItem Something endif StopQuest AddSomethingQuest End Go back to the quest and attach your script. Done. Well, you know, that's about the basics of it I think. Link to comment Share on other sites More sharing options...
Nadin Posted March 25, 2011 Share Posted March 25, 2011 I'd leave out the line StopQuest.Also, be sure the script type is a quest. Easy but frustrating mistake to make. Link to comment Share on other sites More sharing options...
Tefnacht Posted March 25, 2011 Share Posted March 25, 2011 Hello. Personally, I would keep the StopQuest line but drop the If-statement around the AddItem command altogether. AddSomethingQuest comes with the same mod the Something item comes with, so there is no way the player could already have that item. If the player starts a new game or loads the mod into an existing savegame for the first time, the quest is running, the script is executed after roughly 5 seconds, adds the item and stops the quest. Another job well done. What I have seen in a lot of mods is this approach: ScriptName AddSomethingQuestScript Short doonce Begin GameMode If doonce == 0 Player.AddItem Something 1 Set doonce To 1 EndIf End To me this seems like a waste of resources. Well ... yes ... not a big waste. You'll probably never notice that this quest is now forever running in the background, eating a couple CPU cycles every fife seconds and never doing anything. However: ScriptName AddSomethingQuestScript Begin GameMode Player.AddItem Something 1 StopQuest AddSomethingQuest End achieves the exact same thing. The script is shorter and the quest is stopped. So now the game engine doesn't have to keep track of it anymore or execute the script every fife seconds. Its done. This might seem like nitpicking. But imagine you run a game with 100 mods that all use their own quest to add a item. Then you have 100 quests constantly running in the background that don't do anything except eat away precious CPU cycles. @Nadin: I am really not trying to troll or flame here. Is there a reason why you would want to keep the quest running in this case? If all it does is add that one item? Link to comment Share on other sites More sharing options...
Nadin Posted March 26, 2011 Share Posted March 26, 2011 Oftentimes, the item would be removed by mistake, or glitch, especially if there are multiple mods running. However, too many quests running can be a drag on on framerates, so...it's a toss-up. Link to comment Share on other sites More sharing options...
Nadin Posted March 26, 2011 Share Posted March 26, 2011 However, if there a multiple examples of this....hmm. You just gave me an excellent idea. Kudos. Link to comment Share on other sites More sharing options...
rickerhk Posted March 26, 2011 Share Posted March 26, 2011 If the item absolutely needs to stay in the player's inventory - make it a quest item. Then you can add it once with the script and stopquest. Link to comment Share on other sites More sharing options...
Crockeo Posted March 26, 2011 Author Share Posted March 26, 2011 Thank you for this information, I have a feeling I'm going to be using this a lot more instead of making activators to give me weapons. Link to comment Share on other sites More sharing options...
Crockeo Posted March 26, 2011 Author Share Posted March 26, 2011 I feel like such a 'newb'. How might I add a new quest, I've completely forgotten. Link to comment Share on other sites More sharing options...
Xepha537 Posted March 27, 2011 Share Posted March 27, 2011 From Bethsoft Tutorial Basic Quest: Quests can be found in the Object Window under Actor Data>Quest. Right-Click in this list and select "new" to create a quest from scratch. After you've done the above, you'll need to "OK" out of that Quest dialog before you can select any scripts. Link to comment Share on other sites More sharing options...
Recommended Posts