Files
Bubberstation/code/datums/elements/caseless.dm
T
SkyratBot 2acf2641e6 [MIRROR] Fixes runtime when firing arrows at non-carbon mobs [MDB IGNORE] (#23359)
* Fixes runtime when firing arrows at non-carbon mobs (#77942)

* Fixes runtime when firing arrows at non-carbon mobs

---------

Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
2023-08-27 10:37:21 -07:00

30 lines
1.1 KiB
Plaintext

/**
* An element that deletes the casing when fired and, if reusable is true, adds the projectile_drop element to the bullet.
* Just make sure to not add components or elements that also use COMSIG_FIRE_CASING after this one.
* Not compatible with pellets (how the eff would that work in a senible way tho?).
*/
/datum/element/caseless
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
var/reusable = FALSE
/datum/element/caseless/Attach(datum/target, reusable = FALSE)
. = ..()
if(!isammocasing(target))
return ELEMENT_INCOMPATIBLE
src.reusable = reusable
RegisterSignal(target, COMSIG_FIRE_CASING, PROC_REF(on_fired_casing))
/datum/element/caseless/proc/on_fired_casing(obj/item/ammo_casing/shell, atom/target, mob/living/user, fired_from, randomspread, spread, zone_override, params, distro, obj/projectile/proj)
SIGNAL_HANDLER
if(isnull(proj))
return
if(reusable)
proj.AddElement(/datum/element/projectile_drop, shell.type)
if(isgun(fired_from))
var/obj/item/gun/shot_from = fired_from
if(shot_from.chambered == shell)
shot_from.chambered = null //Nuke it. Nuke it now.
QDEL_NULL(shell)