Jump to content

Script Help: "You lack the item" message displays even if I have the item


Armornv

Recommended Posts

Apologies if this is the wrong forum section for this, but I'm here hoping for a little help. I have practically no knowledge when it comes to Papyrus (or really any other scripting language for that matter). I am trying to implement a display activator script in my own player home mod, but I'm having trouble getting my debug notification to work properly.

 

To explain a bit further: I'm not very creative but I love playing around in the creation kit to the extent of building player homes for my different character playthroughs and to just get better at it in general. Maybe one day I'll come up with something worth publishing, but for now they are just for my own enjoyment. I like taking other people's mods apart to see how they do things and hopefully learn something in the process. That and I couldn't release my current player home as I have several resources from other player homes. :) Which brings me back around to the script.

 

I have copied the display activator script from Elysium Estate as a base because from the tooltips/comments in the script, it appears to do everything I want it to (and some things that I don't really even understand lol)

 

So I have the script working fine. I click my activator, it removes the item from my inventory and stores it in the chest outside of view, and enables the static version I have hanging on the wall. In this case, an amulet. The one thing I didn't like about the script is that it doesn't give you any feedback if you don't have the item in your inventory. For some reason my ADD/OCD just prefers to see that little message.

 

I've mostly been able to understand what each of the functions of the script do, and I have successfully added a Debug.Notification("You lack the required item.") message and it does show me that message when the item is not present. The problem is it ALSO shows the message when I DO have the item. I am close to my wits end and pretty much out of ideas as to why it is doing this, or what needs to be changed.

 

I have messaged the mod author asking for help as well as posting in the comments section of the mod hoping for the same, but I haven't gotten any replies yet so I thought I would try here.

 

Hopefully what I'm doing isn't frowned upon since it is just for my own personal modded playthroughs. However if it is, by all means let me know and I will cease and desist. I'm not terribly familiar with that sort of gray area of other people's stuff/copyrights and what not.

 

I can post the code section that I've added my message to (again, if that is allowed). The script itself is pretty long and made up of multiple functions and events (as well as a separate script for the container that I didn't modify) so it may not be enough to only post the section I've added to. At the same time I'm again unsure if posting the entirety of someone else's script would be no no.

 

The part I added was a simple:

 

