llde / xOBSE

Oblivion Script extender source
243 stars 35 forks source link

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

Open ir4ne opened 1 year ago

ir4ne commented 1 year ago

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 commented 1 year ago

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.