PrinceKawaii Posted July 30, 2015 Share Posted July 30, 2015 Hello, so I've been working on this mod for awhile now and it's finally near completion. Everything works just fine minus the final part (fun), but I can't seem to fix it. I've been working on making a sword that changes the amount of damage that it does depending on the day phase. So as it becomes night it does more damage, very much like Abigail. In the scripts/prefabs/item.lua my code is as follows:local assets={ Asset("ANIM", "anim/moonsword.zip"), Asset("ANIM", "anim/swap_moonsword.zip"), Asset("ATLAS", "images/inventoryimages/moonsword.xml"), Asset("IMAGE", "images/inventoryimages/moonsword.tex"),}prefabs = {}local function fn() local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_moonsword", "swap_moonsword") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") end local function OnUnequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") end local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() local sound = inst.entity:AddSoundEmitter() MakeInventoryPhysics(inst) anim:SetBank("moonsword") anim:SetBuild("moonsword") anim:PlayAnimation("idle") inst:AddTag("sharp") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("weapon")--This should cause the sword to do more damage at night. But it isn't functioning. local function updatesworddamage(inst, phase) if phase == "day" then inst.components.weapon:SetDamage(37) elseif phase == "night" then inst.components.weapon:SetDamage(65) elseif phase == "dusk" then inst.components.weapon:SetDamage(51) endend inst:AddComponent("inspectable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "moonsword" inst.components.inventoryitem.atlasname = "images/inventoryimages/moonsword.xml" inst:AddComponent("equippable") inst.components.equippable:SetOnEquip( OnEquip ) inst.components.equippable:SetOnUnequip( OnUnequip ) return inst endreturn Prefab("common/inventory/moonsword", fn, assets, prefabs)There are no crashes when the mod compiles and is used. It just does the default punching damage. The mod as it is currently is below. All art is placeholder and will change. (The sword assets are from the "Taronci" mod on the workshop)Sword.zip Link to comment Share on other sites More sharing options...
przemolsz Posted July 30, 2015 Share Posted July 30, 2015 So you've got your function that processes the phase and changes damage, but the issue is it's never called. You need to make a hookup in your code to make it be called every once the phase changes. Just add those lines:inst:WatchWorldState("phase", updatesworddamage)updatesworddamage(inst, TheWorld.state.phase) --We also need the damage to be set when the item is createdYou might also want to move updatesworddamage, OnEquip and OnUnequip functions out of the fn function. It's not like it would change anything in the code's behaviour, it's just nice to have everything written in a style similar to that of the original game files. Link to comment Share on other sites More sharing options...
PrinceKawaii Posted July 31, 2015 Author Share Posted July 31, 2015 Thank you! This worked perfectly! 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