ElunaLuaEngine / Eluna

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

RegisterBGEvent - bg:GetMap(), (nil) missing metatable #426

Closed PerfectlyFineCode closed 2 years ago

PerfectlyFineCode commented 2 years ago

As title mentions, upon the callback of RegisterBGEvent, if you try to get the bg's map you will get (nil) missing metatable.

Am I doing something wrong?

function start(event, bg, bgId, instanceId)
    -- get players in the battleground
    local map = bg:GetMap()

    PrintInfo(map)
end

RegisterBGEvent(1, start)
Rochet2 commented 2 years ago

What core are you using? (TC, AC, mangos, cmangos, ...)

PerfectlyFineCode commented 2 years ago

What core are you using? (TC, AC, mangos, cmangos, ...)

Tried with both Azerothcore and Trinitycore from various versions, same result.

But let's say Azerothcore.

Rochet2 commented 2 years ago

The issue seems to be that GetMap in C++ returns a BattlegroundMap which is not supported/implemented. However, it is just a derivative of Map. This should fix it and makes the function return a Map as it is expected to according to Eluna documentation. https://github.com/ElunaLuaEngine/Eluna/commit/2eb527509051761f673d8b620b0dfdd81101787c

PerfectlyFineCode commented 2 years ago

The issue seems to be that GetMap in C++ returns a BattlegroundMap which is not supported/implemented. However, it is just a derivative of Map. This should fix it and makes the function return a Map as it is expected to according to Eluna documentation. 2eb5275

Unfortunately doesn't work. it returns (null) missing metatable now, and not (nil) missing metatable. at least it doesn't crash now which is a bonus, but it still doesn't work.

Code:

function start(event, bg, bgId, instanceId)
    -- get players in the battleground
    local map = bg:GetMap()

    -- if map is nil
    if map == nil then
        PrintInfo("GetMap returned nil")
        return
    end

    local players = map:GetPlayers()

    if players == nil then
        PrintInfo("players returned nil")
        return
    end

    -- loop through all players in the battleground
    for _, player in pairs(players) do
        -- get the player's team
        local team = player:GetTeam()
        PrintInfo("Got Player")
    end
    PrintInfo("end of start()")
end

RegisterBGEvent(1, start)

image

Rochet2 commented 2 years ago

Unfortunately doesn't work. at least it doesn't crash now which is a bonus, but it still doesn't work.

Are you still having the issue? If you are using azerothcore, they need to pull the latest changes to their eluna module (https://github.com/azerothcore/mod-eluna) On TC it should not occur if latest eluna is used.

it returns (null) missing metatable now, and not (nil) missing metatable.

I think that originally the error message was saying null, so the error probably did not change.