Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Here is the code I have in my plugin:
- auto CAHZScaleform::GetIsKnownEnchantment(RE::TESObjectREFR* targetRef) -> uint32_t
- {
- if (!targetRef) {
- return 0;
- }
- //auto pPC = RE::PlayerCharacter::GetSingleton();
- auto baseForm = targetRef->GetBaseObject();
- if ((baseForm) &&
- (baseForm->GetFormType() == RE::FormType::Weapon ||
- baseForm->GetFormType() == RE::FormType::Armor ||
- baseForm->GetFormType() == RE::FormType::Ammo ||
- baseForm->GetFormType() == RE::FormType::Projectile)) {
- RE::EnchantmentItem* enchantment = nullptr;
- auto keyWordForm = baseForm->As<RE::BGSKeywordForm>();
- auto enchantable = baseForm->As<RE::TESEnchantableForm>();
- if (baseForm->GetFormType() == RE::FormType::Projectile) {
- enchantable = AHZGetForm(targetRef)->As<RE::TESEnchantableForm>();
- keyWordForm = AHZGetForm(targetRef)->As<RE::BGSKeywordForm>();
- }
- bool wasExtra = false;
- if (enchantable) { // Check the item for a base enchantment
- enchantment = enchantable->formEnchanting;
- }
- if (auto extraEnchant = static_cast<RE::ExtraEnchantment*>(targetRef->extraList.GetByType(RE::ExtraDataType::kEnchantment))) {
- wasExtra = true;
- enchantment = extraEnchant->enchantment;
- }
- if (enchantment) {
- if ((enchantment->formFlags & RE::TESForm::RecordFlags::kKnown) == RE::TESForm::RecordFlags::kKnown) {
- return MagicDisallowEnchanting(enchantment) ? 2 : 1;
- } else if (MagicDisallowEnchanting(enchantment)) {
- return 2;
- }
- auto baseEnchantment = static_cast<RE::EnchantmentItem*>(enchantment->data.baseEnchantment);
- if (baseEnchantment) {
- if ((baseEnchantment->formFlags & RE::TESForm::RecordFlags::kKnown) == RE::TESForm::RecordFlags::kKnown) {
- return MagicDisallowEnchanting(baseEnchantment) ? 2 : 1;
- } else if (MagicDisallowEnchanting(baseEnchantment)) {
- return 2;
- }
- }
- }
- // Its safe to assume that if it not a base enchanted item, that it was enchanted by the player and therefore, they
- // know the enchantment
- if (wasExtra) {
- return 1;
- } else if (enchantable) {
- return MagicDisallowEnchanting(keyWordForm) ? 2 : 0;
- }
- }
- return 0;
- }
- 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