Jump to content

Lighting provoked electric damage weapon help


Recommended Posts

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 by FelineDreams
Link to comment
Share on other sites

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 by FelineDreams
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...