Jump to content

GetEquippedWeapon().GetAmmo() returns base ammo type only.


littleerve

Recommended Posts

maybe someone can confirm if this is me or the mod im using, but I can't seem to use: GetEquippedWeapon().GetAmmo() to return the correct ammo type, it returns the default ammo type for the weapon. I've tried it with the hunting rifle and some modded weapons and I get the same result.

 

Is there anyway to get the currently equipped ammo type?

Link to comment
Share on other sites

Yes it returns base ammo for that weapon form. Its because getequipped weapon returns weapon form and not specific objectreference which may have omod changing ammo type it uses. Nothing can be done with that and there is no direct way to do what you want. (There may be messy workarounds but nothing that can be easily done)
Link to comment
Share on other sites

Hmm so I'd just have to check a list of ammo keywords with WornHasKeyword, doesn't sound too hard, I'm not good with arrays tho, i'll have to do some more reading.

 

Edit: Hmm I'd want to check a list of every ammo type as i'm trying to make a generic script for all weapons. I'd have to somehow make an array with every ammo that has the keyword ObjectTypeAmmo and then check it with WornHasKeyword.

 

Edit2: Maybe I can make a formlist of all the ammotypes hmm

Edited by littleerve
Link to comment
Share on other sites

  • 2 weeks later...

Don't be afraid to ask for scripting help if that's all that's standing in the way of what you want to do. Obviously, you can get the base ammo type and that's almost certainly going to cover you in most cases. There aren't too many other edge cases considering mods that can alter ammo types. I can think of a few ways I would go about this in terms of scripting and one of them is even open-ended so that plugins adding weapon mods that change ammo type can easily be incorporate to truly make your script generic. Granted, even without that feature your what you're looking to do might be more complicated that you expected, but that's not a huge deal-breaker, IMO.

 

The underlying issue is that you need to associate a particular keyword with a particular ammo type. The way to go about that would be a struct. More precisely, you'll need an array of them and you'll need to iterate over it to check for each keyword that might alter the ammo type. If Papyrus didn't have certain restrictions on what can and cannot go in to structs and arrays, it would be possible to make this lookup process more efficient. Strictly speaking, it still is, but it would become convoluted to the point of impracticality. Regardless, that's what you'll need. If you intend to make your script something that third-party plugins can interact with (or better yet, you intend to write a plugin that will detect plugins that interest you and automatically pull in the appropriate data from them,) you'll want to add a function to the script you write that adds another of your structs to the array.

 

Does that help any?

Link to comment
Share on other sites

If you are going to be doing such a check anyway, rather than the struct you could create a giant "if" block and shorten the check speed with creative use of what you are checking, perhaps.

 

Make a property of all your ammo types and make a property of all your relevant keywords. Now, make properties of keywords defining the weapons type (rifle, shotgun, pistol etc). The first check will be for the type. Then you have if blocks inside each of them, with a list of all known keywords that change ammo, and I would imagine you'd try to put this in order of how common the gun in question is/keyword (how likely this keyword is gonna appear) as to try to speed this up for common guns.

 

Loose Example

 

If HasKeyword Pistol

If HasKeyword Some10mmMod

EquippedAmmo == 10mm

Elseif HasKeyword Some45Mod

EquippedAmmo == 45

Endif

Elseif HasKeyword Rifle

Etc etc etc

 

Typing on phone but hoping you catch my drift. I can see, like it has been said, that there's no straight up cleaning way to do it. But that seems simple to me. Array searching, I can't imagine it's gonna be any faster.

Link to comment
Share on other sites

  • 3 months later...
  • Recently Browsing   0 members

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