Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetWeaponType and IsAmmo are not working when being called on reference #183

Open
ir4ne opened this issue Nov 14, 2022 · 1 comment
Open

Comments

@ir4ne
Copy link
Contributor

ir4ne commented Nov 14, 2022

It's stated in xOBSE documentation that IsAmmo and GetWeaponType can be called on reference. But it seems they only work if weapon reference is passed as an argument.

Steps to reproduce:

  1. Register OnHitWith event handler
    SetEventHandler "OnHitWith" MyOnHitWithHandler
  2. Write the following in your handler script file:
scn MyOnHitWithHandler

Ref target
Ref weapon

Int weaponType
Int isWeaponAmmo

	
begin Function { target, weapon }

	PrintC "OnHit target %n, weapon %n" target weapon

	let weaponType := weapon.GetWeaponType 
	let isWeaponAmmo := weapon.IsAmmo

	PrintC "weapon %n isAmmo = %g, type = %g" weapon isWeaponAmmo weaponType

end
  1. Run the game and hit someone
  2. Open your logs, you'll see something like this:
[OnHit target Commoner, weapon Silver Shortsword
Error in script b24cd8c4
Attempting to call a function on a NULL reference or base object: GetWeaponType
    File: IIC_AGFM.esp Offset: 0x0062 Command: GetWeaponType
  Let @0062 script B24CD8C4
Error in script b24cd8c4
Attempting to call a function on a NULL reference or base object: IsAmmo
    File: IIC_AGFM.esp Offset: 0x0079 Command: IsAmmo
  Let @0079 script B24CD8C4
weapon Silver Shortsword isAmmo = 0, type = 0
@llde
Copy link
Owner

llde commented Feb 28, 2023

Reflecting a but: this may even not be a bug. In this context weapon is the weapon used to attack, this means that it's in the inventory. Items in inventory doesn't have a reference attached (items that already exist in the word and if I recall correctly are persistent, save their original reference in ExtraData)
So the variable passed to the item is not a reference is a base form, and the error message make perfectly sense.

Maybe I can enhance the event to pass a InventoryReference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants