GetItemCount and Base Object

Post » Mon Nov 19, 2012 7:42 pm

Specifically how do I get the number of each dragon claw inside my container?

Here is the erroneous code:
Spoiler

Event OnUpdate()If (MDHClawCont.GetItemCount(dunYngolBarrowCoralClaw) == 1)  Claw01.Enable()else  Claw01.Disable()endifEndEvent

It rejects dunYngolBarrowCoralClaw as being invalid. This is one of the base objects I wish to count.

This is my whole script so far as well:
Spoiler

Scriptname MDHClawScriptCONTAINER extends ObjectReference{Toggles claw display based on contents of container (valid claws)}Bool Property Blocked = False  Auto HiddenMessage Property MessageWarning  AutoFormList Property ClawList  AutoActor Property PlayerREF AutoInt Property DisplayType = 6  Auto;		  ClawXX refers to the Enable parents of claw displayObjectReference Property Claw01 Auto ;CoralObjectReference Property Claw02 Auto ;DiamondObjectReference Property Claw03 Auto ;EbonyObjectReference Property Claw04 Auto ;EmeraldObjectReference Property Claw05 Auto ;GlassObjectReference Property Claw06 Auto ;Golden Claw, handled uniquelyObjectReference Property Claw07 Auto ;IronObjectReference Property Claw08 Auto ;IvoryObjectReference Property Claw09 Auto ;RubyObjectReference Property Claw10 Auto ;SapphireObjectReference Property MDHClawCont Auto  ;Is container used for this scriptEvent OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)If (akSourceContainer == PlayerRef)  If (AllowedItems(akBaseItem))RegisterForSingleUpdate(0.1)  Else   MessageWarning.Show()   RemoveItem(akBaseItem, aiItemCount, False, PlayerRef)  EndIfElse  RemoveItem(akBaseItem, aiItemCount, False, akSourceContainer)EndIfEndEventEvent OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)If (akDestContainer == Game.GetPlayer())  UnregisterForUpdate()EndIfEndEventEvent OnUpdate()If (MDHClawCont.GetItemCount(dunYngolBarrowCoralClaw) == 1)Claw01.Enable()elseClaw01.Disable()endifEndEventBool Function AllowedItems(Form akBaseItem)If (DisplayType == 6)  Return (ClawList.HasForm(akBaseItem))EndifEndFunction

Haven't tested any aspect of this in-game yet.

*EDIT: I'd rather not have each individual dragon claw as its own formlist. There has to be a more elegant method.
User avatar
Ezekiel Macallister
 
Posts: 3493
Joined: Fri Jun 22, 2007 12:08 pm

Post » Mon Nov 19, 2012 1:43 pm

You get the count on the PROPERTY name of the object.

Say for example I wanted to count Bear Pelts the player has. I set a property, call it BearPelts. Then I'd use GetItemCount(BearPelts).

But I can call my property whatever I wanted. I could call it TinkerbellB****. But as long as the property is linked to the object Bear Pelts, it'll count Bear Pelts.

SO:

GetItemCount(Claw01)

