igel69 Posted July 10, 2021 Share Posted July 10, 2021 Hello. Here is my problem : I have a modcharacter than gains health sanity and hunger when eating meatrelated stuff. Problem is that the stats reset after rejoining the world. Modmain and Prefab.lua attached. Thanks in advance modmain.lua esctemplate.lua Link to comment https://forums.kleientertainment.com/forums/topic/131737-permanent-statsgain-resets-after-relogging/ Share on other sites More sharing options...
Thomas_klei Posted July 11, 2021 Share Posted July 11, 2021 (edited) I've think you've seen from the esctemplate that it has a onsave and onload function: these functions save and load data so that the data stays after leaving and rejoining. you'll need to save the data first which should start by creating the variable to be saved but instead of local you should save it to the player so inst.variable_name = 0 -- or nil --above inst.onsave cus it needs to be created before being called than simply have inst.variable_name = data given to add to the data being save local function OnSave (inst, data) --inst is you the object, and data is data :] data.variable_name = inst.variable_name --saving the data you have to the data to be saved end local function onload(inst, data) --loading the data you saved if data ~= nil and data.variable_name ~= nil then --checking the data is saved/there inst.varaible_name = data.variable_name --re-introducing the data which was saved end end btdubs if the esctemplate doesn't already have a save function simpy put --inst.vairable_name = 0--data inst.OnSave = function_name Edited July 11, 2021 by Thomas Die Link to comment https://forums.kleientertainment.com/forums/topic/131737-permanent-statsgain-resets-after-relogging/#findComment-1477796 Share on other sites More sharing options...
igel69 Posted July 11, 2021 Author Share Posted July 11, 2021 17 hours ago, Thomas Die said: I've think you've seen from the esctemplate that it has a onsave and onload function: these functions save and load data so that the data stays after leaving and rejoining. you'll need to save the data first which should start by creating the variable to be saved but instead of local you should save it to the player so inst.variable_name = 0 -- or nil --above inst.onsave cus it needs to be created before being called than simply have inst.variable_name = data given to add to the data being save local function OnSave (inst, data) --inst is you the object, and data is data :] data.variable_name = inst.variable_name --saving the data you have to the data to be saved end local function onload(inst, data) --loading the data you saved if data ~= nil and data.variable_name ~= nil then --checking the data is saved/there inst.varaible_name = data.variable_name --re-introducing the data which was saved end end btdubs if the esctemplate doesn't already have a save function simpy put --inst.vairable_name = 0--data inst.OnSave = function_name So I tried copying what you told me but it still isnt working I attached the prefab and the client log if that helps it doesnt crash or anything but the stats just still dont get saved esctemplate.lua client_log.txt Link to comment https://forums.kleientertainment.com/forums/topic/131737-permanent-statsgain-resets-after-relogging/#findComment-1477912 Share on other sites More sharing options...
Monti18 Posted July 12, 2021 Share Posted July 12, 2021 Here, I fixed it for you. You would have needed to save the health, hunger and sanity as a variable to make it load. Also you forgot the data argument in the onload function. esctemplate.lua 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/131737-permanent-statsgain-resets-after-relogging/#findComment-1478032 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