File information

Last updated

Original upload

Created by

Krimson

Uploaded by

KrimsonKhaos

Virus scan

Safe to use

Tags for this mod

13 comments

  1. sourceror
    sourceror
    • premium
    • 0 kudos
    Unfortunately, this has a number of issues:

    • Adding Soul Trap to the bow does not work: triggers too late..? (Edit: I'll need to test this with 2 sec Soul Trap. User error?)
    • Does not check charge level before casting spell.
    • (This also means it's incompatible with e.g. Controlled Weapon Enchants.)
    • Config does not get saved. Config saves to "Cast on Hit Bows" but loads from "Auto Harvest"
    • playerOnly config var means the opposite of its name
    Opinion:

    • Sound and animation should not play on character on cast.
    • Animation should not play on hit point for non-area-effect enchants.
    I think this needs more work.

    Edit: I made a new version of this mod for personal use. Krimson kindly gave me permission to release it on the Nexus. I'll upload it in a week or so, after I have a chance to do some more stress-testing.
    1. SolaireJM
      SolaireJM
      • member
      • 0 kudos
      Did you ever get around to releasing your version? Sound great :)
    2. ysehporp
      ysehporp
      • member
      • 0 kudos
      Did you post it ever?
    3. HadToRegister
      HadToRegister
      • premium
      • 196 kudos
      So where is this improved mod?
  2. Yakobeeem
    Yakobeeem
    • member
    • 0 kudos
    Is this mod still in development, or does anybody have a version that irons out the remaining bugs?
  3. Shangallar
    Shangallar
    • member
    • 1 kudos
    That "fixed" main.lua below also removes the configuration options from the Mod Config menu. Fix one, break the other, eh?
    1. pr0tan0pia
      pr0tan0pia
      • premium
      • 1 kudos
      Oh probably yeah, it is what it is, a quick fix. Use at your own risk
  4. pr0tan0pia
    pr0tan0pia
    • premium
    • 1 kudos
    Love the mod but the lua script doesn't work as intended, the spell will be triggered even if there is not enough charge left.
    Fixed main.lua:
    local config = mwse.loadConfig("Auto Harvest", {
        playerOnly = true,
        AOEDamage = true,
    })

    local function projectileHit(e)

        if config.playerOnly == false then

            if e.firingReference ~= tes3.player then

                return
            end
        end

        if e.firingWeapon.type == (tes3.weaponType.marksmanBow or tes3.weaponType.marksmanCrossbow) then

            if e.firingReference == e.target then

                return
            end

            local weapEnchant = e.firingWeapon.enchantment
            local equippedBow = tes3.getEquippedItem({ actor = e.firingReference, objectType = tes3.objectType.weapon, type = tes3.weaponType.marksmanBow })
            local equippedXbow = tes3.getEquippedItem({ actor = e.firingReference, objectType = tes3.objectType.weapon, type = tes3.weaponType.marksmanCrossbow })
            local enchantCostBow
            local enchantCostXbow
            local projectileSpell
            local impactObject
            local radius = 0

            if weapEnchant == nil then

                return
            end

            if projectileSpell == nil then

                projectileSpell = tes3.createObject({ objectType = tes3.objectType.spell, effects = weapEnchant.effects })
            end

            if impactObject == nil then

                impactObject = tes3.createObject({ objectType = tes3.objectType.miscItem, id = "Krimson_impactObject", mesh = [[sve\sve_invisible_cube.nif]]})
            end

            if weapEnchant.castType == tes3.enchantmentType.onStrike or tes3.enchantmentType.onUse then

                if config.AOEDamage then

                    for i = 1, #projectileSpell.effects do

                        local effectIndex = projectileSpell.effects[i]

                        if radius < effectIndex.radius then

                            radius = effectIndex.radius
                        end
                    end

                    if e.collisionPoint:distance(e.firingReference.position) <= radius * 22.1 then

                        local effectList = {}
                        local aoeSpell

                        for _, effect in pairs (projectileSpell.effects) do

                            if effect ~= nil then

                                if e.collisionPoint:distance(e.firingReference.position) <= effect.radius * 22.1 then

                                    table.insert(effectList, effect)
                                end
                            end
                        end

                        if not table.empty(effectList) then

                            if aoeSpell == nil then

                                aoeSpell = tes3.createObject({ objectType = tes3.objectType.spell, effects = effectList })
                            end

                            for _, effect in pairs (aoeSpell.effects) do

                                if effect.radius > 0 then

                                    effect.radius = 0
                                end
                            end

                            tes3.cast({ reference = e.firingReference, target = e.firingReference, spell = aoeSpell, instant = true, alwaysSucceeds = true })
                        end

                        if not table.empty(effectList) then

                            for i = 1, #effectList do

                                table.removevalue(effectList, i)
                            end
                        end
                    end
                end

                if equippedBow then

                    enchantCostBow = tes3.calculateChargeUse({ enchantment = e.firingWeapon.enchantment, mobile = e.firingReference.mobile })

                    if equippedBow.itemData.charge >= weapEnchant.chargeCost then
                            --Casts the spell after checking the weapon charge
                            local impactRef = tes3.createReference({ object = impactObject, position = e.collisionPoint, orientation = 0 })
                            local impactTarget = impactRef or e.target
                            tes3.cast({ reference = e.firingReference, target = impactTarget, spell = projectileSpell, instant = true, alwaysSucceeds = true })
                            equippedBow.itemData.charge = equippedBow.itemData.charge - enchantCostBow
                    end
                end

                if equippedXbow then

                    enchantCostXbow = tes3.calculateChargeUse({ enchantment = e.firingWeapon.enchantment, mobile = e.firingReference.mobile })

                    if equippedXbow.itemData.charge >= weapEnchant.chargeCost then
                            --Casts the spell after checking the weapon charge
                            local impactRef = tes3.createReference({ object = impactObject, position = e.collisionPoint, orientation = 0 })
                            local impactTarget = impactRef or e.target
                            tes3.cast({ reference = e.firingReference, target = impactTarget, spell = projectileSpell, instant = true, alwaysSucceeds = true })
                            equippedXbow.itemData.charge = equippedXbow.itemData.charge - enchantCostXbow
                    end
                end

               

                if impactRef then

                    impactRef:disable()
                end

                if impactRef.diabled then

                    impactRef:delete()
                end
            end
        end
    end

    local function registerConfig()

        local template = mwse.mcm.createTemplate("Cast on Hit Bows")
            template:saveOnClose("Cast on Hit Bows", config)
            template:register()

        local page = template:createSideBarPage({
            label = "Cast on Hit Bows",
            description = "Any arrow shot with any bow will now use the bows \"cast on strike\" or \"cast on use\" enchantment on what ever it hits.\n\nWill work with any mod added bows/arrows also.\n\nBows used by NPCs are also affected if that setting is turned on.\n\nBe careful of using AoE enchantments, they can hurt you too if the setting is turned on.\n\nGOD MODE WILL NOT STOP THE DAMAGE TO YOU!!!!!!\n\n",
        })

        local settings = page:createCategory("Cast on Hit Bows Settings\n\n\n")

        settings:createOnOffButton({
            label = "Enables NPCs using Cast on Hit Bows",
            description = "Turns on/off NPCs bows from being Cast on Hit.\n\nDefault: On\n\n",
            variable = mwse.mcm.createTableVariable {id = "playerOnly", table = config }
        })

        local settings2 = page:createCategory("\n\n\n\n")

        settings2:createOnOffButton({
            label = "Enables AOE Damage to the attacker",
            description = "Turns on/off the attacker taking damage from \"Area of Effect\" enchantments shot from their bows when too close of what the arrow hits.\n\nDefault: On\n\n",
            variable = mwse.mcm.createTableVariable {id = "AOEDamage", table = config }
        })
    end

    event.register("modConfigReady", registerConfig)

    local function onInitialized()

        event.register("projectileHitActor", projectileHit)
        event.register("projectileHitObject", projectileHit)
        event.register("projectileHitTerrain", projectileHit)
        mwse.log("[Krimson] Cast on Hit Bows: Initialized")
    end

    event.register("initialized", onInitialized)
  5. ahalopooka
    ahalopooka
    • supporter
    • 0 kudos
    Does not work?!
    Strike enchants behave like vanilla still.
    I have newest version of mwse
    1. ahalopooka
      ahalopooka
      • supporter
      • 0 kudos
      okay bows work but xbows don't :D
  6. whitenomad
    whitenomad
    • member
    • 0 kudos
    Hello!
    Is there any MCP settings that could broke that mod? I've made just the same bow as u on screenshots, but it doesnt work for me(
    MWSE version 2.1, i can see mod settings in menu, but enchanted on hit bow just strike as usual, without any effects.
  7. inpv
    inpv
    • member
    • 14 kudos
    Any chance to add this functionality to crossbows as well?
    1. KrimsonKhaos
      KrimsonKhaos
      • member
      • 14 kudos
      It already works for crossbows, guess I could have put that in the description