Jump to content

Script Assistance - Get Ammo List For Active Weapon


ThatOtherUser

Recommended Posts

I'm really hoping this isn't as complex as it may end up being, but here we go.

 

Right now, I'm working on a modification to Wasteland Defense that will allow me to use the Armory to restock the currently equipped (or owned) weapon of the guards, as well as the ammo currently in use. Now, I think it may be harder to just grab the equipped ammo than it would be to get the entire ammo list for the weapon, but both have me hitting a wall.

 

I'm not sure how to get that information through a script command, nor do I really know how to write the command myself. I'm still new to all this, so I'm depending on functions already provided in the GECK and New Vegas Script Extender.

 

Does anyone know how to get this, or possibly a simple way to? I know there's gotta be a way, since the ammo list is in the weapon's properties. Even if I have to rip it from the weapon's table, I'll do it, but it's gotta exist.

 

I hope. Otherwise, I have a lot of coding to do.

 

Mind you, this isn't about any bugs in the script. This is just looking for a function.

Link to comment
Share on other sites

Alright, sorry fellas, but I need some more help. Here's the script I've got right now, pulled from Wasteland Defense's code. I've marked my own edits in bold.

 

 

 

SHORT randomweapon
SHORT Button
SHORT Active
SHORT recalled
SHORT rearmed
SHORT healed
SHORT count
REF equippedweapon
REF equippedammo
REF guard

 

...

 

; Test script: Let's see if I can actually get the available weapon and ammo that the guard has, and then restock it with that same weapon and ammo.

if aaaSettlementFortRaid.rearmguards == 1 && rearmed == 0
if guard.GetEquippedObject 5 == 1
set equippedweapon to GetEquippedObject 5
set ammolist to equippedweapon.GetWeaponAmmo
removeitem equippedweapon
additem equippedweapon 1
additem ammolist 50
elseif guard.GetEquippedObject 5 == 0
if randomweapon < 25
if GetItemCount WeapNVLeverActionShotgun > 0
Set count to GetItemCount WeapNVLeverActionShotgun
removeitem WeapNVLeverActionShotgun count
endif
if GetItemCount Ammo20ga > 0
Set count to GetItemCount Ammo20ga
removeitem Ammo20ga count
endif
additem WithAmmoLeverActionShotgunLoot 1
elseif randomweapon < 50
if GetItemCount WeapNVCowboyRepeater > 0
Set count to GetItemCount WeapNVCowboyRepeater
removeitem WeapNVCowboyRepeater count
endif
if GetItemCount Ammo357Magnum > 0
Set count to GetItemCount Ammo357Magnum
removeitem Ammo357Magnum count
endif
additem WithAmmoNVCowboyRepeaterLoot 1
elseif randomweapon < 75
if GetItemCount WeapNVVarmintRifle > 0
Set count to GetItemCount WeapNVVarmintRifle
removeitem WeapNVVarmintRifle count
endif
if GetItemCount Ammo556mm > 0
Set count to GetItemCount Ammo556mm
removeitem Ammo556mm count
endif
additem WithAmmoNVVarmintRifleLoot 1
else
if GetItemCount Weap10mmSubmachineGun > 0
Set count to GetItemCount Weap10mmSubmachineGun
removeitem Weap10mmSubmachineGun count
endif
if GetItemCount Ammo10mm > 0
Set count to GetItemCount Ammo10mm
removeitem Ammo10mm count
endif
additem WithAmmo10mmSubmachineGunRaider 1
endif
AddItem LootGrenadeFrag10 1
Set aaaSettlementFortRaid.recalltimer to 5
Set rearmed to 1
endif
endif
The end result I'm needing here is this:
If the guard has a weapon, take the weapon, remove it, and add the weapon back with some ammo for it.
If the guard doesn't have a weapon, check its randomweapon value and give it a gun with ammo.
There's a syntax error somewhere in here, and I do have the properly defined variables, which I've put at the top of the code block. I'm certain I'm using GetEquippedObject wrong, but I'm not sure.
Is there a GetActor function, possibly? Or am I just going about this wrong?
Edited by ThatOtherUser
Link to comment
Share on other sites

GetEquippedObject returns a base object, not a reference, so you can't use GetWeaponAmmo as a reference function. You need to use the base form calling convention or call the function directly on the guard instead.

 

What is the script attached to? You're using both explicit and implied reference syntax. You're calling GetEquippedObject on a reference (guard) but AddItem/RemoveItem/GetItemCount are not being called on the same reference.

 

Is this the complete script? I see no Begin block. I also don't see the randomweapon variable being set anywhere.

Edited by Ladez
Link to comment
Share on other sites

GetEquippedObject returns a base object, not a reference, so you can't use GetWeaponAmmo as a reference function. You need to use the base form calling convention or call the function directly on the guard instead.

 

What is the script attached to? You're using both explicit and implied reference syntax. You're calling GetEquippedObject on a reference (guard) but AddItem/RemoveItem/GetItemCount are not being called on the same reference.

 

Is this the complete script? I see no Begin block. I also don't see the randomweapon variable being set anywhere.

 

No, this isn't the full script. Don't worry, I got it working properly, I was facing several problems including getting some commands wrong.

 

This is part of the aaaSettlementFortGuardScript, the section devoted to rearming the guards. And yeah, I wanted to return the base object.

 

I've since removed the 'guard' reference and just stuck with implicit references. The script wasn't breaking due to that, it was due to me just writing the commands wrong. Thanks, though!

 

