Jump to content

Script is not working(AddIem is not a function)


Yrdolf

Recommended Posts

Hi everyone

 

I have a problem with my script that sould work like the archmage chest of Oblivion.

Every time I want to compile it the CK says "AddItem is not a function or does not exist".

I've tried to let the Items move into the players inventory by using "Game.GetPlayer()" and this works but if I use "Chest" it says it is not a function.

Here it is:

 

;Propertys

Container Property Chest Auto

 

;Functions

Function AddItem(Form akItemToAdd, int aiCount = 1, bool abSilent = false) native

Function WaitGameTime(float afHours) native global

 

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

Utility.WaitGameTime(24)

; Game.GetPlayer().AddItem(akBaseItem, aiItemCount, false)

Chest.AddItem(akBaseItem, aiItemCount, true)

Utility.WaitGameTime(168)

EndEvent

 

I can't find my fault. I hope anyone else can help me.

Link to comment
Share on other sites

;Propertys
Container Property Chest Auto

;Functions
Function AddItem(Form akItemToAdd, int aiCount = 1, bool abSilent = false) native
Function WaitGameTime(float afHours) native global

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
Utility.WaitGameTime(24)
; Game.GetPlayer().AddItem(akBaseItem, aiItemCount, false)
Chest.AddItem(akBaseItem, aiItemCount, true)
Utility.WaitGameTime(168)
EndEvent 

 

 

Im not a master myself, but i think the chest property is unseen by the fuction. Try adding

 

 
Chest = akSourceContainer

 

 

do not know if it works but had a similar problem once and that solved it!

Link to comment
Share on other sites

What exactly are you trying to accomplish? I'm not familiar with Oblivion but have done several scripts regarding containers and transfering items for Skyrim. I may have something lying about that could be easily adapted. Just need to know exactly what you are wanting to do.
Link to comment
Share on other sites

1) do not declare native functions

2) the chest must be an ObjectReference. You cannot add items to the base Container form

Tip: if you are putting this script on your chest, then you don't even need the chest property at all (self == chest).

 

ScriptName AddItemTest extends ObjectReference

;Properties
ObjectReference Property Chest Auto

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
Utility.WaitGameTime(24)
; Game.GetPlayer().AddItem(akBaseItem, aiItemCount, false)
Chest.AddItem(akBaseItem, aiItemCount, true)
; Utility.WaitGameTime(168) ; this line is redundant, it serves no purpose?
EndEvent

 

Question: what would happen if you add an item to the chest, then immediately after, add a different item to the chest? Would only the last item get multiplied after 24 hours?

Edited by steve40
Link to comment
Share on other sites

Archmages chest works like this :

You put in some plant (nirinroot)

And in 24 h you will find 10 nirinroots

In the chest

It works with any ingridient

Hmm ok.

 

steve40's suggestion should allow the script to compile. As it appears tho it would perform the task on any item, not just ingredients. You may want to consider looking at this example script on the wiki to see how it causes a container to only accept certain items: http://www.creationkit.com/Complete_Example_Scripts#Script_a_container_that_only_accepts_certain_types_of_items

Link to comment
Share on other sites

@IsharaMeradin: I was just getting around to that :)

 

ScriptName AddItemTest extends ObjectReference

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
If akBaseItem as Ingredient
	BlockActivation() ; don't allow any more ingredients to be added or removed
	Utility.WaitGameTime(24)
	AddItem(akBaseItem, aiItemCount, true)
	BlockActivation(false) ; can now add more ingredients or remove items from container
Else
	RemoveItem(akBaseItem, aiItemCount, true, akSourceContainer) ; if it is not an ingredient, return it to the player
EndIf
EndEvent

Edited by steve40
Link to comment
Share on other sites

Thanks for your replys. I tried some of your solutions.

The ObjectReference Property works, now the script can compile, the "Ingredient Filter" works and the BlockActivation too.

But now, if I place Items in that Chest, they will not duplicate. Before in my Script above the Item that was added to the Chest was Duplicated as many times as it was added (For example, i've added 2 Wheat and after 24 hours the Chest had 4 Wheat)

And the second problem is, that the Chest will not stop to Block but i've told it to stop blocking after the 24 hours.

 

Scriptname duplicateItem extends ObjectReference  
{Duplicates an Item in a chest.}


;Propertys
ObjectReference Property Chest Auto

;Functions
Function AddItem(Form akItemToAdd, int aiCount = 1, bool abSilent = false) native
Function WaitGameTime(float afHours) native global

;Events, If the player adds an Item to the chest, it will be duplicated after 24 hours and you can do this again after 168 hours (one week)
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
if akBaseItem as Ingredient
BlockActivation()
Utility.WaitGameTime(24)
Chest.AddItem(akBaseItem, aiItemCount, true)
BlockActivation(false)
Else
      RemoveItem(akBaseItem, aiItemCount, true, akSourceContainer) ; if it is not an ingredient, return it to the player
EndIf
EndEvent

Link to comment
Share on other sites

Function AddItem(Form akItemToAdd, int aiCount = 1, bool abSilent = false) native

 

Is it just me or does this line look a little funny? :tongue:

Edited by MShoap13
Link to comment
Share on other sites

  • Recently Browsing   0 members

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