Jump to content

How to update corpses removal? - Communication Client -> Server


smajt

Recommended Posts

Hi... again...
so after a long hours of trying to make corpse removal i got to the point that i remove corpses but only on server side (after i respawn i dont see corpses, but everyone else sees it)

For testing purpouses I make that OnPlayerDeath event on server side and it worked then, but thats not what i need. I need it strict client -> server.

Here im sending player object to the server

function PlayerDataCollector.OnPlayerDeath(player)

    if PlayerDataCollector.isReviving then
        debugPrint("OnPlayerDeath - Player died while reviving. Skipping.")
        sendClientCommand("RevivingClient", "isReviving", { true })
        return
    end

    sendClientCommand("RevivingClient", "isReviving", { false })
    PlayerDataCollector.isReviving = true
end

 

 

Here im receiving it on the server and im putting player square to the array

function commandModule.RevivingClient.isReviving(player, args)
    if player ~= nil then
        if args[1] == true then
            debugPrint("RemovePlayersServer - OnPlayerDeath - Putting square to the alt list.")
            altDeathSquares[#altDeathSquares+1] = player:getSquare()
        elseif args[1] == false then
            debugPrint("RemovePlayersServer - OnPlayerDeath - Putting square to the list.")
            deathSquares[#deathSquares+1] = player:getSquare()
        end
    else
        debugPrint("RemovePlayersServer - isReviving - Player object is null.")
    end
end


Here im executing checks on the squares to see if there is a body

function OnTick(ticks)
    checkDeathSquares(deathSquares, bodyIds)
    checkDeathSquares(altDeathSquares, altBodyIds)
    clearDeadCorpses(bodyIds, false)
    clearDeadCorpses(altBodyIds, true)
end

 

function checkDeathSquares(squares, bodyids)
    for key, square in pairs(squares) do
        local bodies = square:getDeadBodys()

        if bodies == nil or bodies:size() == 0 then
            return
        end

        for i=0, bodies:size() - 1 do
            local body = bodies:get(i)
            bodyids[body:getObjectID()] = body
        end

        squares[key] = nil
    end
end

 

 

Here im deleting corpses and dropping player items on the ground
 

function clearDeadCorpses(bodyids, fullclear)
    for objectId, body in pairs(bodyids) do
        local bodysquare = body:getSquare()
        
        if not fullclear then
            local bodyinv = body:getContainer()
            local items = bodyinv:getItems()
            local itemsarray = {}

            if items then
                for i=1, items:size() do
                    local item = items:get(i-1)
                    table.insert(itemsarray, item)
                end
            end

            for i=1,#itemsarray do
                bodysquare:AddWorldInventoryItem(itemsarray[i], ZombRandFloat(0, 0.99), ZombRandFloat(0, 0.99), 0);
                bodyinv:Remove(itemsarray[i])
            end
        end

        bodysquare:removeCorpse(body, false)
        bodyids[objectId] = nil
    end
end


Unfortunately the lack of modding documentation with examples makes it more difficult to understand the problem
maybe someone more experienced with project zomboid modding could help me :D

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...