CharmedBaryon / CommonLibSSE-NG

This is a reverse engineered library for Skyrim Special Edition and Skyrim VR.
MIT License
142 stars 32 forks source link

Add `GetActorValueIdFromName` #10

Closed fireundubh closed 2 years ago

fireundubh commented 2 years ago

I use this function in LibFire.

Usage example:

if (const auto actor = a_ref->As<RE::Actor>(); actor) {
    const auto actorValueId = GetActorValueIdFromName(a_actorValue.c_str());  // <-- a_actorValue is of type RE::BSFixedString
    const auto actorValue = static_cast<RE::ActorValue>(actorValueId);
    return actor->GetPermanentActorValue(actorValue);
}
jpstewart commented 2 years ago

Thanks, been very busy this weekend, but I'll check this out after the weekend and update the PR.

powerof3 commented 2 years ago

This already exists as RE::ActorValueList::LookupActorValueByName

fireundubh commented 2 years ago

This already exists as RE::ActorValueList::LookupActorValueByName

How are you supposed to use this? edit: Got it.

if (const auto actor = a_ref->As<RE::Actor>(); actor) {
    const auto actorValueList = RE::ActorValueList::GetSingleton();
    const auto actorValueId = actorValueList->LookupActorValueByName(a_actorValue.c_str());
    const auto actorValue = static_cast<RE::ActorValue>(actorValueId);
    return actor->GetPermanentActorValue(actorValue);
}
powerof3 commented 2 years ago
if (const auto actor = a_ref->As<RE::Actor>(); actor) {
    const auto actorValue = RE::ActorValueList::GetSingleton()->LookupActorValueByName(a_actorValue);
    return actor->GetPermanentActorValue(actorValue);
}
fireundubh commented 2 years ago

Thanks, po3. This PR can be closed.

jpstewart commented 2 years ago

Closing as per the discussion above.