Digidragon Posted May 5, 2016 Share Posted May 5, 2016 Hello again, while still new to the world of coding I tried creating an instrument item for a character, its function is similar to the One Man Band. I've tried for hours to create the item and only succesfully finished the visuals. Could someone give me a couple of pointers to modify the One Man Band code so that instead of being a One Man Band it will: 1. When equipped will slowly cause sanity to be regained for character and nearby players 2. Causes enemies within a radius to immediately start attacking 3. Uses up hunger to play 4. Has a crafting recipe of a Stick, 2 Logs and 3 Silk Please and thank you in advance. Link to comment Share on other sites More sharing options...
DarkXero Posted May 5, 2016 Share Posted May 5, 2016 10 hours ago, Digidragon said: Hello again, while still new to the world of coding I tried creating an instrument item for a character, its function is similar to the One Man Band. I've tried for hours to create the item and only succesfully finished the visuals. Could someone give me a couple of pointers to modify the One Man Band code so that instead of being a One Man Band modmain.lua: PrefabFiles = { "onemanband_special", } local RECIPETABS = GLOBAL.RECIPETABS local TECH = GLOBAL.TECH local onemanband_special_recipe = AddRecipe("onemanband_special", {Ingredient("twigs", 1), Ingredient("log", 2), Ingredient("silk", 3)}, RECIPETABS.MAGIC, TECH.NONE, nil, nil, nil, nil, nil, "images/inventoryimages.xml", "onemanband.tex") onemanband_special_recipe.sortkey = 0 local STRINGS = GLOBAL.STRINGS STRINGS.NAMES.ONEMANBAND_SPECIAL = "One Special Band" STRINGS.RECIPE_DESC.ONEMANBAND_SPECIAL = "Make monsters mad, and players unmad." onemanband_special.lua: local assets = { Asset("ANIM", "anim/armor_onemanband.zip"), Asset("ANIM", "anim/swap_one_man_band.zip"), } local band_dt = 1 local band_radius = 12 local sanity_tick = 0.1 local hunger_tick = 0.2 local function band_update(inst) local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner if owner then local x, y, z = owner.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, band_radius, {"_combat"}, {"playerghost", "INLIMBO"}) for k, v in pairs(ents) do if v.components.sanity then v.components.sanity:DoDelta(sanity_tick, true) elseif v.components.combat:CanTarget(owner) then v.components.combat:SuggestTarget(owner) end end if owner.components.hunger then owner.components.hunger:DoDec(hunger_tick, true) end end end local function band_enable(inst) inst.updatetask = inst:DoPeriodicTask(band_dt, band_update) end local function band_disable(inst) if inst.updatetask then inst.updatetask:Cancel() inst.updatetask = nil end end local function band_perish(inst) band_disable(inst) inst:Remove() end local function on_equip(inst, owner) owner.AnimState:OverrideSymbol("swap_body_tall", "swap_one_man_band", "swap_body_tall") inst.components.fueled:StartConsuming() band_enable(inst) end local function on_unequip(inst, owner) owner.AnimState:ClearOverrideSymbol("swap_body_tall") inst.components.fueled:StopConsuming() band_disable(inst) end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst:AddTag("band") inst.AnimState:SetBank("onemanband") inst.AnimState:SetBuild("armor_onemanband") inst.AnimState:PlayAnimation("anim") inst.foleysound = "dontstarve/wilson/onemanband" inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "onemanband" inst:AddComponent("fueled") inst.components.fueled.fueltype = FUELTYPE.ONEMANBAND inst.components.fueled:InitializeFuelLevel(TUNING.ONEMANBAND_PERISHTIME) inst.components.fueled:SetDepletedFn(band_perish) inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.BODY inst.components.equippable:SetOnEquip(on_equip) inst.components.equippable:SetOnUnequip(on_unequip) return inst end return Prefab("onemanband_special", fn, assets) You can customize the effect radius, the sanity it provides per tick, and the hunger it depletes per tick. Link to comment Share on other sites More sharing options...
Digidragon Posted May 6, 2016 Author Share Posted May 6, 2016 Thanks a lot! You're a life saver! 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