Object Refs vs. Base Form IDs

Post » Sat Feb 05, 2011 3:50 pm

Final question for the night.

The idea behind the code below is that I want to add ammo for whatever weapon the player currently has equipped.

Set refWeapon to Player.GetEquippedObject 5Set refAmmo to Player.GetWeaponAmmo refWeaponSet nItemCount to Player.GetItemCount refAmmoif( nItemCount < 1000 )	Player.AddItem refAmmo 1000endif


First, assume the player does, indeed, have a Laser Pistol equipped, i.e., ignore the pitfalls of the above if the player does not have a weapon equipped or has a melee weapon equipped. With that in mind, what's wrong with the above? It crashes. (The game doesn't crash, but the script exits.)

Second, let's not assume anything. How do I determine if the player doesn't have any weapon equipped? Just check if "refWeapon" doesn't equal 0?
User avatar
Deon Knight
 
Posts: 3363
Joined: Thu Sep 13, 2007 1:44 am

Post » Sat Feb 05, 2011 4:46 pm

Well my question would be, what is refWeapon and refAmmo? What are they defined as?
User avatar
A Dardzz
 
Posts: 3370
Joined: Sat Jan 27, 2007 6:26 pm

Post » Sat Feb 05, 2011 1:07 pm

Put PrintCs into the script between the lines to see where it's dying (e.g. Printc "Got equipped object %n" refWeapon).
User avatar
Sarah Bishop
 
Posts: 3387
Joined: Wed Oct 04, 2006 9:59 pm

Post » Sat Feb 05, 2011 6:25 am

Only thing I have to ask is with the code what are you trying to do? Are you trying to add ammo for 1 specific weapon or the type of weapon that is equipped at that current point in time? If you want to add ammo for 1 specific type of weapon you could do

If ( player.getEquipped NVGaussRilfe == 1 )

player.addItem Microfusioncell 1000

ENDIF

One thing i'm experimenting with form lists and what you could do is separate the weapons that use microfusion cells, electron charge packs, physical ammo, etc... . It'll be tricky for the physical ammo and figuring out how to do 1 straight line of code without doing a ton of IFs would be the challenge. As for determining if the player doesn't have anything equipped I think that would fall into the "Unarmed/Melee Weapons" which would be covered by the formlist.

This code may give you some help:

IF (player.IsWeaponInList RepairKitEnergyListPart1 == 1 || player.IsWeaponInList RepairKitEnergylistPart2 == 1 )


That basically references a formlist I created which contains energy weapons. I split it into 2 parts so the computer isn't constantly going through 30+ weapons in 1 single list which can bog it down. It's much faster to go through 2 seperate lists containing 10 to 15 weapons each.

IF (player.IsWeaponInList ProjectileList == 1 || player.IsWeaponInList FusionCell == 1 || player.IsWeaponInList SmallCell == 1 ) *insert code*ELSEShowMessage WeaponNoAmmoENDIFEND


Thing i'm not seeing is the Player.GetWeaponAmmo command/function are you using the script extender? You could even take the code and split it up so that IF (player.isweaponinlist smallcell == 1) it'll add 1000 small cells to the player's ammo count.

*Edit*

Had a quick thought OP you instead of putting the weapons in a formlist you could just check to see if the player is using the Unarmed Skill or if they are using melee weapons by doing the player.getEquipped Unarmed == 1 || player.getEquipped MeleeWeapons == 1 and if the player is unarmed it will trigger a message. If it isn't then you can do an else then put your code into the Else area.
User avatar
claire ley
 
Posts: 3454
Joined: Fri Aug 04, 2006 7:48 pm

Post » Sat Feb 05, 2011 6:36 am

Well my question would be, what is refWeapon and refAmmo? What are they defined as?

I just posted a code snippet. As my naming convention implies, I have refWeapon and refAmmo defined as...

ref refWeaponref refAmmo;; and though you didn't ask...int nItemCount



Put PrintCs into the script between the lines to see where it's dying (e.g. Printc "Got equipped object %n" refWeapon).

Good suggestion. I've never messed with script extender's print statements--mainly because I never was sure where the output would go. :)


Only thing I have to ask is with the code what are you trying to do?

As I originally stated, "The idea behind the code below is that I want to add ammo for whatever weapon the player currently has equipped."

Your alternate solution is a viable workaround, but it can quickly get messy and cumbersome. The functions in my above script are all valid functions, and it is a much cleaner and generic solution, so if possible, I would like to figure out specifically why it's not working before I throw in the towel and try an alternate approach.
User avatar
Kayla Bee
 
Posts: 3349
Joined: Fri Aug 24, 2007 5:34 pm

Post » Sat Feb 05, 2011 3:13 pm

Thing i'm not seeing is the Player.GetWeaponAmmo command/function are you using the script extender?

Ah! I just reread your reply and this statement sunk in. I think that's my problem.

I thought GetWeaponAmmo was a "default" (read: SE not required) function (http://geck.gamesas.com/index.php/GetWeaponAmmo), but it's an SE function. (The script compiles, so it's defined, but maybe it's not fully implemented in the NV version of SE.*shrug*) Anyway, the reference should be the actual weapon, not the player! Duh. :facepalm: That's undoubtedly why it's crashing.

As a side-note, though, I think I'll try another approach and use SE's GetPlayerCurrentAmmo function. It's not cited in the documentation, but he mentioned it in his release notes. I just noticed it now.


UPDATE:

The following code does the trick:

Set refAmmo to GetPlayerCurrentAmmoSet nItemCount to Player.GetItemCount refAmmoif( nItemCount < 1000 )	Player.AddItem refAmmo 1000endif


Now I just need add checks for error conditions (player is unarmed, player is using melee weapon, etc.).

Thanks, everyone!
User avatar
Kat Lehmann
 
Posts: 3409
Joined: Tue Jun 27, 2006 6:24 am

Post » Sat Feb 05, 2011 8:52 am

For posterity (i.e., for future forum searches), here's the final code (snippet) needed to resupply the player's ammo:

;;---------------------------------------;;Resupply Ammo (if holding ranged weapon);;---------------------------------------;;We will use the current animation to determine if we are unarmed or using a melee weapon.;;;;	0	:	AGW_NONE;;	1	:	AGW_HAND_TO_HAND;;	2	:	AGW_ONE_HAND_MELEE;;	3	:	AGW_TWO_HAND_MELEE;;	4	:	AGW_ONE_HAND_PISTOL;;	5	:	AGW_TWO_HAND_RIFLE;;	6	:	AGW_TWO_HAND_AUTOMATIC;;	7	:	AGW_TWO_HAND_HANDLE;;	8	:	AGW_TWO_HAND_LAUNCHER;;	9	:	AGW_ONE_HAND_GRENADE;;	10	:	AGW_ONE_HAND_MINE;;	11	:	AGW_ONE_HAND_LUNCHBOX_MINE;;---------------------------------------if( Player.GetWeaponAnimType >= 4 )	Set refAmmo to GetPlayerCurrentAmmo	;requires NVSE	Set nItemCount to Player.GetItemCount refAmmo	if( nItemCount < 1000 )		Player.AddItem refAmmo 1000 1	;final "1" hides the notification	endifendif


Of course, the "1000" for the ammo count was just for testing purposes.

Edit: Added comment to line in code requiring NVSE.
User avatar
Rachel Eloise Getoutofmyface
 
Posts: 3445
Joined: Mon Oct 09, 2006 5:20 pm


Return to Fallout: New Vegas