Desblat Posted February 5, 2014 Share Posted February 5, 2014 (edited) Hello, I am working on mod adding new mob - walking skeleton. I made him get random items on spawn. BUT if you save-load he doesn't keep items he got on first spawn he get new random items instead. How to make him keep items? Help, please. Here is the code: local function EquipWeapon(inst) if inst.components.inventory and not inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) then ----I believe checking this he should not lose items---weapon local weapon_type = WEAPONS[math.random(#WEAPONS)]local weapon = SpawnPrefab(weapon_type) inst.components.inventory:Equip(weapon) endend local function fn(Sim)........... inst:DoTaskInTime(10, EquipWeapon) ......end Edited February 5, 2014 by Desblat Link to comment https://forums.kleientertainment.com/forums/topic/31394-mod-help-how-to-save-prefab/ Share on other sites More sharing options...
dontstarver.wiki Posted February 5, 2014 Share Posted February 5, 2014 (edited) Hello, I am working on mod adding new mob - walking skeleton. I made him get random items on spawn. BUT if you save-load he doesn't keep items he got on first spawn he get new random items instead. How to make him keep items? Help, please. sounds like you haven't a onsave/onload function in your prefab. please check some other prefabs how "onsave,onload" works. example:local function OnSave(inst, data) if inst.colonyNum then data.colonyNum = inst.colonyNum endendlocal function OnLoad(inst, data) if data and data.colonyNum then inst.colonyNum = data.colonyNum local spawner = GetWorld().components.penguinspawner if spawner then spawner:AddToColony(inst.colonyNum,inst) end endendinto your prefab: inst.OnSave = OnSave inst.OnLoad = OnLoadregards Edited February 5, 2014 by dontstarver.wiki Link to comment https://forums.kleientertainment.com/forums/topic/31394-mod-help-how-to-save-prefab/#findComment-412724 Share on other sites More sharing options...
Desblat Posted February 6, 2014 Author Share Posted February 6, 2014 @dontstarver.wikiThanx, for help.Another question: "data" is variable which is saved by game? So in fuction "OnSave" I save data.itemhands, and in the "Onload" I can call data.itemhands ? Link to comment https://forums.kleientertainment.com/forums/topic/31394-mod-help-how-to-save-prefab/#findComment-412996 Share on other sites More sharing options...
Desblat Posted February 6, 2014 Author Share Posted February 6, 2014 (edited) Oh, tried this today. Got this error on saving game: LUA ERROR stack traceback:=[C] in function 'error'D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/dumper.lua(98,1)=(tail call) ?D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/dumper.lua(136,1)=(tail call) ?D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/dumper.lua(136,1)=(tail call) ?D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/dumper.lua(136,1)=(tail call) ?D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/dumper.lua(136,1)=(tail call) ?D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/dumper.lua(136,1)=(tail call) ?D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/dumper.lua(136,1)=(tail call) ?D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/dumper.lua(210,1) in function 'DataDumper'D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(566,1) in function 'SaveGame'D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/saveindex.lua(532,1) in function 'SaveCurrent'D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/screens/pausescreen.lua(55,1) in function 'cb'D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/frontend.lua(394,1) in function 'DoFadingUpdate'D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/frontend.lua(445,1) in function 'Update'D:/Program Files/Steam/steamapps/common/dont_starve/data/scripts/update.lua(46,1)scripts/frontend.lua(707,1) SCRIPT ERROR! Showing error screen Here is all the mod http://rghost.ru/52240458 Edited February 6, 2014 by Desblat Link to comment https://forums.kleientertainment.com/forums/topic/31394-mod-help-how-to-save-prefab/#findComment-413031 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