(Your property Claw01 says Coral next to it, so I'm guessing this property links to the dunYngolBarrowCoralClaw object)
User avatar
Prue
 
Posts: 3425
Joined: Sun Feb 11, 2007 4:27 am

Post » Mon Nov 19, 2012 6:32 pm

I still don't understand.
How do I fill that property then with a base object?

*Edit: Existing Claw01 is an Xmarker enable parent.
The comments are just so I know which Xmarker is a parent of which claw.
Basically

If Golden > 0
enable Claw01 ----->>> enables child as well = :biggrin:
Likewise for disable etc.
User avatar
Christine Pane
 
Posts: 3306
Joined: Mon Apr 23, 2007 2:14 am

Post » Mon Nov 19, 2012 5:57 pm

I don't think you're going about it the right way for what you want to do mate.

Example. There is a quest in the game to collect 10 Bear Pelts for a dude. The GetItemCount function counts the pelts the player has as they are in the Form List. The form list has all Bear Pelt types in it. And uses that list as the Bear Pelt global.

So if you have 2 Bear and 2 Cave Bear, it'll say you have 4 Bear Pelts. That's how a form list works in that scenario. How many items, of the list of items in the form list, does the player have. It can't tell you specifically which pelts.

I think you're best making a property for each claw object in your script. And using GetItemCount(ClawPropertyName). That's the way I'd go mate.

Make each claw a property (I think they are Misc Objects in the CK).
User avatar
Flash
 
Posts: 3541
Joined: Fri Oct 13, 2006 3:24 pm

Post » Mon Nov 19, 2012 5:06 pm

The claws are MiscItems. So at th top of your script you'd have some entries like

MiscItem Property dunDeadMensRubyDragonClaw Auto

And then fill/auto-fill those properties.

Then the erroneous code should work.

Basically because scripts are external, they don't know what any EditorID is unless you define it as a property of the script.
User avatar
OJY
 
Posts: 3462
Joined: Wed May 30, 2007 3:11 pm

Post » Mon Nov 19, 2012 12:39 pm

The claws are MiscItems. So at th top of your script you'd have some entries like

MiscItem Property dunDeadMensRubyDragonClaw Auto

And then fill/auto-fill those properties.

Then the erroneous code should work.

Basically because scripts are external, they don't know what any EditorID is unless you define it as a property of the script.

Awesome, thanks! I think I'll be ok for now.

MiscItem Property dunDeadMensRubyDragonClaw Auto

Types of "Property": MiscItem, ObjectReference, Int, etc .... Is it just me or is the valid syntax for this really hard to find on the creation kit wiki? (I had no idea you could have a MiscItem Property)
User avatar
Cool Man Sam
 
Posts: 3392
Joined: Thu May 10, 2007 1:19 pm

Post » Mon Nov 19, 2012 9:10 pm


Types of "Property": MiscItem, ObjectReference, Int, etc .... Is it just me or is the valid syntax for this really hard to find on the creation kit wiki. (I had no idea you could have a MiscItem Property)

The syntax is easy. Get out of the code, and look at the script's properties.

Add a Misc Object property (Goblets, Pelts, all the generic objects in the game). Call it whatever, and link it to an object.

In your script, you'll then see a line (automatically generated at the bottom of your script)

MiscObject Property PropertyName auto


If you made a quest property, it'd say:

Quest Property PropertyName auto


Do you get it now? :)
User avatar
Del Arte
 
Posts: 3543
Joined: Tue Aug 01, 2006 8:40 pm

Post » Mon Nov 19, 2012 4:46 pm

I'm starting to :)

I don't have any background in programming and I've put off learning Papyrus until now. I'm finding it a little challenging.
My mod is getting to the stage where I can't ignore it any longer :P

I do think Papyrus is vastly superior to the Oblivion scripting language. I actually love the property functionality. It allows the author to write a single flexible script and define certain parameters locally. Rather than have multiple scripts doing essentially the same things but in different places.
User avatar
Janeth Valenzuela Castelo
 
Posts: 3411
Joined: Wed Jun 21, 2006 3:03 am

Post » Mon Nov 19, 2012 11:23 am

I only ever learned scripting with the CK, so my thoughts mean nothing. But I also think its a good programming language and easy once you learn the basics :P
User avatar
le GraiN
 
Posts: 3436
Joined: Thu Mar 22, 2007 6:48 pm

Post » Mon Nov 19, 2012 1:45 pm

Types of "Property": MiscItem, ObjectReference, Int, etc .... Is it just me or is the valid syntax for this really hard to find on the creation kit wiki? (I had no idea you could have a MiscItem Property)

There's http://www.creationkit.com/Category:Script_Objects.

I imagine like any language, there's an unavoidable process of building up familiarity with the concepts and terminology, after which it starts to make enough sense that you can guess where to look for any information you don't know. I actually hadn't known about the above page until I went looking for it just now, but I know that Papyrus is pseudo-object oriented, so I knew to look for a page that lists those base objects.
User avatar
Ian White
 
