Jump to content

Properly handling player leave

Recommended Posts

I'm trying to make the following happen: When a player leaves the server, he drops all his items.
But, I've hit a wall.. I just don't know what happens to his inventory when he's leaving.
Here's what I'm doing:

AddPlayerPostInit( function (inst)    inst:AddTag("recently_joined")        inst.oldOnRemoveEntity = inst.OnRemoveEntity        inst.OnRemoveEntity = function ( inst )        print("Player ", inst.name, "has left")        print("inst.components.health.current",inst.components.health.currenthealth)        print("inst.components.hunger",inst.components.hunger.current)        print("inst.components.inventory:GetActiveItem()",inst.components.inventory:GetActiveItem() or inst.components.inventory:GetActiveItem() ~= nil)                inst.components.inventory:DropEverything(false, false)                return inst:oldOnRemoveEntity( inst )    endend)

When my friend "Meow" leaves the server, this is the console output:

Player Meow has leftinst.components.health.current 150inst.components.hunger 30.24inst.components.inventory:GetActiveItem() false

She doesn't drops any items neither. Testing for the inventory component shows it's missing too.
My question is, how can I grab the inventory before it's saved/cleared somewhere else?

Link to comment
Share on other sites

Welp, found it, it was in playerspawner. Just in case anyone is wondering:

AddComponentPostInit("playerspawner", function(PlayerSpawner, inst)    inst:ListenForEvent("ms_playerdespawn", function (inst, player)        player.components.inventory:DropEverything(false,false)    end)end)
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...