Jump to content

Recommended Posts

i was trying to save a list of my character's followers. but it seems that i have no followers anymore, once the OnSave function from my character's prefab triggers.

when does OnSave actually trigger?

does the game remove the character on disconnect but only save it, once the server shuts down, or something like that?

is there something like a "OnDisconnect"/"OnConnect" function, or something like that, that i can use for this?

-- stuff happens after player left the serverlocal function OnPlayerLeft(world, player)	-- stuffendTheWorld:ListenForEvent("ms_playerleft", OnPlayerLeft)

Or

-- stuff happens after player despawns, before savinglocal function OnPlayerDespawn(world, player)	-- stuffendTheWorld:ListenForEvent("ms_playerdespawn", OnPlayerDespawn)

Or

-- you can make use of the extra despawn function that player_common calls when doing OnDespawninst._OnDespawn = function(inst)	-- stuffend

Or

-- do it wendy style, overriding the OnDespawn of player_commonlocal function OnDespawn(inst)	-- stuffendinst.OnDespawn = OnDespawn

When a player disconnects, he despawns and then his session gets serialized so OnSave gets triggered.

Edited by DarkXero

@DarkXero,

Thx for the help, there just one last problem i have right now:

Currently i save and remove all my followers with my character's OnDespawn function, and then put them into the savedata with the OnSave function.

However, iam not sure how the i should handle regular saving during gameplay(the game saves after each day for instance).

because if i just save my followers without removing them, then the game will also save the creature themselves, duplicating them, if i then load such a regular save.

So what i currently do, is to save and remove all my creature even on regular saves during gameplay, and then use

inst:DoTaskIntime(0,inst.OnLoad)
to spawn them again.

This works, however has some interupting effects and resets certain states and i was wondering, if there was a better way?

Also, does the game always save the characterprefabs before creatures? if not, then this might be another problem...

Edited by Seiai

@Seiai, from Krampusnacht mod I ported to DST:

function self:OnSave()	local data = {}	local references = {}	data.timeleft = self.timeleft	data.phase = self.phase	for k,v in pairs(self.krampuses) do		if not data.krampuses then			data.krampuses = {}		end				local krampus_data = {			GUID = v.GUID,			target = v.components.kidnapper.target and v.components.kidnapper.target.GUID,			kidnapping = v.components.kidnapper.kidnapping,			shouldkidnap = v.components.kidnapper.shouldkidnap,		}		table.insert(data.krampuses, krampus_data)		table.insert(references, krampus_data)	end	return data, referencesendfunction self:OnLoad(data)	if data then		self:SetTimer(data.timeleft)		self.phase = data.phase	endendfunction self:LoadPostPass(newents, savedata)	if savedata.krampuses then		for k,v in pairs(savedata.krampuses) do			local krampus = newents[v.GUID]			if krampus then				krampus = krampus.entity				local target = v.target				if target then					JoinKrampusnacht(krampus, GetTarget(v.target), v.kidnapping, v.shouldkidnap)				else					JoinKrampusnacht(krampus, nil)				end				TakeOwnership(krampus)			end		end	endend

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...