- edited description
-
assigned issue to
[#modding] `MagazineAmmoLoader.HandleEvent(GetMissileWeaponProjectileEvent E)` doesn't set ...
Marked for crossposting by: Noelle Lavenza (transgendeer)
Message (jump):
<Noelle Lavenza (transgendeer)>
MagazineAmmoLoader.HandleEvent(GetMissileWeaponProjectileEvent E)
doesn't setE.Projectile
toMagazineAmmoLoader.Ammo
(if valid/non-null), causing issues with using this event in mods with bows.
Comments (5)
-
repo owner -
repo owner -
assigned issue to
-
assigned issue to
-
Projectiles’re separate objects from Ammo (
Zetachrome Arrow
|ProjectileZetachromeArrow
), XYP it’s not mentioned here what you’re trying to do?We can provide the ammo object in that event if you ultimately want it.
-
I realised that when I tried implementing it with a Harmony patch; the final implementation I wound up with was effectively the following:
[HarmonyPatch(typeof(MagazineAmmoLoader), nameof(MagazineAmmoLoader.HandleEvent), new Type[] { typeof(GetMissileWeaponProjectileEvent) })] static bool Prefix(MagazineAmmoLoader __instance, GetMissileWeaponProjectileEvent E, ref bool __result) { if (__instance.Ammo != null && __instance.Ammo.IsValid()) { E.Projectile = GetProjectileObjectEvent.GetFor(__instance.Ammo, __instance.ParentObject); __result = false; return false; } return true; }
or, translated out of Harmony:
public override bool HandleEvent(GetMissileWeaponProjectileEvent E) { + if (Ammo?.IsValid()) + { + E.Projectile = GetProjectileObjectEvent.GetFor(Ammo, ParentObject) + return false; + } if (!string.IsNullOrEmpty(ProjectileObject)) { E.Blueprint = ProjectileObject; return false; } return base.HandleEvent(E); }
The main reason this is necessary is to make GetMissileWeaponProjectileEvent work for launchers and bows, which don’t set
ProjectileObject
. It might need to go after the ProjectileObject clause instead of before to avoid issues with things that do set it and instead ignore the Ammo object, like anything that loads lead slugs. (It might also need to set E.Blueprint in the Ammo clause as well, to avoid inconsistencies if something uses both E.Projectile and E.Blueprint expecting them to correspond.) -
repo owner - changed status to resolved
- Log in to comment