Next project is writing a companion.

Link to comment
Share on other sites

GetEquippedObject returns a base object, not a reference, so you can't use GetWeaponAmmo as a reference function.

You CAN, however, use
GetEquippedObject != 0
as a condition to test that the guard has a weapon. Personally, I'd be arranging it like
if (guard.GetEquippedObject 5)
	; This block runs if 'guard' has any weapon equipped. Any weapon at all. The hardcoded "Fist" weapon might actually count - you'd better check.
	; This above condition is functionally-identical to "if guard.GetEquippedObject 5 != 0".
	;   Either way the scripting engine has to evaluate if the condition is equal to zero or not, so you're shaving a couple of cycles off this way.
else
	; This block runs if the reference has no weapon equipped at all. It may never execute - see above.
endif
Also, keep in mind that by using AddItem AmmoList 50, you'll be adding 50 rounds of EVERY SINGLE VALID TYPE OF AMMO for that weapon. The ammolist you'll receive from the weapon is just a formlist of every single round the weapon is allowed to use. If the ammolist returned is AmmoList308, for example, the guard will now be carrying 50 rounds of regular .308, 50 rounds of .308 hollowpoint, 50 rounds of .308 AP, and 50 rounds of .308 JSP - and that's just if the player's running completely vanilla, no DLC or other mods. If the user has installed mods that add to that list, there'll be even more ammo on the guard now. This might be desireable behaviour; if it isn't though, you'd better figure something else out. Edited by DaWrecka
Link to comment
Share on other sites

You CAN, however, use
GetEquippedObject != 0
as a condition to test that the guard has a weapon.

 

I never said otherwise. I'm not sure what you're trying to argue here, he's already testing whether the guard has a weapon in that exact way.

 

Also, keep in mind that by using AddItem AmmoList 50, you'll be adding 50 rounds of EVERY SINGLE VALID TYPE OF AMMO for that weapon.

 

This is true, I completely missed that. It's safe to assume that NPCs are not using special ammo types, so just adding the first type of ammo from the list would do the trick.

Set rEquippedWeapon to GetEquippedObject 5
Set rAmmo to GetWeaponAmmo rEquippedWeapon
Set rAmmo to ListGetNthForm rAmmo 0
AddItem rAmmo 50
Edited by Ladez
Link to comment
Share on other sites

 

GetEquippedObject returns a base object, not a reference, so you can't use GetWeaponAmmo as a reference function.

You CAN, however, use
GetEquippedObject != 0
as a condition to test that the guard has a weapon. Personally, I'd be arranging it like
if (guard.GetEquippedObject 5)
	; This block runs if 'guard' has any weapon equipped. Any weapon at all. The hardcoded "Fist" weapon might actually count - you'd better check.
	; This above condition is functionally-identical to "if guard.GetEquippedObject 5 != 0".
	;   Either way the scripting engine has to evaluate if the condition is equal to zero or not, so you're shaving a couple of cycles off this way.
else
	; This block runs if the reference has no weapon equipped at all. It may never execute - see above.
endif
Also, keep in mind that by using AddItem AmmoList 50, you'll be adding 50 rounds of EVERY SINGLE VALID TYPE OF AMMO for that weapon. The ammolist you'll receive from the weapon is just a formlist of every single round the weapon is allowed to use. If the ammolist returned is AmmoList308, for example, the guard will now be carrying 50 rounds of regular .308, 50 rounds of .308 hollowpoint, 50 rounds of .308 AP, and 50 rounds of .308 JSP - and that's just if the player's running completely vanilla, no DLC or other mods. If the user has installed mods that add to that list, there'll be even more ammo on the guard now. This might be desireable behaviour; if it isn't though, you'd better figure something else out.

 

 

Adding the full ammolist was the intention, so no worries about that. It was mostly to just restock the guard with everything.

 

Wasn't aware of that Fist weapon problem, though. I'll have to look into that one.

 

 

 

 

You CAN, however, use
GetEquippedObject != 0
as a condition to test that the guard has a weapon.

 

I never said otherwise. I'm not sure what you're trying to argue here, he's already testing whether the guard has a weapon in that exact way.

 

Also, keep in mind that by using AddItem AmmoList 50, you'll be adding 50 rounds of EVERY SINGLE VALID TYPE OF AMMO for that weapon.

 

This is true, I completely missed that. It's safe to assume that NPCs are not using special ammo types, so just adding the first type of ammo from the list would do the trick.

Set rEquippedWeapon to GetEquippedObject 5
Set rAmmo to GetWeaponAmmo rEquippedWeapon
Set rAmmo to ListGetNthForm rAmmo 0
AddItem rAmmo 50

 

Although, knowing that there's a way to isolate certain entries in the ammo list is very nice. Will the vanilla ammo type (say, regular Missiles for a Missile Launcher) always appear at the top of the given ammo list? Or can mods get in the way of that?

Edited by ThatOtherUser
Link to comment
Share on other sites

Wasn't aware of that Fist weapon problem, though. I'll have to look into that one.

 

There's no problem, GetEquippedObject will never return fists. If no weapon is equipped it will return 0.

 

Although, knowing that there's a way to isolate certain entries in the ammo list is very nice. Will the vanilla ammo type (say, regular Missiles for a Missile Launcher) always appear at the top of the given ammo list? Or can mods get in the way of that?

 

The vanilla ammo lists all have the standard ammo type at the top of the list. I don't know if this is to be relied upon with ammunition mods, but I think it's safe to assume.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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