Jump to content

Scripting a weapon backfiring


adb3nj

Recommended Posts

Or, more specifically, I'm trying to balance the legendary explosive effect by adding a chance of a bullet exploding in the barrel. I know I want something along the lines of this:

Scriptname UniqueWeapons:ExplodeBulletInBarrelScript extends ActiveMagicEffect

Actor Property PlayerRef Auto Const
ActorValue Property Health Auto Const
Spell Property BulletExplodingInBarrel Auto Const
Int Property Min = 1 const auto
Int Property Max = 100 const auto
Float Property fDamage = 5.0 const auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
    RegisterForAnimationEvent(PlayerRef,"WeaponFire")
endEvent

Event OnAnimationEvent(ObjectReference akSource, string asEventName)
    int roll = Utility.RandomInt(Min, Max)
    if roll < 3
        debug.notification("Bullet exploded in barrel.")
;       PlayerRef.DamageAV(Health, fDamage)
;       OR BulletExplodingInBarrel.Cast(akCaster, akTarget)
    else
        debug.notification("Bullet did not explode in barrel.")
    endIf
endEvent

The problem I'm having is, I can't call DamageAV without extending the Actor script, and I can't call Cast outside of the OnEffectStart event, so what to do? This part of scripting always trips me up :sad:

Edited by adb3nj
Link to comment
Share on other sites

The Explosive Object Mod (OMOD) just overrides the Projectile of the weapon reference that has the OMOD. The projectile places the actual Explosion that deals the damage.

 

You can place that projectile in front of the player if you'd like to make a "bullet exploaded in the barrel effect" with PlayerRef.PlaceAtMe(ExplosiveProjectile, abInitiallyDisabled = True), MoveTo() the barrel, then Enable() it.

Link to comment
Share on other sites

The Explosive Object Mod (OMOD) just overrides the Projectile of the weapon reference that has the OMOD. The projectile places the actual Explosion that deals the damage.

 

You can place that projectile in front of the player if you'd like to make a "bullet exploaded in the barrel effect" with PlayerRef.PlaceAtMe(ExplosiveProjectile, abInitiallyDisabled = True), MoveTo() the barrel, then Enable() it.

 

 

Do you have something specific in mind with regard to using MoveTo to get it to the barrel? The best I can come up with is MoveTo(PlayerRef, afZOffset = 100.0), but it's not very precise. I could also potentially use MoveToNode if I could work out player character node names, but I tried copying one from the mesh and I guess those aren't the nodes it's supposed to be used with…

Link to comment
Share on other sites

Hypothetically you could use the weapon's nodes?

You just have to get the specific reference the player is holding.

 

EDIT: I wrote that wrong, I'm very tired lol

 

If you look at my Weapon Strength Requirements mod, you can Champollion the script and look at my functions, one of them gets the weapon the player is holding and I believe you could use that Owner, ThisInstance.

Link to comment
Share on other sites

 

The Explosive Object Mod (OMOD) just overrides the Projectile of the weapon reference that has the OMOD. The projectile places the actual Explosion that deals the damage.

 

You can place that projectile in front of the player if you'd like to make a "bullet exploaded in the barrel effect" with PlayerRef.PlaceAtMe(ExplosiveProjectile, abInitiallyDisabled = True), MoveTo() the barrel, then Enable() it.

 

 

Do you have something specific in mind with regard to using MoveTo to get it to the barrel? The best I can come up with is MoveTo(PlayerRef, afZOffset = 100.0), but it's not very precise. I could also potentially use MoveToNode if I could work out player character node names, but I tried copying one from the mesh and I guess those aren't the nodes it's supposed to be used with…

 

The weapon reference the player holds is treated as an inventory item so probably you won't be able to use it as akTarget for MoveToNode(). (It might worth mentioning that MoveToNode() also requires the object's 3D to be rendered in order to work).

 

As for the positioning, this would move the projectile in front of the targetActorRef.

ProjectileRef.MoveTo(targetActorRef, 60.0 * Math.Sin(targetActorRef.GetAngleZ()), 60.0 * Math.Cos(targetActorRef.GetAngleZ()), 125)

Regarding ThisInstance and Owner, take a look at F4SE's script object InstanceData.

Edited by LarannKiar
Link to comment
Share on other sites

I've tried the following:

InstanceData:Owner thisInstance = PlayerRef.GetEquippedWeapon().GetInstanceOwner()
thisInstance.PlaceAtMe(explosionInBarrel)

but I get the compilation error, 'instancedata#owner is not a known user-defined script type'. Trying to use functions from the InstanceData script works fine though, so I'm guessing what I'm trying to do isn't possible without a plugin? Or am I missing steps in the script? My interpretation is 'thisInstance' functions as an object reference, but that doesn't seem to be accurate.

Link to comment
Share on other sites

LarannKiar is right, I had forgotten that the InstanceData structs don't contain the loaded ObjectReference of the weapon, only the form ie the base data of the weapon. They're very useful but not for what you're doing.

Back when I was attempting to work on a mod to make a power armor mounted turret, I was able to place it at a node that was loaded at the time on the player's skeleton(power armor skeleton). I didn't try it and don't know if it's possible but perhaps while you are holding the weapon, it counts as part of the skeleton for the purposes of weighting it to the hand bones, which SHOULD mean that you can just assume the weapon's nodes exist and are there to maybe be utilized by a PlaceAtNode call.

You'll just need the name of the weapon's barrel node presumably.

ie

Self.GetActorRef().PlaceAtNode("BarrelNode", explosionInBarrel, 1, False, False, True, True)

But again, this is theoretical.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...