Jump to content

Photo

inconsistent GetItemHealthPercent() for Fusion Cores

papyrus

  • Please log in to reply
3 replies to this topic

#1
malernah

malernah

    Stranger

  • Members
  • Pip
  • 2 posts

I have a container with a custom script attached that fires the following event:

Scriptname FusionCoreCrateScript extends ObjectReference
{converts partial fusion cores into fusion core fragments and back}

Ammo Property AmmoFusionCore Auto
MiscObject Property FusionCoreFragment Auto

Event OnInit()
	AddInventoryEventFilter(AmmoFusionCore)
EndEvent

Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
	Debug.TraceAndBox("detected item: " + akItemReference)
	Float h = akItemReference.GetItemHealthPercent()
	If h == -1.00
		Debug.TraceAndBox("brand new core")
	Else
		; 99/100 = 1.00, 98/100 = 0.99, 71/100 = 0.72
		Debug.TraceAndBox("health: " + h)
		Debug.TraceAndBox("health * 100: " + h * 100)
		Debug.TraceAndBox("health as Int: " + (h * 100) as Int)
		Debug.TraceAndBox("should add " + (h * 100) as Int + " fragments")
		AddItem(FusionCoreFragment, (h * 100) as Int)
		RemoveItem(akItemReference)
	EndIf
	RemoveInventoryEventFilter(AmmoFusionCore)
	While GetItemCount(FusionCoreFragment) > 100
		AddItem(AmmoFusionCore)
		RemoveItem(FusionCoreFragment, 100)
	EndWhile
	AddInventoryEventFilter(AmmoFusionCore)
EndEvent

the script behaves inconsistently. On some cores, it reads its health no problems and adds the Fragment items to the container. On other fusion cores, it reads it as no health at all, and just puts the original fusion core into the container. I can't figure out any pattern to the different types of cores.



#2
ThoraldGM

ThoraldGM

    Fan

  • Premium Member
  • 498 posts
AddItem(FusionCoreFragment, (h * 100) as Int)

So you are saying if h == 0, you are getting 0 fragments?



#3
shavkacagarikia

shavkacagarikia

    Old Hand

  • Supporter
  • PipPipPip
  • 800 posts
AkItemReference is always none if object is not persistent ref

#4
malernah

malernah

    Stranger

  • Members
  • Pip
  • 2 posts

@shakacagarikia is correct, that is indeed what I am seeing. Some of the fusion cores show as None when added, and therefore read no attributes at all when I try to get its' health percentage, and some fusion cores read as [defaultdisablehavoconload <Item # in container (id here)>]

 

I guess my real question is how do I consistently get an ID for the fusion core?







Also tagged with one or more of these keywords: papyrus

Page loaded in: 0.780 seconds