Wishmaster
Wishmaster

Reputation: 1

Elunas script issues

Hi guys i'm working on a hardcore like script but i'm facing a issue, in this function, when the player die, i spawn a grave that is a gob (that is a chest), and i want that all the stuff that the player have goes to this chest, but i have two issues:

The first issue is that the chest desappear when the player resurect and not after the time i specified here:

local secondsInADay = 86400
local event = CreateLuaEvent(function()
if grave and grave:IsInWorld() then
grave:Despawn()
end
end, secondsInADay * 1000, 1)

The second issue is that the stuff of the player don't go in the GOB.

local function CreateGrave(player)
if player:GetLevel() < 15 then
return
end
local chestGameObjectEntry = 8000015 -- Utilisez l'ID du modèle de coffre que vous souhaitez
local secondsInADay = 86400 -- Durée pendant laquelle le cimetière restera spawn en secondes (1 jour)
local x, y, z, o = player:GetLocation()
local grave = player:SummonGameObject(chestGameObjectEntry, x, y, z, o)
if grave then
    local graveGUID = grave:GetGUIDLow() -- Obtenir le GUID du gardien d'âmes
    for slot = 0, 18 do
        local item = player:GetItemByPos(255, slot) -- Emplacement des équipements
        if item then
            grave:AddLoot(item:GetEntry(), 22) -- Ajouter l'objet au coffre (1 quantité)
        end
    end
    for bag = 19, 22 do
        for slot = 0, 35 do
            local item = player:GetItemByPos(bag, slot) -- Emplacement des sacs équipés
            if item then
                grave:AddLoot(item:GetEntry(), 5) -- Ajouter l'objet au coffre (1 quantité)
            end
        end
    end
    local event = CreateLuaEvent(function()
        if grave and grave:IsInWorld() then
            grave:Despawn()
        end
    end, secondsInADay * 1000, 1)
    print("Tombe (Coffre) GUID: " .. graveGUID)
    local input_Grave_GUID = "UPDATE hc_dead_log SET grave_guid = '" .. graveGUID .. "' WHERE guid = '" .. player:GetGUIDLow() .. "'"
    AuthDBExecute(input_Grave_GUID)
end
end

Someone have a tip for me?

Thanks in advance.

Upvotes: 0

Views: 159

Answers (1)

iThorgrim
iThorgrim

Reputation: 1

I took the liberty of rewriting your code.

The despawn problem is fixed and to see the loot of your object you need to update your gameobject like this :

UPDATE `gameobject_template` SET `Data1` = 0 WHERE (`entry` = 8000015);

For your lua script I allowed myself a few optimizations and reworking :

local Constant = {
    GameObjectEntry = 8000015,
    SecondsInDelay = 86400,
}

local function print_format(msg, values)
    print(string.format(msg, table.unpack(values)))
end

local function AddItemToObject(object, item)
    if ( item ) then
        local item_entry = item:GetEntry()
        local item_count  = item:GetCount()
        object:AddLoot(item_entry, item_count)
        print_format("Log:: Gameobject GUID %s now contains item %s in %s exemplars.", {object:GetGUIDLow(), item_entry, item_count})
    end
end

local function OnPlayerDied(player)
    local player_level = player:GetLevel()
    if ( player_level < 15 ) then return end

    local object = player:SummonGameObject(Constant.GameObjectEntry, player:GetLocation())
    if ( object ) then
        local object_guid = object:GetGUIDLow()
        print_format("Log:: Gameobject GUID %s as spawn", {object_guid})

        for slot = 0, 22 do
            if ( slot <= 18 ) then
                AddItemToObject(object, player:GetItemByPos(255, slot))
            end
            if ( slot >= 19 ) then
                for bag_slot = 0, 35 do
                    AddItemToObject(object, player:GetItemByPos(slot, bag_slot))
                end
            end
        end

        object:RegisterEvent( function(_, _, _, game_object)
            game_object:Despawn()
            print_format("Log:: Gameobject GUID %s as despawn", {object_guid})
        end, Constant.SecondsInDelay * 1000, 1 )
    end
end

Best regards, iThorgrim

Upvotes: 0

Related Questions