azerothcore / mod-eluna

Eluna Lua Engine © for WoW Emulators
https://elunaluaengine.github.io/
GNU General Public License v3.0
96 stars 126 forks source link

Feature: Add Creature:GetCreatureByEntry(entry) as well as Global GetCreatureTemplate(entry) #143

Closed New-HavenWotLK closed 1 year ago

New-HavenWotLK commented 1 year ago

Integrated 2 new methods to gain creature entries =)

New-HavenWotLK commented 1 year ago

@Helias / @r-o-b-o-t-o: got one more for you if u got some time...

I am on fire! =D

55Honey commented 1 year ago

Thanks for the PR. I'm not sure if the naming of the new methods is consistent with the core. Interested to hear what others think.

Helias commented 1 year ago

Thanks for the PR. I'm not sure if the naming of the new methods is consistent with the core. Interested to hear what others think.

Are you referring to GetCreatureById(entry)? we could call it GetCreatureTemplate to be more coherent with the core, what do you think?

New-HavenWotLK commented 1 year ago

Thanks for the PR. I'm not sure if the naming of the new methods is consistent with the core. Interested to hear what others think.

Are you referring to GetCreatureById(entry)? we could call it GetCreatureTemplate to be more coherent with the core, what do you think?

can change the global method according to that =) would have no problem with it... just wanted in the end a naming difference for both methods that it is clear which is which ^^

New-HavenWotLK commented 1 year ago

Sooo... changed now the global method to GetCreatureTemplate(entry) =)

Let me know in case u want me to change the creature method as well a bit ;)

r-o-b-o-t-o commented 1 year ago

Reading this again, I'm not sure what you're trying to achieve with GetCreatureByEntry? You're returning a CreatureTemplate which is not even registered in Eluna 🤔

New-HavenWotLK commented 1 year ago

Reading this again, I'm not sure what you're trying to achieve with GetCreatureByEntry? You're returning a CreatureTemplate which is not even registered in Eluna 🤔

wanted in the end a creature method to gain directly a creature with a specifc entry so it doesn't need a for loop iteration inside a function to get a specific creature via creaturesInRange(range, entry) The global one i made in the end so we can make an array of npc's and iterate then over this array on e.g. creaturedeath for all those creatures without the need of extra writing for every single creature a RegisterCreatureEvent line ^^

would the creature method eventually be accomplishable with this changed version here:

int GetCreatureByEntry(lua_State* L, Creature* creature)
    {
        uint32 entry = creature->GetEntry();
        CreatureTemplate const* cEntry = sObjectMgr->GetCreatureTemplate(entry);
        if (cEntry)
            Eluna::Push(L, cEntry->Entry);

        return 1;
    }
GoMateoGo commented 1 year ago

Can you tell me your ultimate goal? :)

New-HavenWotLK commented 1 year ago

Can you tell me your ultimate goal? :)

the goal behind this is to get specific creatures e.g. at the same bossroom and to activate them after a specific time...

means... they already are spawned in but are kinda "deactivated" i want then in the end that boss gains the creature with entry xyz after e.g. 60 secs and activates them... but without the need of a for loop where it retreives the creatures out of a table from GetCreaturesInRange(range, entry)

so kinda like:

local function WaveOneCheck(event, delay, repeats, creature)
    local check = creature:GetCreatureByEntry(NPC_EXAMPLE)
    local checkFlags = check:GetUnitFlags()

    if checkFlags == creatureFlags then
        check:SetUnitFlags(UNIT_FLAGS_NONE)
        WaveOneOnCombat(event, creature, target)
    end
end

and this then registered via creature:RegisterEvent(WaveOneCheck, 60000, 1)

New-HavenWotLK commented 1 year ago

anyways...

it might not be my best idea... ROFL... was kinda stoned when i had this idea... ahahaha

so just let me know if u want me to scrap the creature method since the global method would also be more than enough in the end ^^

since then it still is checkable via the global one and IsInRange(target, range)

GoMateoGo commented 1 year ago

According to your code, you should have already obtained creaturePtr

So there's no need to obtain creation through Entry again. Relying solely on Entry is not enough Entry is just an Index

All operations on Creature are performed through class pointers, not Creature ->entry

My guess:

You want to rewrite some boss AI within a replica

Are you currently obtaining CreaturePtr through GetCreaturesInRange?

But based on the code you displayed, you have already obtained it