Jump to content

Running a script when the player enters the game?


Crockeo

Recommended Posts

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

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

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

  • Recently Browsing   0 members

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