Posts: 3476
Joined: Thu Jul 19, 2007 8:08 pm

Post » Mon Nov 19, 2012 2:00 pm

The strangest thing OP is 4 months ago I was in here begging for help from simple to complicated things. Now I'm here giving it lol. Not an expert like, but I like to help out the newer modders :)
User avatar
Flutterby
 
Posts: 3379
Joined: Mon Sep 25, 2006 11:28 am

Post » Mon Nov 19, 2012 10:12 pm

There's http://www.creationkit.com/Category:Script_Objects.

Ah I see. Very enlightening. Thank you.

@B1gBadDaddy: This community is a unique and special thing. Imagine the mods that never would have come to fruition if people weren't so willing to make the time and effort explain things and dissect problems. It's rather amazing how much people here look after each other.

*EDIT: 1st test run, fingers crossed
User avatar
Andrea P
 
Posts: 3400
Joined: Mon Feb 12, 2007 7:45 am

Post » Mon Nov 19, 2012 3:34 pm

Works like a charrrrrrrrrrm.

Probably the most stress-free script I've ever had the privilege of writing.

Thanks a lot everyone! I really appreciate it!!
User avatar
Stacey Mason
 
Posts: 3350
Joined: Wed Nov 08, 2006 6:18 am

Post » Mon Nov 19, 2012 8:27 pm

Final Script is here:

Spoiler

Scriptname MDHClawScriptCONTAINER extends ObjectReference {Toggles claw display based on contents of container (valid claws)}Bool Property Blocked = False  Auto HiddenMessage Property MessageWarning  AutoFormList Property ClawList  AutoActor Property PlayerREF AutoInt Property DisplayType = 6  Auto;MiscObject Property dunYngolBarrowCoralClaw AutoMiscObject Property dunSkuldafnDiamondClaw AutoMiscObject Property dunKorvanjundEbonyDragonClaw AutoMiscObject Property dunReachwaterRockEmeraldDragonClaw AutoMiscObject Property dunForelhostGlassClaw AutoMiscObject Property MS13GoldenClaw AutoMiscObject Property dunValthumeIronClaw AutoMiscObject Property dunFolgunthurIvoryDragonClaw AutoMiscObject Property dunDeadMensRubyDragonClaw AutoMiscObject Property FFI01Claw Auto;;                                     ClawXX refers to the Enable parents of claw displayObjectReference Property Claw01 Auto ;CoralObjectReference Property Claw02 Auto ;DiamondObjectReference Property Claw03 Auto ;EbonyObjectReference Property Claw04 Auto ;EmeraldObjectReference Property Claw05 Auto ;GlassObjectReference Property Claw06 Auto ;Golden Claw, handled uniquelyObjectReference Property Claw07 Auto ;IronObjectReference Property Claw08 Auto ;IvoryObjectReference Property Claw09 Auto ;RubyObjectReference Property Claw10 Auto ;SapphireObjectReference Property MDHClawCont Auto  ;Is container used for this scriptEvent OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)If (akSourceContainer == PlayerRef)  If (AllowedItems(akBaseItem))RegisterForSingleUpdate(0.1)  Else   MessageWarning.Show()   RemoveItem(akBaseItem, aiItemCount, False, PlayerRef)  EndIfElse  RemoveItem(akBaseItem, aiItemCount, False, akSourceContainer)EndIfEndEventEvent OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)If (akDestContainer == Game.GetPlayer())  RegisterForSingleUpdate(0.1)EndIfEndEventEvent OnUpdate()If (MDHClawCont.GetItemCount(dunYngolBarrowCoralClaw) > 0)Claw01.Enable()elseClaw01.Disable()endif;If (MDHClawCont.GetItemCount(dunSkuldafnDiamondClaw) > 0)  Claw02.Enable()else  Claw02.Disable()endif;If (MDHClawCont.GetItemCount(dunKorvanjundEbonyDragonClaw) > 0)Claw03.Enable()elseClaw03.Disable()endif;If (MDHClawCont.GetItemCount(dunReachwaterRockEmeraldDragonClaw) > 0)  Claw04.Enable()else  Claw04.Disable()endif;If (MDHClawCont.GetItemCount(dunForelhostGlassClaw) > 0)Claw05.Enable()elseClaw05.Disable()endif;If (MDHClawCont.GetItemCount(dunValthumeIronClaw) > 0)  Claw07.Enable()else  Claw07.Disable()endif;If (MDHClawCont.GetItemCount(dunFolgunthurIvoryDragonClaw) > 0)Claw08.Enable()elseClaw08.Disable()endif;If (MDHClawCont.GetItemCount(dunDeadMensRubyDragonClaw) > 0)  Claw09.Enable()else  Claw09.Disable()endif;If (MDHClawCont.GetItemCount(FFI01Claw) > 0)Claw10.Enable()elseClaw10.Disable()endifEndEventBool Function AllowedItems(Form akBaseItem)If (DisplayType == 6)  Return (ClawList.HasForm(akBaseItem))EndifEndFunction

