cenaa9 Posted May 16, 2019 Share Posted May 16, 2019 Four days ago i started to code a mod called "no spoiling": https://steamcommunity.com/sharedfiles/filedetails/?id=1737809866 I have got massive problems because of the different dlcs! How the hell i can tell the programm only to load prefabs from DLC0001!? local IsDLC0001 = GLOBAL.IsDLCEnabled and GLOBAL.REIGN_OF_GIANTS and GLOBAL.IsDLCEnabled(GLOBAL.REIGN_OF_GIANTS)if IsDLC0001 then PrefabFiles = {"icebox","inv_rocks_ice"} like PrefabFiles = {"DLC0001\scripts\prefabs\inv_rocks_ice.lua"} ----------- how to tell don't starve only to load prefabs files from folder: "DLC0001" !?!?!? I could scream the **** out of me!!! All the problems caused why "inv_rocks_ice.lua" got two different versions. One special for shipwrecked and one for the other dlcs! So i cant put all prefab lua files in the standard folder for all dlcs like: "nospoiling\scripts\prefabs" LOOK AT THIS! I ONLY WANT TO TELL THE PROGRAMM WHICH PREFABS TO LOAD AND WHICH NOT! local IsDLC0001 = GLOBAL.IsDLCEnabled and GLOBAL.REIGN_OF_GIANTS and GLOBAL.IsDLCEnabled(GLOBAL.REIGN_OF_GIANTS) local IsDLC0002 = GLOBAL.IsDLCEnabled and GLOBAL.CAPY_DLC and GLOBAL.IsDLCEnabled(GLOBAL.CAPY_DLC) local IsDLC0003 = GLOBAL.IsDLCEnabled and GLOBAL.PORKLAND_DLC and GLOBAL.IsDLCEnabled(GLOBAL.PORKLAND_DLC) if IsDLC0001 then function nospoiling_rPerishable(inst) if inst.components.perishable then inst:RemoveComponent("perishable") end end PrefabFiles = {"icebox", "inv_rocks_ice"}else PrefabFiles = {} end if IsDLC0002 then PrefabFiles = {}else PrefabFiles = {} end if IsDLC0003 then function nospoiling_rPerishable(inst) if inst.components.perishable then inst:RemoveComponent("perishable") end end PrefabFiles = {}else PrefabFiles = {} end Link to comment Share on other sites More sharing options...
Eusong Posted May 16, 2019 Share Posted May 16, 2019 if IsDLCEnabled(REIGN_OF_GIANTS) then --do the stuff end You may need to add a GLOBAL. in front of some of the things if it's going in your modmain. I've never called them from the modmain so I don't know for sure. But yeah it's a lot simpler than the nightmare you seem to have set up, haha. Edit: I may have misunderstood your question. Was it an issue with checking for the DLCs, or was it a different issue? Link to comment Share on other sites More sharing options...
cenaa9 Posted May 16, 2019 Author Share Posted May 16, 2019 That doesen't help cause the client is still load the prefabs even if they are not listet!!! Link to comment Share on other sites More sharing options...
Ultroman Posted May 17, 2019 Share Posted May 17, 2019 Your code is very weird. I tried to comment what each line does. I don't know what happens after all this code, but it doesn't look like this code ends up doing anything. -- If RoG... if IsDLC0001 then -- Declare a function function nospoiling_rPerishable(inst) if inst.components.perishable then inst:RemoveComponent("perishable") end end -- Set PrefabFiles to be this list of prefabs...weird place to put an "else"... PrefabFiles = {"icebox", "inv_rocks_ice"}else -- Make PrefabFiles empty. PrefabFiles = {} end This would be a much simpler way to handle this. There's no problem if the prefab doesn't exist, because we're looking at actual instances carrying the perishable component in the world, checking whether their prefab is in the list to have the component removed. It gets heavier to run the more prefab names you put in the list, compared to if you run through exact lists of prefabs, which you seem to be going for now, but it'll only happen once for each instance carrying the component, and it doesn't do a lot of work. local function contains(mytable, value) if mytable and value then for _, v in ipairs(mytable) do if v == value then return true end end end return false end local noSpoliagePrefabs = { "hambat", } AddComponentPostInit("perishable", function(component) if contains(noSpoliagePrefabs, component.inst.prefab) then component:DoTaskInTime(0, function() self:Remove() end) end end) Link to comment Share on other sites More sharing options...
cenaa9 Posted May 17, 2019 Author Share Posted May 17, 2019 Thanks trying to help me! Look. to remove the perishable from etc. "ice" you have to change "inv_rocks_ice.lua". There are 3 files. DLC0001, DLC0002, DLC0003 and none inside the standard/main "scripts/prefabs" has got one of it. The prob is that two of theese files are different! If you start a rog match, DLC0001 "inv_rocks_ice" 4 KB is used. If you start a Shipwrecked match, DLC0002 "inv_rocks_ice.lua" 7 KB is used - cause of "hail_ice" and hurricans! If i put my prefabs into my mod folder: "nospoiling/scripts/prefabs" there is no chance to seperate these two files! There must be a possibility to seperate!!! If match is shipwrecked then load "nospoiling/DLC0002/scripts/prefabs/inv_rocks_ice.lua". If match is RoG then load "nospoiling/DLC0001/scripts/prefabs/inv_rocks_ice.lua" and nothing else!!! Even if i put all the files into "nospoiling/scripts/prefabs" and disable the shipwrecked compatibility - shipwrecked is loading files from the "nospoiling/scripts/prefabs" and crashes cause "inv_rocks_ice" 4 KB was loaded! Link to comment Share on other sites More sharing options...
Ultroman Posted May 17, 2019 Share Posted May 17, 2019 Why on Earth would you put original prefab files in your mods folder? That would completely overwrite the original prefab files when loading the game! That is not a good way to go about this. With my code, you don't need to .worry about any prefab names and which prefabs are loaded and which are not. It works and it's safe. Link to comment Share on other sites More sharing options...
cenaa9 Posted May 17, 2019 Author Share Posted May 17, 2019 I know i am not good at programming and my old code worked untill i messed up with two different versions of "inv_rocks_ice.lua"! For me your lines are a misery. Maybe you can figure out how to disable perishing for all food items? I early noteced copying original prefabs into the mod folder is a really bad idea but i didn't know how to handle some prefabs without copy them into the mod folder and change the code in the file directly! Your code doesn`'t have any effect: local function contains(mytable, value) if mytable and value then for _, v in ipairs(mytable) do if v == value then return true end end end return false end local noSpoliagePrefabs = { "ice", "hail_ice", "honey", "acorn", "acorn_cooked", "aloe", "aloe_Seeds", "aloe_cooked", "ceviche", "watermelon_seeds", "watermelonicle", "wetgoop", "wormlight", "wormlight_lesser", etc. --- hats --- "watermelonhat", "icehat", "flowerhat", --- weapons --- "hambat", } AddComponentPostInit("perishable", function(component) if contains(noSpoliagePrefabs, component.inst.prefab) then component:DoTaskInTime(0, function() self:Remove() end) end end Link to comment Share on other sites More sharing options...
Ultroman Posted May 17, 2019 Share Posted May 17, 2019 Try this AddComponentPostInit instead (keep the contains and list as you have them): AddComponentPostInit("perishable", function(component) if contains(noSpoliagePrefabs, component.inst.prefab) then component.inst:DoTaskInTime(0, function(inst) inst:RemoveComponent("perishable") end) end end Link to comment Share on other sites More sharing options...
cenaa9 Posted May 17, 2019 Author Share Posted May 17, 2019 I have got an other question that could solve all my problems! Just tell me how can i tell the programm to find a "code line" inside a prefab and just delete it!? if ("MakeInventoryFloatable(inst, "idle_water", "idle")") then remove("MakeInventoryFloatable(inst, "idle_water", "idle")") else do nothing!!! end end Link to comment Share on other sites More sharing options...
Ultroman Posted May 18, 2019 Share Posted May 18, 2019 2 hours ago, cenaa9 said: I have got an other question that could solve all my problems! Just tell me how can i tell the programm to find a "code line" inside a prefab and just delete it!? if ("MakeInventoryFloatable(inst, "idle_water", "idle")") then remove("MakeInventoryFloatable(inst, "idle_water", "idle")") else do nothing!!! end end Hehe, that's not happening ever xD Did the new code not work? Link to comment Share on other sites More sharing options...
cenaa9 Posted May 18, 2019 Author Share Posted May 18, 2019 Okay I'll give it a last try :)) The client is closing without any crash showing up. Link to comment Share on other sites More sharing options...
Ultroman Posted May 19, 2019 Share Posted May 19, 2019 The crash will show in your log. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.