Sign in to follow this  
CanTotu

Ghosts dropping items

Recommended Posts

CanTotu    5

Well, I'm using Simple Protection mode which causes players spending less than 10 days in server drop their items when they leave server. 

 

I have the following code. However I want players having more than minimum days (which is 10) wont drop their items even when they become ghost. I just want to apply it for the players playing for 11 days or more for example.

AddComponentPostInit("playerspawner", function(PlayerSpawner, inst)    inst:ListenForEvent("ms_playerdespawn", function (inst, player)        if player and player.components and player.components.inventory and player.components.age then            if player.components.age:GetAgeInDays() < min_days then                player.components.inventory:DropEverything(false,false)            end        end    end)end)

I got confused lil bit. Any ideas about how to edit the code above?

Share this post


Link to post
Share on other sites
DarkXero    2886

A player despawning has nothing to do with becoming a ghost.

 

The item dropping occurs in the Wilson stategraph, in the death event:

AddStategraphPostInit("wilson", function(sg)   sg.events.death.fn = function(inst)        if inst.sleepingbag ~= nil and (inst.sg:HasStateTag("bedroll") or inst.sg:HasStateTag("tent")) then -- wakeup on death to "consume" sleeping bag first            inst.sleepingbag.components.sleepingbag:DoWakeUp()            inst.sleepingbag = nil        end        if inst.components.playercontroller ~= nil then            inst.components.playercontroller:Enable(false)        end        inst.sg:GoToState("death")        inst.SoundEmitter:PlaySound("dontstarve/wilson/death")                    if not inst:HasTag("mime") then            local sound_name = inst.soundsname or inst.prefab			inst.SoundEmitter:PlaySound("dontstarve/characters/"..sound_name.."/death_voice")		end                if inst.components.inventory and inst.components.age then           if inst.components.age:GetAgeInDays() < min_age then              inst.components.inventory:DropEverything(false, false)           end        end    endend)

Is what you want, in modmain.lua. You want to overwrite the current function on death that makes you drop things.

 

With this, the people who will drop stuff are people that when they die, they have less time than min_age.

Edited by DarkXero

Share this post


Link to post
Share on other sites
CanTotu    5

A player despawning has nothing to do with becoming a ghost.

 

The item dropping occurs in the Wilson stategraph, in the death event:

AddStategraphPostInit("wilson", function(sg)   sg.events.death.fn = function(inst)        if inst.sleepingbag ~= nil and (inst.sg:HasStateTag("bedroll") or inst.sg:HasStateTag("tent")) then -- wakeup on death to "consume" sleeping bag first            inst.sleepingbag.components.sleepingbag:DoWakeUp()            inst.sleepingbag = nil        end        if inst.components.playercontroller ~= nil then            inst.components.playercontroller:Enable(false)        end        inst.sg:GoToState("death")        inst.SoundEmitter:PlaySound("dontstarve/wilson/death")                    if not inst:HasTag("mime") then            local sound_name = inst.soundsname or inst.prefab			inst.SoundEmitter:PlaySound("dontstarve/characters/"..sound_name.."/death_voice")		end                if inst.components.inventory and inst.components.age then           if inst.components.age:GetAgeInDays() < min_age then              inst.components.inventory:DropEverything(false, false)           end        end    endend)

Is what you want, in modmain.lua. You want to overwrite the current function on death that makes you drop things.

 

With this, the people who will drop stuff are people that when they die, they have less time than min_age.

 

Thanks for help sir.

Share this post


Link to post
Share on other sites
DarkXero    2886

Try:

AddStategraphPostInit("wilson", function(sg)   sg.events.death.fn = function(inst)		if inst.sleepingbag ~= nil and (inst.sg:HasStateTag("bedroll") or inst.sg:HasStateTag("tent")) then			inst.sleepingbag.components.sleepingbag:DoWakeUp()			inst.sleepingbag = nil		end		if inst.components.playercontroller ~= nil then			inst.components.playercontroller:Enable(false)		end		inst.sg:GoToState("death")		inst.SoundEmitter:PlaySound("dontstarve/wilson/death")    		if not inst:HasTag("mime") then			local sound_name = inst.soundsname or inst.prefab			inst.SoundEmitter:PlaySound("dontstarve/characters/"..sound_name.."/death_voice")		end		if inst.components.inventory ~= nil then			if HUMAN_MEAT_ENABLED then				inst.components.inventory:GiveItem(SpawnPrefab("humanmeat"))			end			if inst.components.age then				if inst.components.age:GetAgeInDays() < 10 then					inst.components.inventory:DropEverything(true)				end			end		end    endend)

in modmain.lua

Share this post


Link to post
Share on other sites
CanTotu    5

Try:

AddStategraphPostInit("wilson", function(sg)   sg.events.death.fn = function(inst)		if inst.sleepingbag ~= nil and (inst.sg:HasStateTag("bedroll") or inst.sg:HasStateTag("tent")) then			inst.sleepingbag.components.sleepingbag:DoWakeUp()			inst.sleepingbag = nil		end		if inst.components.playercontroller ~= nil then			inst.components.playercontroller:Enable(false)		end		inst.sg:GoToState("death")		inst.SoundEmitter:PlaySound("dontstarve/wilson/death")    		if not inst:HasTag("mime") then			local sound_name = inst.soundsname or inst.prefab			inst.SoundEmitter:PlaySound("dontstarve/characters/"..sound_name.."/death_voice")		end		if inst.components.inventory ~= nil then			if HUMAN_MEAT_ENABLED then				inst.components.inventory:GiveItem(SpawnPrefab("humanmeat"))			end			if inst.components.age then				if inst.components.age:GetAgeInDays() < 10 then					inst.components.inventory:DropEverything(true)				end			end		end    endend)

in modmain.lua

Solved, thanks.

Share this post


Link to post
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
Sign in to follow this