rons0n Posted August 2, 2017 Share Posted August 2, 2017 So awhile ago I created a character called abigail and made it so her custom prefabs can be inserted into rocks like so: AddSimPostInit(function() local _LT = GLOBAL.LootTables table.insert(_LT['full_rock'], {"sdquartz", 0.75}) table.insert(_LT['stalagmite_tall_full_rock'], {"sdquartz", 0.75}) table.insert(_LT['full_rock'], {"sdiridium", 0.25}) table.insert(_LT['stalagmite_tall_full_rock'], {"sdiridium", 0.25}) end) and I decided to do this by applying the same method to trees like so: AddSimPostInit(function() local _LT = GLOBAL.LootTables table.insert(_LT['evergreen'], {"item1", 0.1}) table.insert(_LT['evergreen'], {"item2", 0.1}) table.insert(_LT['evergreen'], {"item3", 0.1}) table.insert(_LT['evergreen'], {"item4", 0.1}) table.insert(_LT['evergreen'], {"item5", 0.1}) end) but as soon as the game reads the first table insert the game crashes when loading into a world. So why does the first method work and not my second method? To add, the custom prefabs work ingame and by console. [00:00:44]: [string "../mods/character/modmain.lua"]:149: bad argument #1 to 'insert' (table expected, got nil) LUA ERROR stack traceback: =[C] in function 'insert' ../mods/character/modmain.lua(149,1) Link to comment Share on other sites More sharing options...
Lumina Posted August 2, 2017 Share Posted August 2, 2017 Maybe because full_rock and stalagmite_tall_full_rock are prefab names, when evergreen is just too generic and you need to do it for, for example, evergreen_tall, evergreen_medium or whatever are the different prefab names for each evergreen stage ? Link to comment Share on other sites More sharing options...
rons0n Posted August 2, 2017 Author Share Posted August 2, 2017 Oh you're most likely right, that completely slipped my mind. Thanks! Link to comment Share on other sites More sharing options...
rons0n Posted August 2, 2017 Author Share Posted August 2, 2017 (edited) Sorry on the update but even changing it to evergreen_tall, small, etc still yielded me the same error so now im back to square one, suggestions? AddSimPostInit(function() local _LT = GLOBAL.LootTables table.insert(_LT['evergreen_normal'], {"etc1", 0.1}) table.insert(_LT['evergreen_normal'], {"etc2", 0.1}) table.insert(_LT['evergreen_normal'], {"etc3", 0.1}) table.insert(_LT['evergreen_normal'], {"etc4", 0.1}) table.insert(_LT['evergreen_normal'], {"etc5", 0.1}) table.insert(_LT['evergreen_tall'], {"etc1", 0.1}) table.insert(_LT['evergreen_tall'], {"etc2", 0.1}) table.insert(_LT['evergreen_tall'], {"etc3", 0.1}) table.insert(_LT['evergreen_tall'], {"etc4", 0.1}) table.insert(_LT['evergreen_tall'], {"etc5", 0.1}) table.insert(_LT['evergreen_short'], {"etc1", 0.1}) table.insert(_LT['evergreen_short'], {"etc2", 0.1}) table.insert(_LT['evergreen_short'], {"etc3", 0.1}) table.insert(_LT['evergreen_short'], {"etc4", 0.1}) table.insert(_LT['evergreen_short'], {"etc5", 0.1}) end) Edited August 2, 2017 by rons0n Link to comment Share on other sites More sharing options...
Lumina Posted August 2, 2017 Share Posted August 2, 2017 Hmm, Looking at the prefabs, they don't seems to have the same structure. For example, stalagmite_tall have this SetSharedLootTable('stalagmite_tall_full_rock', { {'rocks', 1.00}, {'rocks', 1.00}, {'goldnugget', 1.00}, {'flint', 1.00}, {'fossil_piece',0.10}, {'goldnugget', 0.25}, {'flint', 0.60}, {'redgem', 0.05}, {'log', 0.05}, }) SetSharedLootTable('stalagmite_tall_med_rock', { {'rocks', 1.00}, {'rocks', 1.00}, {'flint', 1.00}, {'fossil_piece',0.10}, {'goldnugget', 0.15}, {'flint', 0.60}, }) SetSharedLootTable('stalagmite_tall_low_rock', { {'rocks', 1.00}, {'flint', 1.00}, {'fossil_piece',0.10}, {'goldnugget', 0.15}, {'flint', 0.30}, }) And tree prefab have this : local builds = { normal = { file="evergreen_new", file_bank = "evergreen_short", prefab_name="evergreen", regrowth_product="pinecone_sapling", regrowth_tuning=TUNING.EVERGREEN_REGROWTH, grow_times=TUNING.EVERGREEN_GROW_TIME, normal_loot = {"log", "log", "pinecone"}, short_loot = {"log"}, tall_loot = {"log", "log", "log", "pinecone", "pinecone"}, drop_pinecones=true, leif="leif", chop_camshake_delay=0.4, }, sparse = { file="evergreen_new_2", file_bank = "evergreen_short", prefab_name="evergreen_sparse", regrowth_product="lumpy_sapling", regrowth_tuning=TUNING.EVERGREEN_SPARSE_REGROWTH, grow_times=TUNING.EVERGREEN_GROW_TIME, normal_loot = {"log","log"}, short_loot = {"log"}, tall_loot = {"log", "log","log"}, drop_pinecones=false, leif="leif_sparse", chop_camshake_delay=0.4, }, twiggy = { file="twiggy_build", file_bank = "twiggy", file_disease = "twiggy_diseased_build", prefab_name="twiggytree", regrowth_product="twiggy_nut_sapling", regrowth_tuning=TUNING.EVERGREEN_REGROWTH, grow_times=TUNING.TWIGGY_TREE_GROW_TIME, normal_loot = {"log","twigs","twiggy_nut"}, short_loot = {"twigs"}, tall_loot = {"log", "twigs","twigs","twiggy_nut","twiggy_nut"}, drop_pinecones=false, rebirth_loot = {loot="twigs", max=2}, chop_camshake_delay=20*FRAMES, }, } Linked to this line : inst.components.lootdropper:SetLoot(GetBuild(inst).tall_loot) (for example) So maybe you need to add loot with lootdropper function rather than table insert ? Link to comment Share on other sites More sharing options...
rons0n Posted August 2, 2017 Author Share Posted August 2, 2017 Whoa look at all those types of loot, what If I just wanted to do it when the tree was normal and tall only? I kinda derped around and made this, skimming through other mods and looking into the game files --Add resources from trees local trees = {"evergreen", "evergreen_sparse", "deciduoustree", "twiggytree"} for i,v in pairs(trees) do if inst.components.growable.stage == 3 then inst.components.lootdropper:AddChanceLoot("apple", 1) end end but yeah it ended in a catastrophe cause i have no idea what im doing: [00:00:38]: [string "../mods/character/modmain.lua"]:148: attempt to index global 'inst' (a nil value) LUA ERROR stack traceback: ../mods/character/modmain.lua(148,1) in main chunk Its what i expect of myself. Anyway, would anyone know how to approach this differently? Link to comment Share on other sites More sharing options...
Lumina Posted August 2, 2017 Share Posted August 2, 2017 I don't know. Try something like this maybe ? if not GLOBAL.TheNet:GetIsServer() then return end local function LeifPostInit( inst ) if inst.components.lootdropper then inst.components.lootdropper:AddChanceLoot("myprefab", .5) end return inst end AddPrefabPostInit( "leif", LeifPostInit) (So my example is for leif because it was i wanted to do but you could probably adapt. Link to comment Share on other sites More sharing options...
rons0n Posted August 2, 2017 Author Share Posted August 2, 2017 Ahhh it worked, made it so chopping down evergreen_normal guaranteed drop apples and it worked! I can't thank ya enough, now I can get back on track and making all trees drop stuff! Thanks x 100 Link to comment Share on other sites More sharing options...
Lumina Posted August 2, 2017 Share Posted August 2, 2017 I'm happy it helped you Link to comment Share on other sites More sharing options...
rons0n Posted August 2, 2017 Author Share Posted August 2, 2017 Ah, im sorry for dragging you down into this mess but there is one more problem. While this does make the host be able to play the character, it disables the clients from playing the character and I noticed it was because of if not GLOBAL.TheNet:GetIsServer() then return end what would i tack on so both the host and client can play her? Link to comment Share on other sites More sharing options...
Lumina Posted August 2, 2017 Share Posted August 2, 2017 This code is to tell that this part of code i gave you should not be run client side because there are component in it. Where are you putting the code ? Link to comment Share on other sites More sharing options...
rons0n Posted August 3, 2017 Author Share Posted August 3, 2017 (edited) Apologies, I just shoved it within my modmain Oh alright I just removed it and now it worked, I guess if its in the modmain you dont need that huh. Hah~ Edited August 3, 2017 by rons0n Link to comment Share on other sites More sharing options...
Lumina Posted August 3, 2017 Share Posted August 3, 2017 This is strange, i know for sure i got crash in the past without this line but it seems fine without now. It was some years ago so maybe it's not needed anymore ? Anyway, the line itself isn't supposed to cause crash, just to ensure that the component part is only server side. So i don't get why you get a crash with, all is working fine for me with the line... But if it's fixed for you it's the most important. 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