RedHairedHero Posted December 25, 2016 Share Posted December 25, 2016 Hello, I'm trying to create an amulet that increase the wielders combat damage by 30% and it's uses are reduced when the user lands a hit. I've attempted several ways to do this, but it always ends up in errors or it just doesn't do anything. Any help would be appreciated. local assets = { Asset("ANIM", "anim/discord_orb.zip"), Asset("ANIM", "anim/swap_discord_orb.zip"), Asset("ATLAS", "images/inventoryimages/discord_orb.xml"), Asset("IMAGE", "images/inventoryimages/discord_orb.tex"), } local function OnFinished(inst) inst.SoundEmitter:PlaySound("dontstarve/common/gem_shatter") inst:Remove() end local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_body", "swap_discord_orb", "discord_orb") inst.components.combat.damagemultiplier = 1.3 end local function onunequip(inst, owner) owner.AnimState:ClearOverrideSymbol("swap_body") end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("discord_orb") inst.AnimState:SetBuild("discord_orb") inst.AnimState:PlayAnimation("idle") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.BODY inst.components.equippable:SetOnEquip( onequip ) inst.components.equippable:SetOnUnequip( onunequip ) inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "discord_orb" inst.components.inventoryitem.atlasname = "images/inventoryimages/discord_orb.xml" inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(150) inst.components.finiteuses:SetUses(150) inst.components.finiteuses:SetOnFinished(OnFinished) MakeHauntableLaunch(inst) return inst end return Prefab( "discord_orb", fn, assets, prefabs) Link to comment Share on other sites More sharing options...
Aquaterion Posted December 25, 2016 Share Posted December 25, 2016 inst.components.combat.damagemultiplier = 1.3 --In the onequip function, INST is the amulet, and OWNER is the player --so: owner.components.combat.damagemultiplier = 1.3 --btw, ideally you add an amount like X + 0.3, rather than setting it to a new value, as this would conflict with anything that changes damagemultipliers Link to comment Share on other sites More sharing options...
RedHairedHero Posted December 25, 2016 Author Share Posted December 25, 2016 Ah, swapping out inst for owner worked. Thank you. I ended up adding owner.components.combat.damagemultiplier = 1 To the unequip, but I'm assuming that would be an issue with some characters default multiplier's like Wes, would this not impact that or is there a way to just return the user back to their default damage multiplier? Part of my original question was also adding on finiteuses for the amulet and reducing it when attacking. I had added inst.components.finiteuses:SetConsumption(ACTIONS.ATTACK, 1) but it doesn't appear to lose any durability when attacking. Link to comment Share on other sites More sharing options...
Aquaterion Posted December 25, 2016 Share Posted December 25, 2016 (edited) not sure why that wouldn't work, but then again i never used that function so i can't be sure, but in the mean time you can do something like this: local function UseDurability(inst) inst.components.finiteuses:Use(1) end local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_body", "swap_discord_orb", "discord_orb") local damagemult = owner.components.combat.damagemultiplier or 1 owner.components.combat.damagemultiplier = damagemult + 0.3 --its better to do + or - rather than * or /, to avoid values getting messed up inst:ListenForEvent("onattackother", UseDurability, owner) end local function onunequip(inst, owner) owner.AnimState:ClearOverrideSymbol("swap_body") owner.components.combat.damagemultiplier = owner.components.combat.damagemultiplier - 0.3 inst:RemoveEventCallback("onattackother", UseDurability, owner) end Edited December 25, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
RedHairedHero Posted December 25, 2016 Author Share Posted December 25, 2016 6 hours ago, Aquaterion said: not sure why that wouldn't work, but then again i never used that function so i can't be sure, but in the mean time you can do something like this: local function UseDurability(inst) inst.components.finiteuses:Use(1) end local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_body", "swap_discord_orb", "discord_orb") local damagemult = owner.components.combat.damagemultiplier or 1 owner.components.combat.damagemultiplier = damagemult + 0.3 --its better to do + or - rather than * or /, to avoid values getting messed up inst:ListenForEvent("onattackother", UseDurability, owner) end local function onunequip(inst, owner) owner.AnimState:ClearOverrideSymbol("swap_body") owner.components.combat.damagemultiplier = owner.components.combat.damagemultiplier - 0.3 inst:RemoveEventCallback("onattackother", UseDurability, owner) end Seems the UseDurability function causes an error. 16: attempt to index field 'finiteuses' (a nil value) Link to comment Share on other sites More sharing options...
Aquaterion Posted December 25, 2016 Share Posted December 25, 2016 5 minutes ago, RedHairedHero said: Seems the UseDurability function causes an error. 16: attempt to index field 'finiteuses' (a nil value) hmm it could the that the ListeforEvent and RemoveEventCallback have to be like so: owner:ListenForEvent("onattackother", UseDurability, inst) owner:RemoveEventCallback("onattackother", UseDurability, inst) Link to comment Share on other sites More sharing options...
RedHairedHero Posted December 25, 2016 Author Share Posted December 25, 2016 5 minutes ago, Aquaterion said: hmm it could the that the ListeforEvent and RemoveEventCallback have to be like so: owner:ListenForEvent("onattackother", UseDurability, inst) owner:RemoveEventCallback("onattackother", UseDurability, inst) It's the same error. I'll attempt to look at some other mods to see how they're handled. Link to comment Share on other sites More sharing options...
Aquaterion Posted December 25, 2016 Share Posted December 25, 2016 local function UseDurability(inst) local bodyslot = inst.components.inventory.equipslots.body if bodyslot.prefab == "discord_orb" and bodyslot.components.finiteuses then bodyslot.components.finiteuses:Use(1) end end owner:ListenForEvent("onattackother", UseDurability) owner:RemoveEventCallback("onattackother", UseDurability) Link to comment Share on other sites More sharing options...
RedHairedHero Posted December 26, 2016 Author Share Posted December 26, 2016 That worked perfectly. Thank you for your help on this. 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