Jump to content

Papyrus: Check for a Specific weapon in the players Inventory


Recommended Posts

I need to see if a custom weapon is in the player's Inventory before allowing certain things to happen. How do I check in Papyrus to see if the weapon is there?

 

I know that GetItemCount will return the number of the items in the inventory, but that requires the ObjectID. So how do I dynamically obtain the ObjectID?

Edited by Guest
Link to comment
Share on other sites

Check for a Specific weapon in the players Inventory

 

So how do I dynamically obtain the ObjectID

 

That, seems to me, is contradictory. If you want to check for a specific weapon I don't know what issue you have with GetItemCount, you just pass that specific form you want to check for. What exactly do mean by dynamically in this context?

Edited by FrankFamily
Link to comment
Share on other sites

According to the doc (https://www.creationkit.com/index.php?title=GetItemCount#Papyrus_Version) the GetItemCount requires the ObjectID to get the count. So for GetItemCount to work for a specific weapon the Script will need the Objectid.

I was hoping to get the ObjectID via Papyrus by supplying the form name of the weapon and not have to update some 2000+ activators with the weapon's form name.

Edited by Guest
Link to comment
Share on other sites

Oh, I see. The one you should be looking at for Papyrus is this one: https://www.creationkit.com/index.php?title=GetItemCount_-_ObjectReference

You supply the form, in papyrus not just the name, you need to make a property.

https://www.creationkit.com/index.php?title=Bethesda_Tutorial_Papyrus_Introduction_to_Properties_and_Functions

 

And you don't need to do this at the level of the individual activators if they are the same form, you do it in the form. That said, if a process needs 2000+ activators then maybe you should rethink if there isn't a better way to accomplish your goal.

 

For reference: https://www.creationkit.com/index.php?title=Category:Papyrus

Edited by FrankFamily
Link to comment
Share on other sites

Oh, I see. The one you should be looking at for Papyrus is this one: https://www.creationkit.com/index.php?title=GetItemCount_-_ObjectReference

You supply the form, in papyrus not just the name, you need to make a property.

https://www.creationkit.com/index.php?title=Bethesda_Tutorial_Papyrus_Introduction_to_Properties_and_Functions

 

And you don't need to do this at the level of the individual activators if they are the same form, you do it in the form. That said, if a process needs 2000+ activators then maybe you should rethink if there isn't a better way to accomplish your goal.

 

For reference: https://www.creationkit.com/index.php?title=Category:Papyrus

 

I know you are trying to be helpful, but I have no choice about the Activators. They are all those little spots throughout the game where you can mine ore or gems and quarry building materials.

 

So to accomplish my goal, I am attempting to update the script which every one of these sites invoke (MineOreScript). To pass a variable to that script, I must either update every one of the 2000+ activators with the new variable and assign it a value, hard code the ID (not a good idea as its position in the Load Order will change) or obtain the ID via code. This last option is what I am attempting to do, for obvious reasons.

Link to comment
Share on other sites

Before you go editing the script (MineOreScript), can you go into more detail about what it is you are wanting to accomplish with this weapon? I've done work with the MineOreScript for one of my mods and I'd hate to see incompatibility creep up if it can be avoided.

 

I'm guessing that you want to use a custom weapon in place of the stock pickaxe. If that is the case, you just need to add the weapon to the formlist MineOreToolsList. No editing of the script needed in that scenario.

Link to comment
Share on other sites

 

Before you go editing the script (MineOreScript), can you go into more detail about what it is you are wanting to accomplish with this weapon? I've done work with the MineOreScript for one of my mods and I'd hate to see incompatibility creep up if it can be avoided.

 

I'm guessing that you want to use a custom weapon in place of the stock pickaxe. If that is the case, you just need to add the weapon to the formlist MineOreToolsList. No editing of the script needed in that scenario.

 

Following line 118 in vanilla script:

; ------------------------------------------------------------------------------
          if Game.GetPlayer().GetItemCount(UC_weap_Miners_Advantage) > 0
               ResourceCount *= 2
          else
          endif
; ------------------------------------------------------------------------------

 

If you PM me a place, I will drop a zip of the esp.

Edited by Guest
Link to comment
Share on other sites

I see what you are doing. Adjusting the amount given when the player has a specific weapon on their person.

Unfortunately for my mod, that would be a conflict in intention even if the two were made to be compatible.

 

As cdcooley stated GetFormFromFile is the function that you will need to obtain the FormID of the weapon in question.

Example:

 

 

          Form UC_weap_Miners_Advantage = Game.GetFormFromFile(0x00123456,"SomeMod.esp")
          if Game.GetPlayer().GetItemCount(UC_weap_Miners_Advantage) > 0
               ResourceCount *= 2
          else
          endif

Replace "SomeMod.esp" with the plugin where the actual weapon is coming from.

Replace the hex number with the FormID number of the weapon in question. Only replace the last 6 digits. The first two are load order and for the purposes of GetFormFromFile they need to remain at 00 as that function looks at entries relative to the passed in plugin.

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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