else
if count < 1
Debug.Notification("You lack the required item.")
endif
that I snuck into one of the bool functions. Like I said, it does work. Mostly. It just gives me the message when it shouldn't.
Sorry for the wall. :(
Any ideas? thoughts? Advice on what to do? Advice on posting part or all of the script?
Thanks in advance for your time!
Link to comment
Share on other sites

At first glance, what you did seems right. However, it is missing a lot of context. Would need to see the entire script to know what is going on. Perhaps there is a better location for this particular message but without the full script, we will never know.

Link to comment
Share on other sites

That's what I figured. Just wasn't sure if that was cool or not. Posting someone else's script to try and get help hacking it up so to speak. I'll see if I can figure out how to post code here, or can I/should I just post it as text?

Link to comment
Share on other sites

Ok let's see if I get this right. I don't wanna be the guy that spams a forum with walls of improperly formatted code. :smile:

The bits I added are under the Internal Function and Event section toward the end of the bool Function Transfer Items

[spoiler]

Scriptname nt_Script_DisplayActivator extends ObjectReference  
 
{Generic ItemDisplay script for an activator object that stores an item (or one of a set 
of leveled items) in a master container and displays a matching static version in the world.}
 
ObjectReference Property ItemToDisplay Auto
{The display item to be enabled or disabled. If not filled, the reference linked in the CK will be used instead.}
 
Armor[] Property ItemToPlace_Armor Auto
{An item (or group of leveled items) that can be stored in the container and displayed.}
 
Ammo[] Property ItemToPlace_Ammo Auto
{An item (or group of leveled items) that can be stored in the container and displayed.}
 
Book[] Property ItemToPlace_Book Auto
{An item (or group of leveled items) that can be stored in the container and displayed.}
 
Ingredient[] Property ItemToPlace_Ingredient Auto
{An item (or group of leveled items) that can be stored in the container and displayed.}
 
MiscObject[] Property ItemToPlace_MiscObject Auto
{An item (or group of leveled items) that can be stored in the container and displayed.}
 
Potion[] Property ItemToPlace_Potion Auto
{An item (or group of leveled items) that can be stored in the container and displayed.}
 
SoulGem[] Property ItemToPlace_SoulGem Auto
{An item (or group of leveled items) that can be stored in the container and displayed.}
 
Weapon[] Property ItemToPlace_Weapon Auto
{An item (or group of leveled items) that can be stored in the container and displayed.}
 
FormList Property ItemToPlace_WithFormList Auto
{A group of items that should be stored or retrieved. Use if you have a group too large 
to fit in one of the other arrays. Items in the list will always be removed regardless 
of the TransferAllMatchingItems property.}
 
ObjectReference Property MasterContainer Auto
{The container (possibly shared with other activators) that will hold the real items.}
 
Actor Property PlayerRef Auto
 
bool Property TransferAllMatchingItems = false Auto
{Should activating transfer all possible items instead of just one?}
 
 
Form[] Property ItemToPlace Auto Hidden
{Items are copied here from the more specificly typed versions of the script.}
 
 
;=====================================================================
; Functions that can be called from the MasterContainer and other scripts.
;=====================================================================
 
Function TakeItemsFromPlayer(bool forceGreedyMode = false)
{Try to take a matching item (or all matching items) from the player then update the display.
The forceGreedyMode setting will cause a transfer of all matching items even if the activator
would normally only transfer one.}
TransferItems(PlayerRef, MasterContainer, TransferAllMatchingItems || forceGreedyMode)
UpdateDisplay()
EndFunction
 
 
Function ReturnAllItemsToPlayer()
{Return all matching items to the player and update the display.}
TransferItems(MasterContainer, PlayerRef, true)
UpdateDisplay()
EndFunction
 
 
Function UpdateDisplay()
{Refresh the display item to match the master container contents.}
if ItemToDisplay
bool shouldHide = true
if ItemToPlace
int i = ItemToPlace.Length
while i > 0 && shouldHide
i -= 1
if  MasterContainer.GetItemCount(ItemToPlace[i]) > 0
shouldHide = false
endif
endwhile
endif
if ItemToPlace_WithFormList && MasterContainer.GetItemCount(ItemToPlace_WithFormList) > 0
shouldHide = false
endif
if shouldHide
ItemToDisplay.Disable()
else
ItemToDisplay.Enable()
endif
endif
EndFunction
 
 
bool Function CanDisplay(Form akBaseItem)
if ItemToPlace && ItemToPlace.Find(akBaseItem) >= 0
return true            
elseif ItemToPlace_WithFormList && ItemToPlace_WithFormList.HasForm(akBaseItem)
return true
else
             return false
       endif
EndFunction
 
 
 
 
;=====================================================================
; Internal functions and events not meant to be called from other scripts.
;=====================================================================
 
Event OnActivate(ObjectReference akActionRef)
{Exchange item between player and MasterContainer and always sync display.}
if akActionRef == PlayerRef
if !TransferItems(MasterContainer, PlayerRef, TransferAllMatchingItems)
TransferItems(PlayerRef, MasterContainer, TransferAllMatchingItems)
endif
UpdateDisplay()
endif
EndEvent
 
bool Function TransferItems(ObjectReference source, ObjectReference destination, bool greedy)
{Utility function to do the transfer of just the first match or all matches (if greedy). 
Returns false when no items are moved.}
bool searching = true
if MasterContainer
int count
if ItemToPlace
int i = ItemToPlace.Length
while i > 0 && (searching || greedy)
i -= 1
count = source.GetItemCount(ItemToPlace[i])
if count > 0
                                   if !greedy
         count = 1
endif
source.RemoveItem(ItemToPlace[i], count, true, destination)
searching = false
            
                            endif
endwhile
endif
if ItemToPlace_WithFormList && (searching || greedy)
count = source.GetItemCount(ItemToPlace_WithFormList)
if count > 0
source.RemoveItem(ItemToPlace_WithFormList, count, true, destination)
searching = false
                    endif
             else      
                       if count < 1
                              Debug.Notification("You lack the required item.")
                    endif
              endif
endif
return !searching            
EndFunction
 
 
Event OnInit()
{Copy the contents of the more specific lists into the ItemToPlace list. 
With the possibility of more than one type of item being collected together.}
if !ItemToDisplay ; if property not set, try to get display item from a linked ref
ItemToDisplay = GetLinkedRef()
endif
if !ItemToDisplay
Debug.Trace(self + " missing (optional) ItemToDisplay")
endif
if !MasterContainer
Debug.Trace(self + " missing required MasterContainer")
endif
 
int size = ItemToPlace_Armor.Length + ItemToPlace_Ammo.Length + ItemToPlace_Book.Length + ItemToPlace_Ingredient.Length 
size += ItemToPlace_MiscObject.Length + ItemToPlace_Potion.Length + ItemToPlace_SoulGem.Length + ItemToPlace_Weapon.Length
if size < 1 || size > 128
if !ItemToPlace_WithFormList
Debug.Trace(self + " missing required ItemToPlace list")
endif
return ; can not continue with that many items!
endif
ItemToPlace = NewFormArray(size)
int k = 0
if ItemToPlace_Weapon
int i = ItemToPlace_Weapon.Length
while i > 0
i -= 1
ItemToPlace[k] = ItemToPlace_Weapon[i]
k += 1
endwhile
endif
if ItemToPlace_SoulGem
int i = ItemToPlace_SoulGem.Length
while i > 0
i -= 1
ItemToPlace[k] = ItemToPlace_SoulGem[i]
k += 1
endwhile
endif
if ItemToPlace_Potion
int i = ItemToPlace_Potion.Length
while i > 0
i -= 1
ItemToPlace[k] = ItemToPlace_Potion[i]
k += 1
endwhile
endif
if ItemToPlace_MiscObject
int i = ItemToPlace_MiscObject.Length
while i > 0
i -= 1
ItemToPlace[k] = ItemToPlace_MiscObject[i]
k += 1
endwhile
endif
if ItemToPlace_Book
int i = ItemToPlace_Book.Length
while i > 0
i -= 1
ItemToPlace[k] = ItemToPlace_Book[i]
k += 1
endwhile
endif
if ItemToPlace_Ingredient
int i = ItemToPlace_Ingredient.Length
while i > 0
i -= 1
ItemToPlace[k] = ItemToPlace_Ingredient[i]
k += 1
endwhile
endif
if ItemToPlace_Ammo
int i = ItemToPlace_Ammo.Length
while i > 0
i -= 1
ItemToPlace[k] = ItemToPlace_Ammo[i]
k += 1
endwhile
endif
if ItemToPlace_Armor
int i = ItemToPlace_Armor.Length
while i > 0
i -= 1
ItemToPlace[k] = ItemToPlace_Armor[i]
k += 1
endwhile
endif
if ItemToPlace.Find(None) >= 0
Debug.Trace(self + " ItemToPlace: " + ItemToPlace)
       endif
EndEvent
 
 
Form[] Function NewFormArray(int size)
{Create a new form array with the right length.}
if size == 1
return new Form[1]
elseif size == 2
return new Form[2]
elseif size == 3
return new Form[3]
elseif size == 4
return new Form[4]
elseif size == 5
return new Form[5]
elseif size == 6
return new Form[6]
elseif size == 7
return new Form[7]
elseif size == 8
return new Form[8]
elseif size == 9
return new Form[9]
elseif size == 10
return new Form[10]
elseif size == 11
return new Form[11]
elseif size == 12
return new Form[12]
elseif size == 13
return new Form[13]
elseif size == 14
return new Form[14]
elseif size == 15
return new Form[15]
elseif size == 16
return new Form[16]
elseif size == 17
return new Form[17]
elseif size == 18
return new Form[18]
elseif size == 19
return new Form[19]
elseif size == 20
return new Form[20]
elseif size == 21
return new Form[21]
elseif size == 22
return new Form[22]
elseif size == 23
return new Form[23]
elseif size == 24
return new Form[24]
elseif size == 25
return new Form[25]
elseif size == 26
return new Form[26]
elseif size == 27
return new Form[27]
elseif size == 28
return new Form[28]
elseif size == 29
return new Form[29]
elseif size == 30
return new Form[30]
elseif size == 31
return new Form[31]
elseif size == 32
return new Form[32]
elseif size == 33
return new Form[33]
elseif size == 34
return new Form[34]
elseif size == 35
return new Form[35]
elseif size == 36
return new Form[36]
elseif size == 37
return new Form[37]
elseif size == 38
return new Form[38]
elseif size == 39
return new Form[39]
elseif size == 40
return new Form[40]
elseif size == 41
return new Form[41]
elseif size == 42
return new Form[42]
elseif size == 43
return new Form[43]
elseif size == 44
return new Form[44]
elseif size == 45
return new Form[45]
elseif size == 46
return new Form[46]
elseif size == 47
return new Form[47]
elseif size == 48
return new Form[48]
elseif size == 49
return new Form[49]
elseif size == 50
return new Form[50]
elseif size == 51
return new Form[51]
elseif size == 52
return new Form[52]
elseif size == 53
return new Form[53]
elseif size == 54
return new Form[54]
elseif size == 55
return new Form[55]
elseif size == 56
return new Form[56]
elseif size == 57
return new Form[57]
elseif size == 58
return new Form[58]
elseif size == 59
return new Form[59]
elseif size == 60
return new Form[60]
elseif size == 61
return new Form[61]
elseif size == 62
return new Form[62]
elseif size == 63
return new Form[63]
elseif size == 64
return new Form[64]
elseif size == 65
return new Form[65]
elseif size == 66
return new Form[66]
elseif size == 67
return new Form[67]
elseif size == 68
return new Form[68]
elseif size == 69
return new Form[69]
elseif size == 70
return new Form[70]
elseif size == 71
return new Form[71]
elseif size == 72
return new Form[32]
elseif size == 73
return new Form[73]
elseif size == 74
return new Form[74]
elseif size == 75
return new Form[75]
elseif size == 76
return new Form[76]
elseif size == 77
return new Form[77]
elseif size == 78
return new Form[78]
elseif size == 79
return new Form[79]
elseif size == 80
return new Form[80]
elseif size == 81
return new Form[81]
elseif size == 82
return new Form[82]
elseif size == 83
return new Form[83]
elseif size == 84
return new Form[84]
elseif size == 85
return new Form[85]
elseif size == 86
return new Form[86]
elseif size == 87
return new Form[87]
elseif size == 88
return new Form[88]
elseif size == 89
return new Form[89]
elseif size == 90
return new Form[90]
elseif size == 91
return new Form[91]
elseif size == 92
return new Form[92]
elseif size == 93
return new Form[93]
elseif size == 94
return new Form[94]
elseif size == 95
return new Form[95]
elseif size == 96
return new Form[96]
elseif size == 97
return new Form[97]
elseif size == 98
return new Form[98]
elseif size == 99
return new Form[99]
elseif size == 100
return new Form[100]
elseif size == 101
return new Form[101]
elseif size == 102
return new Form[102]
elseif size == 103
return new Form[103]
elseif size == 104
return new Form[104]
elseif size == 105
return new Form[105]
elseif size == 106
return new Form[106]
elseif size == 107
return new Form[107]
elseif size == 108
return new Form[108]
elseif size == 109
return new Form[109]
elseif size == 110
return new Form[110]
elseif size == 111
return new Form[111]
elseif size == 112
return new Form[112]
elseif size == 113
return new Form[113]
elseif size == 114
return new Form[114]
elseif size == 115
return new Form[115]
elseif size == 116
return new Form[116]
elseif size == 117
return new Form[117]
elseif size == 118
return new Form[118]
elseif size == 119
return new Form[119]
elseif size == 120
return new Form[120]
elseif size == 121
return new Form[121]
elseif size == 122
return new Form[122]
elseif size == 123
return new Form[123]
elseif size == 124
return new Form[124]
elseif size == 125
return new Form[125]
elseif size == 126
return new Form[126]
elseif size == 127
return new Form[127]
else
return new Form[128]
endif
EndFunction 
 

[/spoiler]

 

Clearly I didn't get the spoiler tags right... Do I get credit for doing things half right? :)
Edited by Armornv
Link to comment
Share on other sites

Not sure why the spoiler did not work for you. Oh well.

 

I'm gonna skip all the technical stuff and say that I think modifying the UpdateDisplay function would be your best bet. See below:

 

 

Function UpdateDisplay()
{Refresh the display item to match the master container contents.}
  if ItemToDisplay
    bool shouldHide = true
    if ItemToPlace
      int i = ItemToPlace.Length
      while i > 0 && shouldHide
        i -= 1
        if  MasterContainer.GetItemCount(ItemToPlace[i]) > 0
          shouldHide = false
        endif
      endwhile
    endif
    if ItemToPlace_WithFormList && MasterContainer.GetItemCount(ItemToPlace_WithFormList) > 0
      shouldHide = false
    endif
    if shouldHide

;add code that checks if display is already enabled. 
;if it is do nothing, if it is not warn about missing item    

      If ItemToDisplay.IsEnabled()
        ;already enabled - need to disable - do not notify of missing item
      Else
        Debug.Notification("You lack the required item.")
      EndIf

;continue with remainder of existing code

      ItemToDisplay.Disable()
    else
      ItemToDisplay.Enable()
    endif
  endif
EndFunction

 

 

Link to comment
Share on other sites

Ishara, may I call you Ishara? Thank you VERY much. You are my hero! I was going to say I already tried that, but I quickly realized that A: You know waaay more about scripting than I do, and B: when I did try it, it worked, but also gave me the message when I had the item (or when I removed the item. I can't remember now) so I knew putting the code there would work, but I abandoned that idea because I wasn't smart enough to figure out how to prevent the parts I didn't want.

 

Seriously, thank you! I can only hope I'm able to return the favor someday. or at least pay it forward and help someone else.

 

Thanks again!

Link to comment
Share on other sites

Oh, and feel free to pass along all the technical stuff. I'm all for learning. Even if it's just a short explanation of why. Especially things like this. I just wish I had more time to devote to modding and scripting. I'm sure there's some really cool stuff that could be done with it. Well, there ARE some really cool things that can be done judging by what's on the nexus.

Anywho, thanks again!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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