FOSE Weapons Functions

Post » Tue May 17, 2011 5:56 am

I'm trying to make a script that will walk the player's inventory, checking each item to see if it's a weapon. If it is a weapon, it should then check if the weapon is of a certain type (a gun), and then get the weapon's ammo and other various info before performing other functions on the acquired data.

Here's my script so far (minus the initial check for a gun weapon):
set index to 0		label 10		set item to player.getInventoryObject index		printc "%n" item		if (item)			if (GetType item == 40)				printc "Getting weapon info"				set ammoType to item.GetWeaponAmmo				printc "%n uses %n ammo" item, ammotype				set weapType to item.GetWeaponType				printc "%n is a weapon of type %.0f" item, weapType				set clipSize to item.GetWeaponClipRounds				printc "%n has a clip size of %.0f" item, clipSize				set ammoUse to item.GetWeaponAmmoUse				printc "%n uses %.0f rounds per shot" item, ammoUse				set clipUse to (clipSize / ammoUse) ;calculates how many shots can be made with one clip				printc "%n gets %.0f shots per clip" item, clipUse				printc "Weapon info obtained"

In theory, it seems it should all work (I'm working off the rather horribly documented FOSE function descriptions for my usage). And for the first bit, it works. All the lines print out the name of the first weapon. The issue that I'm getting is that none of the functions from getWeaponAmmo down work (it returns and the others just return 0.

Which gets me to my next problem. Since all the values are zero, the line:
set clipUse to (clipSize / ammoUse) ;calculates how many shots can be made with one clip

causes a divide by zero issue and makes the object lock up (Strange the game can survive a divide by zero error, but crashes when you do an integral action like save).

I did try doing an equip on the weapon I wanted to check, but it wound up equipping a laser pistol and checking a shotgun. So I'm not sure what got messed up with that.

Anyway, that's my issue.
User avatar
Robert
 
Posts: 3394
Joined: Sun Sep 02, 2007 5:58 am

Post » Tue May 17, 2011 11:26 am

It took me a little while to figure out how they work, but the basic usage is as follows

set weaponAmmo to weaponOwner.GetWeaponAmmo weapon

So, on the player that would be

set weaponAmmo to player.GetWeaponAmmo weapon

where weaponAmmo is a short and weapon is a reference containing the weapon. You should also be aware that the GetInventoryObject returns the base object, not the actual object in the players inventory.
User avatar
nath
 
Posts: 3463
Joined: Mon Jan 22, 2007 5:34 am

Post » Tue May 17, 2011 1:46 pm

It took me a little while to figure out how they work, but the basic usage is as follows

set weaponAmmo to weaponOwner.GetWeaponAmmo weapon

So, on the player that would be

set weaponAmmo to player.GetWeaponAmmo weapon

where weaponAmmo is a short and weapon is a reference containing the weapon. You should also be aware that the GetInventoryObject returns the base object, not the actual object in the players inventory.


Thanks. This is the kind of thing that could use better explaining on the FOSE site.

Though, shouldn't weaponAmmo be a ref, since it would be holding the name of an ammo type? As for it returning the base object, that's fine, since I'm not aware of anything that could easily affect the stats of a weapon in inventory (that would keep if the weapon were dropped or put in a container).

So, from what you're saying though, each line should read like this:
 set [variable] to player.[foseWeaponFunction] [weaponVariable]


I'll give that a shot in a bit and see how it goes. If it does, then I'll feel awesome, and you'll earn yourself a spot in my credits list.
User avatar
bimsy
 
Posts: 3541
Joined: Wed Oct 11, 2006 3:04 pm

Post » Tue May 17, 2011 4:06 am

I'm using the GetWeaponAmmo like this (calling by base form) in a quest script and it is working:

ref rWeaponREFref rAmmoRefset rWeaponREF to Player.GetEquippedObject 5if (rWeaponREF)   ;Make sure ref is non-zero before running functions against it.     set rAmmoREF to GetWeaponAmmo rWeaponREFendif

User avatar
Vickytoria Vasquez
 
Posts: 3456
Joined: Thu Aug 31, 2006 7:06 pm

Post » Tue May 17, 2011 3:14 pm

Thanks for the input. Now I've got an odd issue. I've got a bunch of console out stuff for debugging purposes. Basically, every function gets put to the console so I can see it. I'm now coming across an unexplainable problem.

label 10		set item to player.getInventoryObject index		printc "%n" item		if (item)			set weapType to player.GetWeaponType item			printc "%n is a weapon of type %.0f" item, weapType			if (GetType item == 40) && (weapType > 2)				printc "Getting weapon info"				set ammoType to player.GetWeaponAmmo item				printc "%n uses %n ammo" item, ammotype				set weapType to player.GetWeaponType item				printc "%n is a weapon of type %.0f" item, weapType				set clipSize to player.GetWeaponClipRounds item				printc "%n has a clip size of %.0f" item, clipSize				set ammoUse to player.GetWeaponAmmoUse item				printc "%n uses %.0f rounds per shot" item, ammoUse				set clipUse to (clipSize / ammoUse) ;calculates how many shots can be made with one clip				printc "%n gets %.0f shots per clip" item, clipUse				printc "Weapon info obtained"				set playerAmmo to player.GetItemCount ammoType				set contAmmo to GTAmmoCabinetRef.GetItemCount ammoType				if (weapType == 3) ;OneHandPistol					printc "In pistols block"					set dispAmmo to (clipSize * GTAmmoQuest.NumClipsPistol)					printc "Set to give %.0f ammo for %n" dispAmmo, item					if (clipUse <= GTAmmoQuest.PistolClipMin)						printc "Clip use less than mult, give %.0fx more ammo" GTAmmoQuest.PistolMult						set dispAmmo to (dispAmmo * GTAmmoQuest.PistolMult)					endif					if (player.GetItemCount ammoType < dispAmmo) && (GTAmmoQuest.PistolTog == 1)						printc "Fixed ammo on, calculating now"						set dispAmmo to (dispAmmo - player.GetItemCount ammoType)					endif					if (dispAmmo > contAmmo)						set dispAmmo to (dispAmmo - contAmmo)					endif				endif.........				if (dispAmmo > 0)					printc "giving %.0f rounds of %n" dispAmmo, item					player.AddItem ammotype dispAmmo 					GTAmmoCabinetRef.RemoveItem ammoType dispAmmo					set dispAmmo to 0				endif			endif			set index to (index + 1)			goto 10		endif

All the output from this to console contains the correct data (the NumClipsPistol variable is initialized to 5), so dispAmmo is output correctly as 60. However, in adding the ammo to the player, and removing it from the container, it winds up as being double the amount it should be (120 instead of 60). I somehow managed to fix it for pistols, but it still does this for rifles. I'm at a bit of a loss as to why it's doing this, because the debug line doesn't get printed twice.

For reference, what is shown here is repeated for each different ammo type.
User avatar
patricia kris
 
Posts: 3348
Joined: Tue Feb 13, 2007 5:49 am

Post » Tue May 17, 2011 4:58 am

Thanks. This is the kind of thing that could use better explaining on the FOSE site.

Yeah, unfortunately no one has found the time to add the FOSE functions to the GECK wiki so that the community can improve the documentation :)

All the output from this to console contains the correct data (the NumClipsPistol variable is initialized to 5), so dispAmmo is output correctly as 60. However, in adding the ammo to the player, and removing it from the container, it winds up as being double the amount it should be (120 instead of 60). I somehow managed to fix it for pistols, but it still does this for rifles. I'm at a bit of a loss as to why it's doing this, because the debug line doesn't get printed twice.

Could you, by coincidence, have two weapons using the same type of ammo?
User avatar
CHangohh BOyy
 
Posts: 3462
Joined: Mon Aug 20, 2007 12:12 pm

Post » Tue May 17, 2011 6:09 am

Could you, by coincidence, have two weapons using the same type of ammo?

In actual play, you could, in my testing, I'm absolutely certain that I have weapons that use different ammo types.
User avatar
Samantha Jane Adams
 
Posts: 3433
Joined: Mon Dec 04, 2006 4:00 pm


Return to Fallout 3