Jump to content

[LE] Getting when the player harvests from a flora


Recommended Posts

Hey guys,

 

I have a function that I need to run whenever the player harvests an ingredient from a flora. Unfortunately there's nothing like "OnHarvest" or anything in flora script so I'm looking for alternatives.

 

I have it working right now by watching the players inventory and if its an ingredient gets added, check the thing they're looking at and if its flora, run my function. It works...but it feels super shitty and inefficient.

 

Anyone have a better idea of how to do this?

Link to comment
Share on other sites

You can try using a formlist of all flora forms and listen for them through an OnItemAdded event.

 

That Event is just.. a mess though, but I don't know of another way to do this.

 

Edit: It sounds like that what you're already doing.

Edited by Rasikko
Link to comment
Share on other sites

I had a strange feeling about that, specifically the aiAcquireType parameter, and I tested it. Just as I thought, 0 and 4 will not detect items added to the inventory through harvesting. :/ And checking for them in a formlist via HasForm and doesn't work out either. Now it could be that I'm just not doing it right. But for all other types this event seems to be an amazing alternative to OnItemAdded. Just don't know how it handles stacked items.

Edited by Rasikko
Link to comment
Share on other sites

I did a bit more experimenting and came accross two ways to do this:

 

OnCrosshairRefChange and OnItemAdded

  • Register for the crosshair ref change and the OnItemAdded.
  • In the OnCrosshairRefChange, update a global variable with whatever thing the player is looking at.
  • When OnItemAdded gets triggered, check if the item is an ingredient. If it is, check the crosshair variable by casting it to a Flora.

If both are true, its probabbly a Flora that just got harvested.

 

OnActivate via QuestAliases

  • Create a dummy quest with a reference alias pointing to the nearest Flora.
  • Attach a script to it and use "OnActivate"

That OnActivate will trigger off of harvest since Flora's are also Activators.

 

Conclusion

 

Both approaches suck, but use the OnActivate approach, its more accurate.

 

The OnCrosshairRefChange approach is basically reads "I looted an ingredient and I'm looking at a flora therefore I'm harvesting". You aren't actually for sure harvesting something. It also falls apart if you don't immediately receive the ingredient for some reason, say there's some animation that happens when you harvest and the player happens to look away during the animation or something.

 

Also Salmon count as Flora for some reason so watch out for that lol

Edited by HOLYCRAPWHALES
Link to comment
Share on other sites

I did a bit more experimenting and came accross two ways to do this:

 

OnCrosshairRefChange and OnItemAdded

  • Register for the crosshair ref change and the OnItemAdded.
  • In the OnCrosshairRefChange, update a global variable with whatever thing the player is looking at.
  • When OnItemAdded gets triggered, check if the item is an ingredient. If it is, check the crosshair variable by casting it to a Flora.

If both are true, its probabbly a Flora that just got harvested.

 

OnActivate via QuestAliases

  • Create a dummy quest with a reference alias pointing to the nearest Flora.
  • Attach a script to it and use "OnActivate"

That OnActivate will trigger off of harvest since Flora's are also Activators.

 

Conclusion

 

Both approaches suck, but use the OnActivate approach, its more accurate.

 

The OnCrosshairRefChange approach is basically reads "I looted an ingredient and I'm looking at a flora therefore I'm harvesting". You aren't actually for sure harvesting something. It also falls apart if you don't immediately receive the ingredient for some reason, say there's some animation that happens when you harvest and the player happens to look away during the animation or something.

 

Also Salmon count as Flora for some reason so watch out for that lol

 

Forget salmon: So are coin purses.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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