iruizu Posted December 18, 2016 Share Posted December 18, 2016 (edited) I am trying to add an iron vein rock, but i just have no idea how to. I tried using the "rocks" prefab from the don't starve together files and i ended up with this code: Quote local rock3_assets = { Asset("ANIM", "anim/rock3.zip"), Asset("MINIMAP_IMAGE", "rock3"), } local prefabs = { "rocks", "flint", "ironnugget", "rock_break_fx", "collapse_small", } SetSharedLootTable( 'rock3', { {'rocks', 1.00}, {'rocks', 1.00}, {'rocks', 0.50}, {'ironnugget', 0.25}, {'ironnugget', 0.50}, {'ironnugget', 0.75}, {'ironnugget', 1.00}, {'flint', 0.50}, {'flint', 0.25}, }) local function OnWork(inst, worker, workleft) if workleft <= 0 then local pt = inst:GetPosition() SpawnPrefab("rock_break_fx").Transform:SetPosition(pt:Get()) inst.components.lootdropper:DropLoot(pt) if inst.showCloudFXwhenRemoved then local fx = SpawnPrefab("collapse_small") fx.Transform:SetPosition(inst.Transform:GetWorldPosition()) end inst:Remove() else inst.AnimState:PlayAnimation( (workleft < TUNING.ROCKS_MINE / 3 and "low") or (workleft < TUNING.ROCKS_MINE * 2 / 3 and "med") or "full" ) end end local function baserock_fn(bank, build, anim, icon, tag) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddMiniMapEntity() inst.entity:AddNetwork() MakeObstaclePhysics(inst, 1) if icon ~= nil then inst.MiniMapEntity:SetIcon(icon) end inst.AnimState:SetBank(bank) inst.AnimState:SetBuild(build) if type(anim) == "table" then for i, v in ipairs(anim) do if i == 1 then inst.AnimState:PlayAnimation(v) else inst.AnimState:PushAnimation(v, false) end end else inst.AnimState:PlayAnimation(anim) end MakeSnowCoveredPristine(inst) inst:AddTag("boulder") if tag ~= nil then inst:AddTag(tag) end inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("lootdropper") inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.MINE) inst.components.workable:SetWorkLeft(TUNING.ROCKS_MINE) inst.components.workable:SetOnWorkCallback(OnWork) local color = 0.5 + math.random() * 0.5 inst.AnimState:SetMultColour(color, color, color, 1) inst:AddComponent("inspectable") inst.components.inspectable.nameoverride = "ROCK" MakeSnowCovered(inst) MakeHauntableWork(inst) return inst end local function rock3_fn() local inst = baserock_fn("rock3", "rock3", "full", "rock3.png") if not TheWorld.ismastersim then return inst end inst.components.lootdropper:SetChanceLootTable('rock3') return inst end return Prefab("rock3", rock3_fn, rock3_assets, prefabs) however, when spawned through console it is invisible. I also need help on getting worlgen to generate these new rocks. Edited December 18, 2016 by iruizu adding more info Link to comment Share on other sites More sharing options...
justjasper Posted December 18, 2016 Share Posted December 18, 2016 You've taken this code from the prexisting rock file, yes? That deals with multiple prefabs using the same resources (anims), so where you've got: inst.AnimState:SetBank(bank) inst.AnimState:SetBuild(build) if type(anim) == "table" then for i, v in ipairs(anim) do if i == 1 then inst.AnimState:PlayAnimation(v) else inst.AnimState:PushAnimation(v, false) end end else inst.AnimState:PlayAnimation(anim) end It's not directly calling on anything in the rock3.zip file I assume you've created. Have a look at other files for single prefabs and see how their bank/build is set and apply those. It's always really useful for modding if you upload a zip/rar file of your WIP mod so we can look directly at your assets/code! Link to comment Share on other sites More sharing options...
iruizu Posted December 18, 2016 Author Share Posted December 18, 2016 i didn't think a zip file of my mod was necessary, because my mod its basically that script and the textures so far...(the modmain is bascially PrefabFiles = { "rock3", } ). anyways I managed to get the animation working, i used the gold vein bank with my own sprites and its working perfectly, when spawned the rock shows up, im able to hit it with the pickaxe and it goes through the 3 stages before finally breaking and releasing loot. The only thing left to do now is get the rock to be spawned among other rocks during worldgen, wich i have no idea on how to do. Link to comment Share on other sites More sharing options...
justjasper Posted December 18, 2016 Share Posted December 18, 2016 13 minutes ago, iruizu said: The only thing left to do now is get the rock to be spawned among other rocks during worldgen, wich i have no idea on how to do. Check out the modworldgenmain file in the Tungsten mod, that'll give you a working example of spawning a rock item in worldgen. Link to comment Share on other sites More sharing options...
iruizu Posted December 18, 2016 Author Share Posted December 18, 2016 Thank you so much, you helped me solve both my problems and now i got it working thanks to you! 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