Functionality: Checks contents of container for certain items. If (not) detected display friendly versions are (dis)enabled. Container only allows items conforming to a defined formlist to enter. All other items are returned to the giver.

Just in case this is useful to anyone.
Feel free to use as you wish. It should be noted that parts of the code come from or where inspired by AmethystDeceiver's Universal Item Display Script. Linked below:
http://www.gamesas.com/topic/1372057-universal-item-display-script-weapons-shields-potions-etc-mini-tutorial/
User avatar
Max Van Morrison
 
Posts: 3503
Joined: Sat Jul 07, 2007 4:48 pm

Post » Mon Nov 19, 2012 2:47 pm

Yay!

Now is usually the time when JustinOther posts to say that the next step is learning to use arrays. :tongue:
User avatar
Holli Dillon
 
Posts: 3397
Joined: Wed Jun 21, 2006 4:54 am

Post » Mon Nov 19, 2012 8:29 am

Yay!

Now is usually the time when JustinOther posts to say that the next step is learning to use arrays. :tongue:

Or to remove bits that aren't necessary :P
User avatar
Lavender Brown
 
Posts: 3448
Joined: Tue Jul 25, 2006 9:37 am

Post » Mon Nov 19, 2012 11:10 am

I've neglected to include the Golden Claw properly in the script I posted as I haven't written it in yet.
I'll update the post when that happens. Activation is automated upon progression through the quest "The Golden Claw" . Disabling the golden claw probably won't be a feature I'll include.

I'm all for optimization! :banana:
User avatar
Rodney C
 
Posts: 3520
Joined: Sat Aug 18, 2007 12:54 am

Post » Mon Nov 19, 2012 11:57 am

I'm all for optimization! :banana:
You've still a GetPlayer instance to replace with the PlayerREF property and you can lose all the '> 0', in that case. Also, you don't need the property for the container reference as stuff can be called implicitly.

Edit: You might not even need the check for PlayerREF unless other NPCs are adding/removing items to that container.

Now is usually the time when JustinOther posts to say that the next step is learning to use arrays. :tongue:
Arrays with corresponding indices would greatly simplify the script, yeah. Good call.

Spoiler
FormList Property ClawList AutoMiscObject[] Property kClawArray AutoMessage Property MessageWarning AutoObjectReference[] Property kClawReference AutoEvent OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	If ClawList.HasForm(akBaseItem)		Check()	Else		RemoveItem(akBaseItem, aiItemCount, False, akSourceContainer)		MessageWarning.Show()	EndIfEndEventEvent OnItemRemoved(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)	If ClawList.HasForm(akBaseItem)		Check()	EndIfEndEventFunction Check()	Int iIndex = kClawArray.Length	While iIndex > 0		iIndex -= 1 ; *		If GetItemCount(kClawArray[iIndex])			kClawReference[iIndex].Enable()		Else			kClawReference[iIndex].Disable()		EndIf	EndWhileEndFunction
*Fixed. Duh, I'd forgotten the countdown &--#62;_&--#60;
User avatar
Kieren Thomson
 
