• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore WotLK Performingamespawn Disapear

TheDoctor

Emulation Addict
Hey guys, got a problem on new Core with fresh Eluna.
After execute this:
PerformIngameSpawn(2, g_id, plr_map, plr_in, x, y, z, plr_o, true)

the Ingamespawn is set up in the DB, but the gameobject shows only after a server restart, but i need the object right at the moment of the script execution.
So anyone knows a way to fix it?
 

Grandelf

Esteemed Member
You seem to be correct, the gameobject doesn't appear when you save it to the database.
When you do not save it to the database however, it appears right away.
This could be a solution, even though it's not the most elegant one.

So one way to solve your problem is to have two PerformIngameSpawn's, one that does
save the gameobject to the database and one that doesn't.
Code:
PerformIngameSpawn(2, g_id, plr_map, plr_in, x, y, z, plr_o, true)
PerformIngameSpawn(2, g_id, plr_map, plr_in, x, y, z, plr_o, false)
 

westtunger

Emulation Addict
You seem to be correct, the gameobject doesn't appear when you save it to the database.
When you do not save it to the database however, it appears right away.
This could be a solution, even though it's not the most elegant one.

So one way to solve your problem is to have two PerformIngameSpawn's, one that does
save the gameobject to the database and one that doesn't.
Code:
PerformIngameSpawn(2, g_id, plr_map, plr_in, x, y, z, plr_o, true)
PerformIngameSpawn(2, g_id, plr_map, plr_in, x, y, z, plr_o, false)

Thank you, i had the same problem.

But your way isn't the best since it's impossible to delete the in game gameobject before restarting.

I think it's better to modify the PerformIngameSpawn() script like the gobject command:


(In GlobalMethods.h, row 1720)
Code:
                // fill the gameobject data and save to the db
                object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase);
		guidLow = object->GetSpawnId();

		delete object;

		object = new GameObject();
                // this will generate a new lowguid if the object is in an instance
                if (!object->LoadGameObjectFromDB(guidLow, map))
                {
                    delete object;
                    Eluna::Push(L);
                    return 1;
                }

                eObjectMgr->AddGameobjectToGrid(guidLow, eObjectMgr->GetGOData(guidLow));


So you'll be able to delete the gobject and see it like if you used the command with only one row.
 

Rochet2

Moderator / Eluna Dev
It seems this was broken due to a recent change in TC.
[MENTION=2484]westtunger[/MENTION] Can you perhaps make a pull request about the fix? And maybe instead do it like it is done in the TC repo cs_gobject.cpp?
Actually I think there needs to be a bit more edits than just that. For example the entry in Create function call.
 
Last edited:

westtunger

Emulation Addict
It seems this was broken due to a recent change in TC.
[MENTION=2484]westtunger[/MENTION] Can you perhaps make a pull request about the fix? And maybe instead do it like it is done in the TC repo cs_gobject.cpp?
Actually I think there needs to be a bit more edits than just that. For example the entry in Create function call.

What do you mean by doing it like in the tc repo ?

This is the same as the cs_gobject i looked :
Code:
    static bool HandleGameObjectAddCommand(ChatHandler* handler, char const* args)
    {
        if (!*args)
            return false;

        // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
        char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
        if (!id)
            return false;

        uint32 objectId = atoul(id);
        if (!objectId)
            return false;

        char* spawntimeSecs = strtok(NULL, " ");

        const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);

        if (!objectInfo)
        {
            handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, objectId);
            handler->SetSentErrorMessage(true);
            return false;
        }

        if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
        {
            // report to DB errors log as in loading case
            TC_LOG_ERROR("sql.sql", "Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", objectId, objectInfo->type, objectInfo->displayId);
            handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, objectId);
            handler->SetSentErrorMessage(true);
            return false;
        }

        Player* player = handler->GetSession()->GetPlayer();
        float x = float(player->GetPositionX());
        float y = float(player->GetPositionY());
        float z = float(player->GetPositionZ());
        float o = float(player->GetOrientation());
        Map* map = player->GetMap();

        GameObject* object = new GameObject;
        ObjectGuid::LowType guidLow = map->GenerateLowGuid<HighGuid::GameObject>();

        if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
        {
            delete object;
            return false;
        }

        if (spawntimeSecs)
        {
            uint32 value = atoi((char*)spawntimeSecs);
            object->SetRespawnTime(value);
        }

        // fill the gameobject data and save to the db
        object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
        guidLow = object->GetSpawnId();

        // delete the old object and do a clean load from DB with a fresh new GameObject instance.
        // this is required to avoid weird behavior and memory leaks
        delete object;

        object = new GameObject();
        // this will generate a new guid if the object is in an instance
        if (!object->LoadGameObjectFromDB(guidLow, map))
        {
            delete object;
            return false;
        }

        /// @todo is it really necessary to add both the real and DB table guid here ?
        sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));

        handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, objectId, objectInfo->name.c_str(), guidLow, x, y, z);
        return true;
    }

So ->

Code:
       if (spawntype == 2) // Spawn object
        {
            const GameObjectTemplate* objectInfo = eObjectMgr->GetGameObjectTemplate(entry);
            if (!objectInfo)
            {
                Eluna::Push(L);
                return 1;
            }

            if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
            {
                Eluna::Push(L);
                return 1;
            }

            GameObject* object = new GameObject;
            uint32 guidLow = map->GenerateLowGuid<HighGuid::GameObject>();

            if (!object->Create(guidLow, objectInfo->entry, map, phase, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
            {
                delete object;
                Eluna::Push(L);
                return 1;
            }

            if (durorresptime)
                object->SetRespawnTime(durorresptime);

            if (save)
            {
                // fill the gameobject data and save to the db
                object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase);
		guidLow = object->GetSpawnId();


                // delete the old object and do a clean load from DB with a fresh new GameObject instance.
                // this is required to avoid weird behavior and memory leaks
		delete object;

		object = new GameObject();
                // this will generate a new lowguid if the object is in an instance
                if (!object->LoadGameObjectFromDB(guidLow, map))
                {
                    delete object;
                    Eluna::Push(L);
                    return 1;
                }

                eObjectMgr->AddGameobjectToGrid(guidLow, eObjectMgr->GetGOData(guidLow));
            }
            else
                map->AddToMap(object);
            Eluna::Push(L, object);
            return 1;
        }

ps : i created the pull request.
 
Last edited:
Top