Jump to content

Script problem


Recommended Posts

So I have a display case that has 3 static objects in it and there are 3 buttons. When pressed it will disable the connected display and give you the item from a container. The code is rigged so that you can ONLY remove 1 at a time, requiring you to replace the display you took before taking another. The issue I have having is that the first time you press the button, it disables the display but fails to give you the item. I have verified that the correct item is indeed in the container and that the button scripts are pointing to the proper displays and proper item forms, but it will not give me the item the first time it's pressed.

 

I then console the item in and press the button again, which returns the item and enables the display and after that all the buttons work perfectly fine. I can't figure out why it's doing this.

 

 

Objectreference Property Staff1Ref Auto
Objectreference Property Staff2Ref Auto
Objectreference Property Staff3Ref Auto

ObjectReference Property ThisStaff Auto
Weapon Property StaffChoice Auto

ObjectReference Property StaffStore Auto

Event OnActivate(ObjectReference akActionRef)
    if akActionRef == Game.GetPlayer()
        if Staff1Ref.IsEnabled() && Staff2Ref.IsEnabled() && Staff3Ref.IsEnabled()
            StaffStore.RemoveItem(StaffChoice, akOtherContainer = Game.GetPlayer())
            ThisStaff.Disable()
        Elseif ThisStaff.IsEnabled()
            Debug.Messagebox("You must replace your current Snow Elf staff before borrowing another")
        Elseif ThisStaff.IsDisabled() && Game.GetPlayer().GetItemCount(StaffChoice) == 0
            Debug.Messagebox("You don't have the staff with you to return")
        Elseif ThisStaff.IsDisabled() && Game.GetPlayer().GetItemCount(StaffChoice) == 1
            Game.GetPlayer().RemoveItem(StaffChoice, akOtherContainer = StaffStore)
            ThisStaff.Enable()
        Endif
    Endif
EndEvent

 

Link to comment
Share on other sites

I don't think your problem is in the script if it works after the player already has the staff. It sounds like a container problem. I remember reading that containers might not respond to scripted events until after the player interacts with them. Basically the game doesn't really put items into the containers until the player has interacted with them. If so I'm guessing that putting an item into the container with a script counts as player interaction and triggers the game to recognize the items that should be there.

 

Try adding "StaffStore.AddItem(Game.GetForm(0xf))" right before the "StaffStore.RemoveItem..." line.

Or maybe "Game.GetPlayer().RemoveItem(Game.GetForm(0xf),akOtherContainer = StaffStore)" instead if AddItem doesn't work.

 

Actually, that's too many Game.GetPlayer() calls and redundant tests for my taste. Try:

Objectreference Property Staff1Ref Auto
Objectreference Property Staff2Ref Auto
Objectreference Property Staff3Ref Auto

ObjectReference Property ThisStaff Auto
Weapon Property StaffChoice Auto

ObjectReference Property StaffStore Auto

Event OnActivate(ObjectReference akActionRef)
    if akActionRef == Game.GetPlayer()
        if Staff1Ref.IsEnabled() && Staff2Ref.IsEnabled() && Staff3Ref.IsEnabled()
            StaffStore.AddItem(Game.GetForm(0xf)) ; Gold
            StaffStore.RemoveItem(Game.GetForm(0xf))
            StaffStore.RemoveItem(StaffChoice, akOtherContainer = akActionRef)
            ThisStaff.Disable()
        Elseif ThisStaff.IsEnabled()
            Debug.Messagebox("You must replace your current Snow Elf staff before borrowing another")
        Elseif akActionRef.GetItemCount(StaffChoice) == 0
            Debug.Messagebox("You don't have the staff with you to return")
        Else
            akActionRef.RemoveItem(StaffChoice, akOtherContainer = StaffStore)
            ThisStaff.Enable()
        Endif
    Endif
EndEvent
Link to comment
Share on other sites

cdcooley is correct about it being a container issue. I've seen similar before. Basically, the game only sees the container and not the contents. The container needs to have its inventory loaded into memory before you can do proper interactions. To load a container's inventory you need to either add something to it or have direct player interaction.

Link to comment
Share on other sites

  • 2 weeks later...

hmmm interesting. Well I worked around it by simply having the item added and removed from base forms and am ignoring the container. Means they basically get a free staff recharge out of it but I'm not too worried about it honestly. Good to know though, I'll have the quest script handlers add the items manually initially in the future. Thanks.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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