Jump to content

[LE] RegisterForTrackedStatsEvent Ingredients Harvested / Eaten - Resource


Recommended Posts

So the RegisterForTrackedStatsEvent() function does not work for Ingredients Harvested or Ingredients Eaten. I created a workaround.

 

First create a formlist of all the keywords that these use such as VendorItemIngredient, VendorItemFood, and VendorItemFoodRaw etc. Create 2 global variables, one for Harvested and one for Eaten. Create a player alias and attached this script. Every time the player has an item added, or removed, and certain conditions are met (the item was added/removed in a certain way, and the item has the proper keyword), we compare our global variables (previous stat) to the current stat for these. If the stat is higher than the global variable of the previous stat, then we know the stat has increased. We set the value of the globals to the new stat value and then DO STUFF.

Pretty straight forward.

Edit:

FormList is of keywords :smile:

Scriptname IngredientStatTracking extends ReferenceAlias

;===============================================================
;;     Script to track when the player eats or harvests
;;     an ingredient.
;;
;;     Attach this to a quest alias assigned to the Player
;;
;;     Script courtesy of B1gBadDaddy
;===============================================================

FormList Property IngList01 Auto
GlobalVariable Property IngredientsHarvestedTotal Auto
GlobalVariable Property IngredientsEatenTotal Auto

;==================================================================
;;  TRACK WHENEVER THE PLAYER HARVESTS AN INGREDIENT.
;;  TO DO THAT WE CHECK EVERY TIME THE PLAYER HAS AN ITEM
;;  ADDED, AND IF THE SCENARIO MEETS THE CONDITION THAT
;;  WOULD HAPPEN IF IT WAS HARVESTED, PASS IT TO THE FUNCTION
;;  TO COMPARE THE BEFORE AND AFTER "HARVESTED" STAT.
;==================================================================
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

 if !akSourceContainer && !akItemReference
  ; Only track any added items for the following scenarios:
  ; If there was no original source container and no object reference
  IngredientHarvested(akBaseItem)
 endif

endif

endEvent

Event IngredientHarvested(Form akBaseItem)

 Int iList = IngList01.GetSize()
 
 while iList
  iList -= 1
  Keyword iKeyword = IngList01.GetAt(iList) as Keyword
  if akBaseItem.HasKeyword(iKeyword)

   Int OldCount = IngredientsHarvestedTotal.GetValue() as Int
   Int NewCount = Game.QueryStat("Ingredients Harvested")

   if NewCount > OldCount
    ; Ingredient was harvested, do stuff
    IngredientsHarvestedTotal.SetValue(NewCount)
    return

   endif

  endif
 endwhile

endEvent

;==================================================================
;;  TRACK WHENEVER THE PLAYER EATS AN INGREDIENT.
;;  TO DO THAT WE CHECK EVERY TIME THE PLAYER HAS AN ITEM
;;  REMOVED, AND IF THE SCENARIO MEETS THE CONDITION THAT
;;  WOULD HAPPEN IF IT WAS EATEN, PASS IT TO THE FUNCTION
;;  TO COMPARE THE BEFORE AND AFTER "EATEN" STAT.
;==================================================================
Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)

 if ( akDestContainer || akItemReference )
  ; Don't track any removed items for the following scenarios:
  ; if akDestContainer = If an item was removed by placing in another container
  ; if akItemReference = If an item was removed and still exists
  return
 else
  IngredientEaten(akBaseItem)
 endif

endEvent

Event IngredientEaten(Form akBaseItem)

 Int iList = IngList01.GetSize()
 
 while iList
  iList -= 1
  Keyword iKeyword = IngList01.GetAt(iList) as Keyword
  if akBaseItem.HasKeyword(iKeyword)

   Int OldCount = IngredientsEatenTotal.GetValue() as Int
   Int NewCount = Game.QueryStat("Ingredients Eaten")

   if NewCount > OldCount
    ; Ingredient was eaten, do stuff
    IngredientsEatenTotal.SetValue(NewCount)
    return

   endif

  endif
 endwhile

endEvent
Edited by B1gBadDaddy
Link to comment
Share on other sites

  • Recently Browsing   0 members

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