CubezertThing Posted January 20 Share Posted January 20 (edited) Hello, thank for trying to help! For context, I am making a character mod that has their own craft-able equipment, and this one I'm making just keeps crashing Don't Starve Together whenever I launch it. The Code is basically a miner hat that can be upgraded by inserting gems, with only one upgrade at a time, kind of like cratered moon rocks. I didn't add any condition to enable these effects, but whenever I add this file to the mod it crashes, so I am *sure* I did something wrong. Most of the code was taken from other vanilla DST items, so I feel like maybe in that jigsaw puzzle of a code I added it in wrong. I also feel like the way I implemented how the item checks for the gem type crashes it, but I don't know how to rewrite it correctly. Thank you so much! Here's the code: This is my first mod, and I have basically minimal experience with DST code and such, so thank you again for any help or tips. local function projector_turnon(inst) local owner = inst.components.inventoryitem ~= nil and inst.components.inventoryitem.owner or nil if not inst.components.fueled:IsEmpty() then if inst._light == nil or not inst._light:IsValid() then inst._light = SpawnPrefab("minerhatlight") end if owner ~= nil then _onequip(inst, owner) inst._light.entity:SetParent(owner.entity) end inst.components.fueled:StartConsuming() inst.components.equippable.dapperness = -TUNING.DAPPERNESS_MED local soundemitter = owner ~= nil and owner.SoundEmitter or inst.SoundEmitter --(Gem conditions) local assets = { --Asset("ANIM", "anim/wotzomooneyes.zip"), Asset("ANIM", "anim/projector.zip") } local prefabs = { "wotzopurplemooneye", "wotzobluemooneye", "wotzoredmooneye", "wotzoorangemooneye", "wotzoyellowmooneye", "wotzogreenmooneye", } local function ItemTradeTest(inst, item) if item == nil then return false elseif string.sub(item.prefab, -3) ~= "gem" then return false, "NOTGEM" elseif string.sub(item.prefab, -11, -4) == "precious" then return false, "WRONGGEM" end return true end local function OnGemGiven(inst, giver, item) local mooneye = SpawnPrefab(string.sub(item.prefab, 1, -4).."mooneye") local container = inst.components.inventoryitem:GetContainer() if container ~= nil then local slot = inst.components.inventoryitem:GetSlotNum() inst:Remove() container:GiveItem(mooneye, slot) else local x, y, z = inst.Transform:GetWorldPosition() inst:Remove() mooneye.Transform:SetPosition(x, y, z) end end local function RedActionForWotzo(inst, giver, slot, wotzoredmooneye) if slot == wotzoredmooneye then inst:AddComponent("insulator") inst.components.insulator:SetInsulation(TUNING.INSULATION_MED) end end local function BlueActionWotzo(inst, giver, slot, wotzobluemooneye) if slot == wotzobluemooneye then inst:AddComponent("insulator") inst.components.insulator:SetSummer() inst.components.insulator:SetInsulation(TUNING.INSULATION_MED) end end local function YellowActionWotzo(inst, giver, slot, wotzoyellowmooneye) if slot == wotzoyellowmooneye then inst.components.equippable.walkspeedmult = TUNING.WALKING_STICK_SPEED_MULT end end local function PurpleActionWotzo(inst, giver, slot, wotzopurplemooneye) if slot == wotzopurplemooneye then inst.components.equippable.dapperness = TUNING.DAPPERNESS_MED end end local function GreenActionWotzo(inst, giver, slot, wotzogreenmooneye) if slot == wotzogreenmooneye then if owner.components.builder ~= nil then owner.components.builder.ingredientmod = TUNING.GREENAMULET_INGREDIENTMOD end inst.onitembuild = function(owner, data) if not (data ~= nil and data.discounted == false) then inst.components.finiteuses:Use(1) end end inst:ListenForEvent("consumeingredients", inst.onitembuild, owner) end end local function OrangeActionWotzo(inst, giver, slot, wotzoorangemooneye) if slot == wotzoorangemooneye then local prefabs = { "explode_big", } local function OnExplodeFn(inst) SpawnPrefab("explode_big").Transform:SetPosition(inst.Transform:GetWorldPosition()) end inst:AddComponent("explosive") inst.components.explosive:SetOnExplodeFn(OnExplodeFn) inst.components.explosive.explosivedamage = TUNING.GUNPOWDER_DAMAGE * 100 -- Oppenheimer kind of stuff end end -- Gem condition stuff -- (Red = Summer, Winter = Winter, Yellow = Speed, Orange = ?!, Purple = sanity, Green = GAmulet effect) local function onunequip_projector(inst, owner) owner.AnimState:ClearOverrideSymbol("swap_body") end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetRayTestOnBB(true) inst.AnimState:SetBank("mooneyes") inst.AnimState:SetBuild("mooneyes") inst.AnimState:PlayAnimation("crater") inst.scrapbook_anim = "crater" inst:AddTag("gemsocket") -- trader (from trader component) added to pristine state for optimization inst:AddTag("trader") inst:AddTag("give_dolongaction") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem:SetSinks(true) inst:AddComponent("trader") inst.components.trader:SetAbleToAcceptTest(ItemTradeTest) inst.components.trader.onaccept = OnGemGiven MakeHauntableLaunch(inst) return inst end return Prefab("projector", fn, assets, prefabs) elseif owner ~= nil then _onequip(inst, owner, "swap_hat_off") end end local function projector_turnoff(inst) local owner = inst.components.inventoryitem ~= nil and inst.components.inventoryitem.owner or nil if owner ~= nil and inst.components.equippable ~= nil and inst.components.equippable:IsEquipped() then _onequip(inst, owner, "swap_hat_off") end inst.components.fueled:StopConsuming() if inst._light ~= nil then if inst._light:IsValid() then inst._light:Remove() end inst._light = nil local soundemitter = owner ~= nil and owner.SoundEmitter or inst.SoundEmitter soundemitter:PlaySound("dontstarve/common/minerhatOut") end end local function projector_unequip(inst, owner) _onunequip(inst, owner) projector_turnoff(inst) end fns.projector_onequiptomodel = function(inst, owner, from_ground) fns.simple_onequiptomodel(inst, owner, from_ground) projector_turnoff(inst) end local function projector_custom_init(inst) inst.entity:AddSoundEmitter() -- waterproofer (from waterproofer component) added to pristine state for optimization inst:AddTag("waterproofer") end local function projector_onremove(inst) if inst._light ~= nil and inst._light:IsValid() then inst._light:Remove() end end fns.projector = function() local inst = simple(projector_custom_init) inst.components.floater:SetSize("med") inst.components.floater:SetScale(0.2) if not TheWorld.ismastersim then return inst end inst.components.inventoryitem:SetOnDroppedFn(projector_turnoff) inst.components.equippable:SetOnEquip(projector_turnon) inst.components.equippable:SetOnUnequip(projector_unequip) inst.components.equippable:SetOnEquipToModel(fns.projector_onequiptomodel) inst:AddComponent("waterproofer") inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL) inst._light = nil inst.OnRemoveEntity = projector_onremove return inst end Edited January 20 by CubezertThing Fixed Issue, but new related problem came up. 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