FelineDreams Posted May 14, 2019 Share Posted May 14, 2019 (edited) I have done most of the modding for the character mod I am making, yet I am having trouble with making a character unique item (a knife to be more specific) have electric damage only when it gets struck by lighting. I plan on the knife staying charged for four to five hits until it goes back to being a (relatively) normal knife yet I haven't been able to get either of these feats working. Does anyone have any tips to help with this? Edited May 14, 2019 by FelineDreams Link to comment Share on other sites More sharing options...
FelineDreams Posted May 15, 2019 Author Share Posted May 15, 2019 (edited) The coding I did for the knife is here just in case you need to see Spoiler local Assets = { Asset("ANIM", "anim/ether_knife_build.zip"), -- a standard asset Asset("ATLAS", "images/inventoryimages/ether_knife.xml"), } local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_nightmaresword", "swap_nightmaresword") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") local function fn(Sim) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork MakeInventoryPhysics(inst) inst.AnimState:SetBank("ether_knife") inst.AnimState:SetBuild("ether_knife_build") inst.AnimState:PlayAnimation("idle", true) inst.AddTag("sharp") inst.AddTag("ether") inst.AddComponent("weapon") inst.components.weapon:SetDamage(TUNING.NIGHTSTICK_DAMAGE) inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/ether_knife.xml" inst:AddComponent("inspectable") return inst end local function discharge(inst) if inst.charged then inst.Light:Enable end STRINGS.NAMES.ETHER_KNIFE = "Ether Knife" STRINGS.CHARACTERS.GENERIC.DESCRIBE.ETHER_KNIFE = "A knife with a magical power within." return Prefab( "common/inventory/ether_knife", fn, Assets) Edited May 15, 2019 by FelineDreams Link to comment Share on other sites More sharing options...
Ultroman Posted May 15, 2019 Share Posted May 15, 2019 So, how do you want this to work? Do you want to have to place the item on the ground, and wait for it to be struck by lightning? Or should it get charged when the character is struck by lightning? Why would lightning strike it? Lightning is pretty random. Link to comment Share on other sites More sharing options...
FelineDreams Posted May 15, 2019 Author Share Posted May 15, 2019 I want it to charge when the character is struck by lightning. I wanted to balance it out a bit by making it that way since lightning is random (with the exception being wickerbottom's the end is neigh book). Link to comment Share on other sites More sharing options...
Ultroman Posted May 15, 2019 Share Posted May 15, 2019 For that, may I suggest you study the component file "playerlightningtarget.lua". It has the following function, which is called when the player is struck by lightning. local DefaultOnStrike = function(inst) if inst.components.health ~= nil and not (inst.components.health:IsDead() or inst.components.health:IsInvincible()) then if not inst.components.inventory:IsInsulated() then local mult = TUNING.ELECTRIC_WET_DAMAGE_MULT * inst.components.moisture:GetMoisturePercent() local damage = TUNING.LIGHTNING_DAMAGE + mult * TUNING.LIGHTNING_DAMAGE -- Magic hit point stuff that isn't being used right now -- if damage >= inst.components.health.currenthealth - 5 and inst.components.health.currenthealth > 10 then -- damage = inst.components.health.currenthealth - 5 -- end inst.components.health:DoDelta(-damage, false, "lightning") inst.sg:GoToState("electrocute") else inst:PushEvent("lightningdamageavoided") end end end As you can see, if it hits and does damage, it calls DoDelta, giving the cause as "lightning", so you can listen to your character's "healthdelta" event, check the "data" parameter you are passed for the "cause" value, and see if it's "lightning". If it is, do something to the character's items. Then you will probably also want to listen to the event "lightningdamageavoided", so you can react to that, too. Link to comment Share on other sites More sharing options...
FelineDreams Posted May 16, 2019 Author Share Posted May 16, 2019 ok thanks, I will look into it 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