Jump to content

Trying to run a script on a weapon's owner whenever they attack


trashgarbage666

Recommended Posts

Hey guys!! Like the title reads, I'm trying to attach a script to a weapon that runs on the weapon's owner whenever they attack with it. I'm using JIP + NVSE, so I have access to all the additional commands they provide.

 

The script itself only needs to do a couple of things:

1) Determine who owns the weapon

2) Run CreateDetectionEvent on the owner

 

Pretty simple stuff! I'm just not sure how it all hooks together. For example, which script block should I use? In order to get the owner, would I have to run GetSelf on the weapon, and then GetOwner on the weapon reference? And so on.

 

I feel like the solution is right in front of me, and that I'm just not seeing it.

 

EDIT: I found a script block called OnFire, which, like its name would suggest, runs whenever the scripted weapon gets fired. So I typed up a quick test script that places a CreateDetectionEvent on the player, and ...it kind of worked? But only kind of. If I quickload, or manually load from another save slot, the script stops working entirely. If I exit to the main menu and load again, it'll work again briefly until the next time I load a save. No idea why.

Edited by punchbattle
Link to comment
Share on other sites

Are you sure GetOwner is returning the actor firing the weapon ? I would think "GetContainer" would be what you would need. Isn't Owner just used for crime ? Or is the ownership of an item set upon being in an npc inventory ?

 

So what is it you are trying to do upon firing a weapon to the weapon user ?

 

Did you see this? https://geckwiki.com/index.php/SetOnFireWeaponEventHandler

 

or is that not what needs to happen ?

Link to comment
Share on other sites

Sorry for the late response! After a few days of silence, I figured everyone else to be as stumped as I was, haha. But I was eventually able solve this issue on my own! Well, more or less.

A while back, I discovered a really helpful command called ToggleCombatDebug, or TCD. Running it in-game adds graphical elements to combat that help give you a better understanding of what's going on under the hood. For instance, one really helpful thing it does is create teal bubbles (called Detection Events) to mark sounds made by the player and NPCs. If an NPC is close enough to a Detection Event, they'll begin searching for the enemy it belongs to. This revealed something very... odd. And bad. The only part of a gunshot that creates a Detection Event is the bullet, and only at the place of impact. This means NPCs will completely ignore the sound of the gun going off, and instead choose to wander right into the enemy's crosshairs. Bethesda is infamous for their shitty stealth systems, but learning about this completely ruined stealth for me, and I wanted to fix it.

 

There's a function that lets you make your own Detection Events. It's called CreateDetectionEvent.

https://geckwiki.com/index.php/CreateDetectionEvent

 

I played around with it for days. My initial idea was to attach a script to a gun, and have it create a detection event at the location of the shooter whenever they pull the trigger. This didn't work for a number of reasons. Now I have a quest that checks for anyone with a gun doing an attack animation, and casts a detection event spell on them. Works perfectly, as far as I can tell!

 

For anyone reading this who wants to mess around with detection events as well: Any field that asks you to assign a Sound Level to a weapon or projectile is actually asking you how big you want your weapon's detection event bubble to be. But remeber! Weapons don't actually create detection events when fired, despite what the GECK seems to imply. The size of each Sound Level is controlled by these settings

 

iSoundLevelLoud - 100

iSoundLevelNormal - 50

iSoundLevelSilent - 10

 

I've read people say that detection events can't be larger than 100, but this isn't true. You can assign values into the thousands, and it still works. Also, 100 is ...very small.

Link to comment
Share on other sites

Thank you! That is some excellent detective work and useful information (TCD and "detection event bubble") I will be adding to the wiki "Getting started creating mods using GECK" article.

 

I had actually looked at "Sound Level" recently (as relates to "silencers" because none sounded like they had any effect) but hadn't followed up on it's details. Even set to "Sound Level = Silent" there was no apparent reduction in the volume of the sound from the chosen sound file (which makes a big difference). I didn't conduct the experiment you performed as to how that translated into the game, but the range of "bubble size" values you discovered makes me wonder if that isn't perhaps a percentage multiplier to the bubble size? That would seem to make more sense than it being a distance unit in game terms. As you say, 100 units is a very small distance. 128 units is the equivalent of a 6ft tall (default) NPC.

 

-Dubious-

Link to comment
Share on other sites

I'll be doing that TCD too thanks for the mention. But in my previous testing ... there are 2 components to detection.

 

What I thought was audio ... and the other visual.

 

Also matters the perception of the detecting npc , which seemed to have a sharp curve.

Link to comment
Share on other sites

Thank you! That is some excellent detective work and useful information (TCD and "detection event bubble") I will be adding to the wiki "Getting started creating mods using GECK" article.

 

I had actually looked at "Sound Level" recently (as relates to "silencers" because none sounded like they had any effect) but hadn't followed up on it's details. Even set to "Sound Level = Silent" there was no apparent reduction in the volume of the sound from the chosen sound file (which makes a big difference). I didn't conduct the experiment you performed as to how that translated into the game, but the range of "bubble size" values you discovered makes me wonder if that isn't perhaps a percentage multiplier to the bubble size? That would seem to make more sense than it being a distance unit in game terms. As you say, 100 units is a very small distance. 128 units is the equivalent of a 6ft tall (default) NPC.

 

-Dubious-

 

I'm really glad you found it helpful! :D

 

Actually, I have a few more bits of information that might be of interest. I'm speculating here, but I think the bullet's Sound Level may also be unused. This is strictly a gut feeling, but I think the bullet only determines the location of the bubble, and that the actual radius of the Detection Event is determined by the Sound Level listed in the Impact Data belonging to the material the bullet collides with. Also! Even if you set iSoundLevelSilent below 10, "Silent" sound sources will still have a minimum radius of 10.

 

I'll be doing that TCD too thanks for the mention. But in my previous testing ... there are 2 components to detection.

 

What I thought was audio ... and the other visual.

 

Also matters the perception of the detecting npc , which seemed to have a sharp curve.

 

This is entirely possible! I know that NPCs don't have be physically inside a Detection Event in order to perceive them. Maybe TCD only displays the base radius of a Detection Event, while other factors dictate how close an NPC has to be to one in order to become alerted.

Edited by punchbattle
Link to comment
Share on other sites

I also think your suspicion is on the money: the actual sound file volume is immaterial. Only the "event" that a sound was played, and a "sound level" is set for that event, along with distance from source to the observer. But more testing is needed to confirm. The reason I didn't follow up was I couldn't figure out how to conduct testing and it was only a matter of curiosity at the time. (Haven't had the time to look into the TCD command to see how it works yet. Away from my game machine at the moment.) But knowing it is possible is half the battle.

 

-Dubious-

Link to comment
Share on other sites

Added 'TIP: TCD and Gunfire Detection Events' to the "Music & Sounds" section of the wiki "Getting started creating mods using GECK" article.

 

And writing that up made me realize my previous comment missed the mark completely. As you point out: the sound file has nothing to do with the "Detection Event". That is triggered by the projectile impact! The "Sound Level" setting contributes to this misconception as it is actually setting the size of the "Detection Event bubble" of the impact. Putting "sound" in the description is misleading, even though obviously this is an attempt to simulate "sound detection" in a backhanded way.

 

Another piece of the puzzle that is GECK solved. Congrats.

 

-Dubious-

Link to comment
Share on other sites

  • Recently Browsing   0 members

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