josra102 Posted January 30 Share Posted January 30 I'm still new to modding but can you help me with one perk for my character? When he stands near the sculptures, he was given one sanity every few seconds. Of course, I searched on the forum for how to make auras or give sanity when it’s in range, but for some reason nothing works when I enter the prefab of sculptures. That is, it works well on ordinary creatures like a butterfly, but the sculpture does not want to work. I don't know what to do but I think it's what the game calls sculpture in the code. If you can help with this I will be grateful. Here's the code I used : local B_CANT_TAGS = {"playerghost", "player"} local function statuesanity(inst) if inst.components.health:IsDead() or inst:HasTag("playerghost") then return end local x,y,z = inst.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, 10, {"chesspiece_moon_marble"}, B_CANT_TAGS) for i, v in ipairs(ents) do if v and v:IsValid() and v.prefab == "chesspiece_moon_marble" then inst.components.sanity:DoDelta(1, true) end end end AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst:DoPeriodicTask(1, statuesanity) end) Link to comment Share on other sites More sharing options...
_zwb Posted January 30 Share Posted January 30 You can do it the opposite way, add a periodic task to your character. The task would check if any statues are nearby, if yes change sanity. Link to comment Share on other sites More sharing options...
Thomas Die Posted January 30 Share Posted January 30 (edited) Ultroman has made a poste detailing the use of something such as this → here if this post cannot help you in this. 17 hours ago, josra102 said: I don't know what to do but I think it's what the game calls sculpture in the code. The don't starve wiki includes the "code_name" for entities in the wiki pages → here. God Bless the wiki team. The tutorials section located at the top of the forums offers a variety of helpful guides for beginner modders, but I recommend heavily Ultromans → here Given the opportunity, I would recommend adding the tag to the chess pieces you desire, instead of constantly cycling through with if statements; Using the TheSim:FindEntities alone would allow for higher efficiency for your code, which is desirable for when using period tasks. AddPrefabPostInit would be useful in this endeavor and further information can be found → here Happy modding, Edited January 30 by Thomas Die adding the funni arrows for dopamine, and correcting past Thomas' mistakes Link to comment Share on other sites More sharing options...
josra102 Posted January 31 Author Share Posted January 31 It seems that I got the function to be executed from the statue and it works, but I would also like that it determined and the material of the statues for I dug into the code of the sculptures and seemed to find how to determine the material of the statues, but when I inserted this parameter and went to the lunar glass statue, I just got the game crashed. This is what was in the server log: [00:03:28]: error calling PrefabPostInit: chesspiece_moon in mod Evgens-DST-MOD (Evgens - Nature Mage and Mechanic): [string "../mods/Evgens-DST-MOD/modmain.lua"]:188: attempt to index global 'MATERIALS' (a nil value) LUA ERROR stack traceback: Now the code looks like this: local B_CANT_TAGS = {"playerghost"} local function statueart(inst) print("work2") local x,y,z = inst.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, 10, {"player"}, B_CANT_TAGS) for i, v in ipairs(ents) do if v.prefab == "evgens" then v.components.sanity:DoDelta(1, true) print("work3") end end end AddPrefabPostInit("chesspiece_moon", function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end if (inst.materialid ~= nil and MATERIALS[inst.materialid].name == MOONGLASS_NAME) then inst:DoPeriodicTask(1, statueart) print("work1") end end) If you know a solution to this problem, you can write Link to comment Share on other sites More sharing options...
_zwb Posted January 31 Share Posted January 31 6 hours ago, josra102 said: modmain.lua"]:188: attempt to index global 'MATERIALS' (a nil value) Use GLOBAL.MATERIALS instead of MATERIALS in modmain environment. Also it's better to add the periodic task to the player because there can be hundreds of statues, but only a few players, adding the task to the player helps with performance. If you are certain there would only be a few statues then it doesn't matter. Link to comment Share on other sites More sharing options...
josra102 Posted January 31 Author Share Posted January 31 (edited) Sorry, but for some reason I can’t figure out where to enter GLOBAL.MATERIALS and how to make an “if” with it, something that would work, and I also tried to make a function from the player, but GLOBAL.TheSim:FindEntities doesn’t want to find sculptures of only creatures Edited January 31 by josra102 Link to comment Share on other sites More sharing options...
josra102 Posted February 4 Author Share Posted February 4 Hi again. After several searches, I was still able to determine that the statues were being sought from the player. Now I do this through a tag, but now there are two gaps: 1.Now we need to make sure that the aura effect does not stack when there are several statues nearby 2.Also determine the material of the statues. But here I tried to pull out the code from the culture prefab responsible for the lunar event, but when I tried it said that [string "../mods/Evgens-DST-MOD/modmain.lua"]:188: attempt to index global 'MATERIALS I was told to use global MATERIALS but that doesn't help either Now the code looks like this: local MOONGLASS_NAME = "moonglass" local function statueart(inst) if inst:HasTag("evgens") then return end local x,y,z = inst.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, 10, {"statueartmoon"}, {"playerghost", "Decor"}, 1) for i, v in ipairs(ents) do if v and v:IsValid() then inst.components.sanity:DoDelta(1, true) inst.components.talker:Say("Work!") end end end AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst:DoPeriodicTask(1, statueart) end) AddPrefabPostInit("chesspiece_moon", function(inst) inst:AddTag("statueartmoon") end) If you have ideas on how to solve these problems, please write Link to comment Share on other sites More sharing options...
josra102 Posted February 8 Author Share Posted February 8 Hello again, I found a solution to the first problem, but I don’t know what to do with the second: AddPrefabPostInit("chesspiece_moon", function(inst) (inst.materialid ~= nil and Global.MATERIALS[inst.materialid].name == "moonglass") then inst:AddTag("statueartmoonmoonglass") end end) I tried to use Global in different ways, but it either doesn’t work or doesn’t allow me to start the server. Maybe he's missing something? I do not know what to do. Link to comment Share on other sites More sharing options...
josra102 Posted February 27 Author Share Posted February 27 Happened! Moon glass statues work, but it was necessary to compare the materialid with the number Here's the whole code: modmain: local function statueartmoonmoonglass(inst) if inst:HasTag("evgens") then return end local x,y,z = inst.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, 4, {"evgensstatueartmoonmoonglass"}, {"playerghost", "Decor"}, 1) for i, v in ipairs(ents) do if v and v:IsValid() and (v.materialid == 3) then inst:AddTag("evgensstatueartmoonmoonglass") end end end AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst:DoPeriodicTask(5, statueartmoonmoonglass) end) Character - Evgens: inst:DoPeriodicTask(1.0, function(inst) if inst:HasTag("sculptures") and inst:HasTag("evgensstatueartmoonmoonglass") then inst.components.sanity:DoDelta(1, true) inst:RemoveTag("evgensstatueartmoonmoonglass") end end) Maybe it will be useful to someone. Link to comment 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