Giving the player an item

Post » Fri Nov 16, 2012 10:19 am

Hello there my fellow Dovahkiins. I finally started modding for this game and I have a really good idea for a quest but I am stuck on something that should be just plain simple. I'm not new to scripting or programming (associates) so I understand most of the concepts I'm just having trouble finding any reference to giving a player an item through a quest.

I've looked at other quests and their scripts but I just can't figure out how to get it to work.

I know that "Start()" starts the quest. It works just fine.

SetObjectiveDisplayed(0) displays my objective correctly.

Start()SetObjectiveDisplayed(0)ObjectReference EADQuest01Lettergame.getPlayer().addItem(EADQuest01Letter, 1)

Those last two lines are not giving me compiler errors, which I take to be a good thing; however they are also not giving me my item either.

When I enter the game the Started text pops up, my objective displays, and my journal has the quest but my item is not appearing in my inventory.

I guess what I'm asking is if I have written the code correctly or do I need to add something else somewhere else to get it to enter my inventory?

Thanks in advance for all the help.
User avatar
Josh Lozier
 
Posts: 3490
Joined: Tue Nov 27, 2007 5:20 pm

Post » Fri Nov 16, 2012 12:22 pm

Your code looks fine, I'm doing something similiar, and this is what I'm using:

Game.GetPlayer().Additem(ScenicCarriagesBook,1)

I would look at your property. Either you don't have the correct item assigned to the property in the CK or it's the type. I am using a Book type, not an ObjectReference.
User avatar
Sharra Llenos
 
Posts: 3399
Joined: Wed Jan 17, 2007 1:09 pm

Post » Fri Nov 16, 2012 1:53 pm

I don't know if it matters, but my properties etc are always at the top of the script, before any Set and Event scripts begin. I see your book reference is in the middle of it :shrug:

Also have you tried making the book an alias, and using the Alias_aliasname as the item to add, instead of using its ID?
User avatar
Roy Harris
 
Posts: 3463
Joined: Tue Sep 11, 2007 8:58 pm

Post » Fri Nov 16, 2012 3:11 pm

I don't know if it matters, but my properties etc are always at the top of the script, before any Set and Event scripts begin. I see your book reference is in the middle of it :shrug:

Good point!

I too put my property declarations at the top (I guess an old habit of having to define before I use them), but I have noticed that many of the default Bethesda scripts are very sloppy (imo) and have them scattered through-out the file. Some on top, some in the middle and some on the bottom.

But, the declaration statement has to be outside of the function.

You need to have a property defined so you can pass the EADQuest01Letter object in to the script. This is the property declaration for my example:
Book Property ScenicCarriagesBook Auto
Thenosis, I'm not really sure what this statement is for:
ObjectReference EADQuest01Letter

It looks like you are using a script fragment for your quest (but same concept applies if you have attached a script to your quest). You need to click the Properties button and create a new property for your script (fragment). (If it's a letter, it's probably a type: book.) After you define it, then you can assign the value. If you gave it the same name and type, you can use the AutoFill and it will automatically populate it. If not, click to Edit the Value and choose your quest letter in the drop down.
User avatar
Taylor Bakos
 
Posts: 3408
Joined: Mon Jan 15, 2007 12:05 am

Post » Fri Nov 16, 2012 10:35 pm


Start()SetObjectiveDisplayed(0)ObjectReference EADQuest01Lettergame.getPlayer().addItem(EADQuest01Letter, 1)

Those last two lines are not giving me compiler errors, which I take to be a good thing; however they are also not giving me my item either.


It looks like your Compiler is recognizing "ObjectReference EADQuest01Letter" as a simple variable and not a property, do you have it assigned to somewhere else in your script or did you intend to make it a property?

if you intended it to be a property then follow Sollar's instructions on how to declare your property and for assigning to it in the Properties page.
User avatar
Natasha Biss
 
Posts: 3491
Joined: Mon Jul 10, 2006 8:47 am

Post » Fri Nov 16, 2012 7:13 am

Thank you so much everyone for helping me see my error.
I already had a property for my Letter in the properties tab but I was trying to declare it as a simple variable as well and I also wasn't calling the property's correct name. I was calling the actual item name. Once I changed it to the property name I had assigned, it did exactly what I wanted it to do.

Thanks again everyone. If I have anymore problems I'll be sure to bring them here.
User avatar
SUck MYdIck
 
Posts: 3378
Joined: Fri Nov 30, 2007 6:43 am

Post » Fri Nov 16, 2012 7:14 am

Since I was using this in my own mod, I decided to create a sample and post it:

Show Gift Window and Track Items Given
This is used for the Player to feed his animal companion. The FormList is created in the CK and includes all the food (Potion & Ingredient) items I want to consider food for the animal.

http://www.creationkit.com/Complete_Example_Scripts#Show_Gift_Window_and_Track_Items_Given
User avatar
KiiSsez jdgaf Benzler
 
Posts: 3546
Joined: Fri Mar 16, 2007 7:10 am

Post » Fri Nov 16, 2012 12:45 pm

Rather than:
FormList Property FoodList AutoBool hasBeenFedToday = False  ; Will initialize 'False' alreadyFunction FeedCompanion()	ObjectReference foodItem = None ; This should be a Form and not an ObjectReference and does not need to be cached	int indexPos = FoodList.GetSize() ; could be made an argument of the function	While(indexPos > 0) Actually, you do not need a while loop	as you can filter for your FLST		indexPos -= 1		foodItem = FoodList.GetAt(indexPos) as ObjectReference		AddInventoryEventFilter(foodItem)	EndWhile	Self.ShowGiftMenu(true, FoodList, false, False) ; 'Self' is extraneous	Self.RemoveAllInventoryEventFilters() ; 'Self' is extraneousEndFunctionEvent OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	If akSourceContainer == Game.GetPlayer()		self.RemoveItem(akBaseItem,aiItemCount) ; 'Self' is extraneous		If hasBeenFedToday == False ; !Bool			hasBeenFedToday=True		EndIf	EndIfEndEvent
...try...
FormList Property FoodList AutoBoolhasBeenFedTodayFunction FeedCompanion()	AddInventoryEventFilter(FoodList)	ShowGiftMenu(True, FoodList, False, False)	RemoveAllInventoryEventFilters()EndFunctionEvent OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	If akSourceContainer == Game.GetPlayer()		RemoveItem(akBaseItem, aiItemCount)		If !hasBeenFedToday			hasBeenFedToday = True		EndIf	EndIfEndEvent
User avatar
Daramis McGee
 
Posts: 3378
Joined: Mon Sep 03, 2007 10:47 am

Post » Fri Nov 16, 2012 11:19 am

Function FeedCompanion()
AddInventoryEventFilter(FoodList)
ShowGiftMenu(True, FoodList, False, False)
RemoveAllInventoryEventFilters()
EndFunction

Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
If akSourceContainer == Game.GetPlayer()
RemoveItem(akBaseItem, aiItemCount)
If !hasBeenFedToday
hasBeenFedToday = True
EndIf
EndIf
EndEvent[/code]

Good cleanup, thanks! I didn't realize the AddInventoryEventFilter could be used with a formlist. Nice.
User avatar
Gavin Roberts
 
Posts: 3335
Joined: Fri Jun 08, 2007 8:14 pm


Return to V - Skyrim