Jamming Tweaks (#8261)

Tweaked how gunjamming works. You now have to spam the Z button, or keep clicking the gun sprite if you don't have hotkeys, to unjam it.
    Added sounds to jamming and unjamming guns.
This commit is contained in:
Geeves
2020-02-22 21:52:37 +02:00
committed by GitHub
parent c0ff0d90d6
commit e6d6e0dfb6
2 changed files with 32 additions and 32 deletions

View File

@@ -28,7 +28,8 @@
var/auto_eject = 0 //if the magazine should automatically eject itself when empty. var/auto_eject = 0 //if the magazine should automatically eject itself when empty.
var/auto_eject_sound = null var/auto_eject_sound = null
var/is_jammed = 0 //Whether this gun is jammed var/jam_num = 0 //Whether this gun is jammed and how many self-uses until it's unjammed
var/unjam_cooldown = 0 //Gives the unjammer some time after spamming unjam to not eject their mag
var/jam_chance = 0 //Chance it jams on fire var/jam_chance = 0 //Chance it jams on fire
//TODO generalize ammo icon states for guns //TODO generalize ammo icon states for guns
@@ -46,8 +47,8 @@
update_icon() update_icon()
/obj/item/gun/projectile/consume_next_projectile() /obj/item/gun/projectile/consume_next_projectile()
if(is_jammed) if(jam_num)
return 0 return FALSE
//get the next casing //get the next casing
if(loaded.len) if(loaded.len)
chambered = loaded[1] //load next casing. chambered = loaded[1] //load next casing.
@@ -58,7 +59,7 @@
if(handle_casings != HOLD_CASINGS) if(handle_casings != HOLD_CASINGS)
ammo_magazine.stored_ammo -= chambered ammo_magazine.stored_ammo -= chambered
if (chambered) if(chambered)
return chambered.BB return chambered.BB
return null return null
@@ -74,12 +75,13 @@
/obj/item/gun/projectile/special_check(var/mob/user) /obj/item/gun/projectile/special_check(var/mob/user)
if(!..()) if(!..())
return 0 return FALSE
if(!is_jammed && jam_chance) if(!jam_num && jam_chance && getAmmo())
if(prob(jam_chance)) if(prob(jam_chance))
playsound(src.loc, 'sound/items/trayhit2.ogg', 50, 1)
to_chat(user, "<span class='danger'>\The [src] jams!</span>") to_chat(user, "<span class='danger'>\The [src] jams!</span>")
is_jammed = 1 jam_num = rand(2, 5) // gotta attackself two to five times to unjam
return 1 return TRUE
/obj/item/gun/projectile/proc/process_chambered() /obj/item/gun/projectile/proc/process_chambered()
if (!chambered) return if (!chambered) return
@@ -166,7 +168,7 @@
update_icon() update_icon()
//attempts to unload src. If allow_dump is set to 0, the speedloader unloading method will be disabled //attempts to unload src. If allow_dump is set to 0, the speedloader unloading method will be disabled
/obj/item/gun/projectile/proc/unload_ammo(mob/user, var/allow_dump=1) /obj/item/gun/projectile/proc/unload_ammo(mob/user, var/allow_dump = 1)
if(ammo_magazine) if(ammo_magazine)
user.put_in_hands(ammo_magazine) user.put_in_hands(ammo_magazine)
user.visible_message("[user] removes [ammo_magazine] from [src].", "<span class='notice'>You remove [ammo_magazine] from [src].</span>") user.visible_message("[user] removes [ammo_magazine] from [src].", "<span class='notice'>You remove [ammo_magazine] from [src].</span>")
@@ -195,28 +197,31 @@
to_chat(user, "<span class='warning'>[src] is empty.</span>") to_chat(user, "<span class='warning'>[src] is empty.</span>")
update_icon() update_icon()
/obj/item/gun/projectile/attackby(var/obj/item/A as obj, mob/user as mob) /obj/item/gun/projectile/attackby(obj/item/A, mob/user)
..() ..()
load_ammo(A, user) load_ammo(A, user)
/obj/item/gun/projectile/attack_self(mob/user as mob) /obj/item/gun/projectile/attack_self(mob/user)
if(is_jammed) if(jam_num)
to_chat(user, "<span class='notice'>\The [user] unjams \the [src]!</span>") playsound(src.loc, 'sound/weapons/empty.ogg', 50, 1)
if(do_after(user, 5)) jam_num--
playsound(src.loc, 'sound/weapons/empty.ogg', 100, 1) if(!jam_num)
is_jammed = 0 visible_message(span("danger", "\The [user] unjams \the [src]!"))
playsound(src.loc, 'sound/items/glowstick.ogg', 100, 1)
unjam_cooldown = world.time
else if(unjam_cooldown + 2 SECONDS > world.time)
return
else if(firemodes.len > 1) else if(firemodes.len > 1)
..() ..()
else else
unload_ammo(user) unload_ammo(user)
/obj/item/gun/projectile/attack_hand(mob/user as mob) /obj/item/gun/projectile/attack_hand(mob/user)
if(user.get_inactive_hand() == src) if(user.get_inactive_hand() == src)
unload_ammo(user, allow_dump=0) unload_ammo(user, allow_dump=0)
else else
return ..() return ..()
/obj/item/gun/projectile/afterattack(atom/A, mob/living/user) /obj/item/gun/projectile/afterattack(atom/A, mob/living/user)
..() ..()
if(auto_eject && ammo_magazine && ammo_magazine.stored_ammo && !ammo_magazine.stored_ammo.len) if(auto_eject && ammo_magazine && ammo_magazine.stored_ammo && !ammo_magazine.stored_ammo.len)
@@ -235,7 +240,7 @@
..(user) ..(user)
if(get_dist(src, user) > 1) if(get_dist(src, user) > 1)
return return
if(is_jammed) if(jam_num)
to_chat(user, "<span class='warning'>It looks jammed.</span>") to_chat(user, "<span class='warning'>It looks jammed.</span>")
if(ammo_magazine) if(ammo_magazine)
to_chat(user, "It has \a [ammo_magazine] loaded.") to_chat(user, "It has \a [ammo_magazine] loaded.")
@@ -251,15 +256,3 @@
if(chambered) if(chambered)
bullets += 1 bullets += 1
return bullets return bullets
/* Unneeded -- so far.
//in case the weapon has firemodes and can't unload using attack_hand()
/obj/item/gun/projectile/verb/unload_gun()
set name = "Unload Ammo"
set category = "Object"
set src in usr
if(usr.stat || usr.restrained()) return
unload_ammo(usr)
*/

View File

@@ -0,0 +1,7 @@
author: Geeves
delete-after: True
changes:
- tweak: "Tweaked how gunjamming works. You now have to spam the Z button, or keep clicking the gun sprite if you don't have hotkeys, to unjam it."
- rscadd: "Added sounds to jamming and unjamming guns."