Posts: 3454
Joined: Sat Jul 21, 2007 3:28 am

Post » Mon Nov 19, 2012 9:09 pm

You've still a GetPlayer instance to replace with the PlayerREF property and you can lose all the '> 0', in that case.

Boom headshot! :D
User avatar
Ells
 
Posts: 3430
Joined: Thu Aug 10, 2006 9:03 pm

Post » Mon Nov 19, 2012 5:01 pm

Thanks for the new code.

What am I filling
MiscObject[] Property kClawArray Auto
with?

Also, kClawReference needs to be any one of 9 x markers. I don't think your code allows for this?
User avatar
Gavin Roberts
 
Posts: 3335
Joined: Fri Jun 08, 2007 8:14 pm

Post » Mon Nov 19, 2012 9:23 pm

The Claw MiscObjects in the same order as the enable parents in the other array.
User avatar
Matthew Barrows
 
Posts: 3388
Joined: Thu Jun 28, 2007 11:24 pm

Post » Mon Nov 19, 2012 12:55 pm

I assume that the claws are also in the formlist? Then really, I don't think you even need both the formlist and the MiscObject array.

Function Check()  Int iIndex = ClawList.GetSize() - 1  While iIndex >= 0	If GetItemCount(ClawList.GetAt(iIndex))	  kClawReference[iIndex].Enable()	Else	  kClawReference[iIndex].Disable()	EndIf	iIndex -= 1  EndWhileEndFunction

(Or something like that.)
User avatar
Anna S
 
Posts: 3408
Joined: Thu Apr 19, 2007 2:13 am

Post » Mon Nov 19, 2012 6:31 pm

This is a shot of what I'm working with.
http://i101.photobucket.com/albums/m57/will_cuthill/DragonClawSetup.png?t=1349407253

Dragon claw's go into the container on the left. Script checks for presence of claw.
If yes > Enable X MarkerYZ (Action is also applied to children which are the jar's seen below the markers)
If no > Disable X MarkerYZ (Action is also applied to children which are the jar's seen below the markers)

To clarify, I'm still confused about how to implement the array's into my script. Please keep in mind my novice grasp of Papyrus.

*EDIT:Sure I could directly toggle the Dragon Claw Jar's without the X Markers, but I just prefer it that way.
User avatar
SEXY QUEEN
 
Posts: 3417
Joined: Mon Aug 13, 2007 7:54 pm

Post » Mon Nov 19, 2012 2:01 pm

DreamKing: I'd thought about that, but cycling through an FLST in a While loop is substantially slower than an array, not to mention there's not currently an easy way to manipulate FLST members' indices. You could probably search the array and use it like a FormList, but since the FLST is already created...

Antares: I'd first fill the MiscObject array in alphabetical order from within the CK, then fill the ObjectReference array with the corresponding enable parents in the same order. Then, when cycling through either array, iIndex will line up between both arrays ensuring the correct display is enabled when any given claw is added/removed from the scripted container.
User avatar
trisha punch
 
Posts: 3410
Joined: Thu Jul 13, 2006 5:38 am

Post » Mon Nov 19, 2012 2:48 pm

Antares: I'd first fill the MiscObject array in alphabetical order from within the CK, then fill the ObjectReference array with the corresponding enable parents in the same order. Then, when cycling through either array, iIndex will line up between both arrays ensuring the correct display is enabled when any given claw is added/removed from the scripted container.

I know this is probably a silly question but how exactly do I define/fill an Array? I haven't used one before so........yeah.

*EDIT: Nevermind. It's done in the Editor Window.
User avatar
SiLa
 
Posts: 3447
Joined: Tue Jun 13, 2006 7:52 am

Next

Return to V - Skyrim