Seiai Posted May 6, 2015 Share Posted May 6, 2015 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? Link to comment https://forums.kleientertainment.com/forums/topic/53571-is-there-a-ondisconnect-function/ Share on other sites More sharing options...
Sheepolution Posted May 6, 2015 Share Posted May 6, 2015 In mainfunctions.lua there is OnPlayerLeave and OnNetworkDisconnect, but I can't find the functions being called anywhere, so either they are used C++ sided, or not at all. Link to comment https://forums.kleientertainment.com/forums/topic/53571-is-there-a-ondisconnect-function/#findComment-634932 Share on other sites More sharing options...
DarkXero Posted May 6, 2015 Share Posted May 6, 2015 (edited) -- 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) -- stuffendOr-- do it wendy style, overriding the OnDespawn of player_commonlocal function OnDespawn(inst) -- stuffendinst.OnDespawn = OnDespawnWhen a player disconnects, he despawns and then his session gets serialized so OnSave gets triggered. Edited May 6, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/53571-is-there-a-ondisconnect-function/#findComment-634959 Share on other sites More sharing options...
Seiai Posted May 17, 2015 Author Share Posted May 17, 2015 (edited) @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 useinst: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 May 17, 2015 by Seiai Link to comment https://forums.kleientertainment.com/forums/topic/53571-is-there-a-ondisconnect-function/#findComment-638250 Share on other sites More sharing options...
Kzisor Posted May 17, 2015 Share Posted May 17, 2015 @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 Link to comment https://forums.kleientertainment.com/forums/topic/53571-is-there-a-ondisconnect-function/#findComment-638329 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now