xovoxx

  • Content Count

    26
  • Joined

  • Last visited

Community Reputation

12 Good

About xovoxx

  • Rank
    Junior Member
...

Badges

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Enable
  1. Hello all, I'm trying to identify an instance of a prefab. I'm guessing that all instances have an ID... but I don't know where to find the variable name. Can I access it with inst.id? inst.entity.id? or something else? Is there documentation somewhere to help me figure this out? Any help is appreciated!
  2. Ok. Is there documentation somewhere that would help me find a way to do this? I feel like if I could access the game's name, and/or the eater instance's ID, I could make it a part of the string and basically make my persistent string related to that specific game.
  3. That worked! but that raises two questions : 1. Why do I sometimes need to call "Global" before "TheSim", and sometimes I don't need to? 2. The persistent string is saved across games. So even if I erase my game and start a new one, my progress remains. How can I prevent this? Thanks a lot for the help as always!
  4. Thank you, that worked! Now I'm at the next step : Getting the persistent string. Here's my code : AddPrefabPostInit("mole", function(inst) TheSim:GetPersistentString("meal", function(load_success, str) if load_success and str == "1" then -- Do stuff end end) end) For some reason, whenever I resume an existing server, my mod crashes during the loading with the error : attempt to index global 'TheSim' (a nil value) On the second line of my function. This occurs regardless of the "meal" persistent string existing or not. I checked and double checked my syntax : it looks like it's fine. Is it because I can't call "TheSim" during the PostInit? Thanks again for all the help!
  5. Thank you for the fast reply! However, there seems to be something I don't understand. I get the error "attempt to call method 'SavePersistentString' (a nil value)". Looking at DST's code, it looks like I'm using the function alright... so there's definitely something I don't understand. Here's my function : local function OnEatFirstMeal(inst) local cb = function() --Do nothing end inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.TIER2 }) inst.components.inspectable:SetDescription("Seems like shinies are his goal. Surely, it would eat gold?") SpawnPrefab("red_mushroomhat").Transform:SetPosition(inst.Transform:GetWorldPosition()) inst.components.eater:SetOnEatFn(OnEatSecondMeal) TheSim:SavePersistentString("meal","1",false,cb)--Save first meal end Do I need some sort of "include"? What am I missing? Thanks in advance!
  6. Hello all, I am making a mod where players can "progress" by feeding a character. I got the progression down and working great, with lots of help from the nice people of this forum! However, while testing my mod, I realize that if the server is shut down and restarted, all "progress" is lost. I'm looking for a way to save the status of the fed character, so that players don't have to start over if they take a break. Thank you!
  7. OMG that did it. Thanks a lot! I thought for sure that prefabs had the same "ID" as the name of their file... Thanks!
  8. Thanks @penguin0616 ! That makes sense. That being said, I get the same result as before. Here's my updated "modmain" code : GLOBAL.FOODTYPE.TIER2 = "TIER2" AddPrefabPostInit("gem",function(inst) inst:AddComponent("edible") inst.components.edible.foodtype = GLOBAL.FOODTYPE.TIER2 inst.components.edible.healthvalue = 10 inst.components.edible.hungervalue = 20 inst.components.edible.sanityvalue = 5 end) local function OnEatFirstMeal(inst) inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.TIER2 }) inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.") SpawnPrefab("flowerhat").Transform:SetPosition(inst.Transform:GetWorldPosition()) end AddPrefabPostInit("mole", function(inst) inst.components.eater:SetOnEatFn(OnEatFirstMeal) -- will now trigger whenever moleworm eats something end) I should note that the description does get updated to "He looks better, but still hungry! He would love something shiny." Thanks a lot for your help! I'm learning a lot thanks to your input
  9. /facepalm that couldn't have helped. However, I fixed it and it doesn't work any better. Is there a way to add this function to modmain? Instead of having it in mole.lua, where it currently is. local function OnEatFirstMeal(inst) inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") inst.components.eater:SetDiet({ FOODTYPE.TIER2 }) if numberOfMeals == 0 then inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.") SpawnPrefab("flowerhat").Transform:SetPosition(inst.Transform:GetWorldPosition()) end if numberOfMeals == 1 then inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") SpawnPrefab("amulet").Transform:SetPosition(inst.Transform:GetWorldPosition()) end numberOfMeals = numberOfMeals + 1 end
  10. @penguin0616 I'll try to rephrase what I'm trying to do. I'm probably not clear enough! What I want to happen : - Feed the moleworm any "ELEMENTAL" food once. - Then, I want to be able to feed "TIER2" food, and only "TIER2" food, to the moleworm What actually happens : - I feed the moleworm any "ELEMENTAL" food once, successfully. - Then, when I attempt to feed the red gem (A "TIER2" food item, thanks to the script in modmain) to the moleworm, the "feed" prompt does not show up. - Additionally, any "ELEMENTAL" food is no longer accepted (the "feed" prompt does not show up). Does that make more sense?
  11. Okay... I'm not sure I understand what you're suggesting. The mole.lua prefab already contains inst.components.eater:SetDiet({FOODTYPE.ELEMENTAL}) I did not remove it. What more am I supposed to do?
  12. Even if it's for an existing NPC? (I'm editing the moleworm) Also, I added the following to my modmain : GLOBAL.FOODTYPE.TIER2 = "TIER2" AddPrefabPostInit("gem",function(inst) inst:AddComponent("edible") inst.components.edible.foodtype = GLOBAL.FOODTYPE.TIER2 inst.components.edible.healthvalue = 10 inst.components.edible.hungervalue = 20 inst.components.edible.sanityvalue = 5 end) Which seems to work. However, this is still not working : local function OnEatFirstMeal(inst) inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") inst.components.eater:SetDiet({ FOODGROUP.TIER2 }) if numberOfMeals == 0 then inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.") end if numberOfMeals == 1 then inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") end numberOfMeals = numberOfMeals + 1 end What happens is this : - I feed the moleworm his usual meal (Since it has its usual diet, that I did not change). - After feeding it once, it looks as if the game did not recognize my FOODGROUP.TIER2 constant, and the moleworm no longer eats anything.
  13. I think you might be misunderstanding what I'm trying to do. I want to be able to feed it anything from its original diet, and THEN adjust its diet so it becomes more picky.
  14. Right! I forgot to mention it in my post, but I did that. I do it right after the NPC eats something else : local function OnEatFirstMeal(inst) inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") inst.components.eater:SetDiet({ FOODGROUP.TIER2 }) if numberOfMeals == 0 then inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.") end if numberOfMeals == 1 then inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") end numberOfMeals = numberOfMeals + 1 end Thanks for the reply! I'm not too worried about compatibility with other mods, I'm doing something really personal for close friends. What I can see from your post is that writing GLOBAL.FOODTYPE.NIGHTMAREFUEL = "NIGHTMAREFUEL" in modmain declares this new foodtype, and then I can use it anywhere in my mod?
  15. Hello, I'm trying to add a few new foodtypes to my mod. My endgoal is to have specific, existing items, and use them to feed a very picky NPC. I am encountering an issue where my "constants.lua" file, the one where all the foodtypes appear to be, does not get overwritten by my mod. I copied the "constants.lua" file in my mod's "scripts" folder, with the following additions : FOODTYPE = { GENERIC = "GENERIC", MEAT = "MEAT", VEGGIE = "VEGGIE", ELEMENTAL = "ELEMENTAL", GEARS = "GEARS", HORRIBLE = "HORRIBLE", INSECT = "INSECT", SEEDS = "SEEDS", BERRY = "BERRY", --hack for smallbird; berries are actually part of veggie RAW = "RAW", -- things which some animals can eat off the ground, but players need to cook BURNT = "BURNT", --For lavae. ROUGHAGE = "ROUGHAGE", WOOD = "WOOD", GOODIES = "GOODIES", MONSTER = "MONSTER", -- Added in for woby, uses the secondary foodype originally added for the berries TIER2 = "TIER2", } (I only added the "Tier2" part, the rest was already there) And further down : TIER2 = { name = "TIER2", types = { FOODTYPE.TIER2, }, }, Then, in the "gem.lua" file, I added the line : inst.components.edible.foodtype = FOODTYPE.TIER2 However, when I'm trying to feed the red gem to the NPC, it won't accept it. This makes me believe that the new foodtype is not recognized by the gem prefab for some reason. Can someone point me in the right direction? Thank you!