Hazuzi

ahzaab moreHUD method

Mar 17th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. The SetPlayerKnows will not work in most cases. Particularly if the enchanted item that you are checking was created by the player. That requires an extra step.
  2.  
  3. Here is the code I have in my plugin:
  4.  
  5. auto CAHZScaleform::GetIsKnownEnchantment(RE::TESObjectREFR* targetRef) -> uint32_t
  6. {
  7. if (!targetRef) {
  8. return 0;
  9. }
  10.  
  11. //auto pPC = RE::PlayerCharacter::GetSingleton();
  12. auto baseForm = targetRef->GetBaseObject();
  13.  
  14. if ((baseForm) &&
  15. (baseForm->GetFormType() == RE::FormType::Weapon ||
  16. baseForm->GetFormType() == RE::FormType::Armor ||
  17. baseForm->GetFormType() == RE::FormType::Ammo ||
  18. baseForm->GetFormType() == RE::FormType::Projectile)) {
  19. RE::EnchantmentItem* enchantment = nullptr;
  20. auto keyWordForm = baseForm->As<RE::BGSKeywordForm>();
  21. auto enchantable = baseForm->As<RE::TESEnchantableForm>();
  22. if (baseForm->GetFormType() == RE::FormType::Projectile) {
  23. enchantable = AHZGetForm(targetRef)->As<RE::TESEnchantableForm>();
  24. keyWordForm = AHZGetForm(targetRef)->As<RE::BGSKeywordForm>();
  25. }
  26.  
  27. bool wasExtra = false;
  28. if (enchantable) { // Check the item for a base enchantment
  29. enchantment = enchantable->formEnchanting;
  30. }
  31. if (auto extraEnchant = static_cast<RE::ExtraEnchantment*>(targetRef->extraList.GetByType(RE::ExtraDataType::kEnchantment))) {
  32. wasExtra = true;
  33. enchantment = extraEnchant->enchantment;
  34. }
  35.  
  36. if (enchantment) {
  37. if ((enchantment->formFlags & RE::TESForm::RecordFlags::kKnown) == RE::TESForm::RecordFlags::kKnown) {
  38. return MagicDisallowEnchanting(enchantment) ? 2 : 1;
  39. } else if (MagicDisallowEnchanting(enchantment)) {
  40. return 2;
  41. }
  42.  
  43. auto baseEnchantment = static_cast<RE::EnchantmentItem*>(enchantment->data.baseEnchantment);
  44. if (baseEnchantment) {
  45. if ((baseEnchantment->formFlags & RE::TESForm::RecordFlags::kKnown) == RE::TESForm::RecordFlags::kKnown) {
  46. return MagicDisallowEnchanting(baseEnchantment) ? 2 : 1;
  47. } else if (MagicDisallowEnchanting(baseEnchantment)) {
  48. return 2;
  49. }
  50. }
  51. }
  52.  
  53. // Its safe to assume that if it not a base enchanted item, that it was enchanted by the player and therefore, they
  54. // know the enchantment
  55. if (wasExtra) {
  56. return 1;
  57. } else if (enchantable) {
  58. return MagicDisallowEnchanting(keyWordForm) ? 2 : 0;
  59. }
  60. }
  61. return 0;
  62. }
  63.  
  64.  
  65. You will notice that I also have to check "ExtraEnchantment" for items enchanted by the player.
Advertisement
Add Comment
Please, Sign In to add comment