Skip to content

SetWeaponsToMaxRange occasionally sets weapons to 0 meters #332

@Blaylock1988

Description

@Blaylock1988

weaponMax = APIs.WeaponCore.GetMaxWeaponRange(termBlock as MyEntity, 0);

Occasionally, this function works fine, but at other times it returns 0 meters, rendering the weapon useless.

Examining the logs shows that it successfully retrieved and applied 0 meters from the WC API GetMaxWeaponRange; otherwise, it would have been the default 800. This WC method is set to return 0f if the result is null, leading me to believe that MES may be sending incorrect weapon reference data to WC.

        public float GetMaxWeaponRange(Sandbox.ModAPI.Ingame.IMyTerminalBlock weapon, int weaponId) =>
            _getMaxWeaponRange?.Invoke(weapon, weaponId) ?? 0f;

I can't tell if it the bug is on MES's end, or WC's end. In the log, the Hurricane and Sentinel are both MyObjectBuilder_LargeMissileTurret TypeIds, so I don't think the issue is related to specific TypeIds. Also, on some NPCs the same Sentinel turret range is set to max just fine.

Additionally, but likely a different problem, is that MES is setting the weapon range on the same weapon 13 times. This is coincidentally the total number of grids and subgrids for this specific NPC (one main grid and 12 wheels), leading me to believe it is trying to apply this to all subgrids unnecessarily, since wheels do not have weapons.

SetWeaponsToMaxRange log sample.txt

NPC in question:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions