From 7cc1c93207fdf2e717dc8588164f556c13e2248e Mon Sep 17 00:00:00 2001 From: Zuhayr Date: Sat, 23 Nov 2013 13:47:20 +1030 Subject: [PATCH] Clamps pill numbers between 1 and 20. --- code/modules/reagents/Chemistry-Machinery.dm | 41 +++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/code/modules/reagents/Chemistry-Machinery.dm b/code/modules/reagents/Chemistry-Machinery.dm index 8b5400fa40e..2ebf1d25900 100644 --- a/code/modules/reagents/Chemistry-Machinery.dm +++ b/code/modules/reagents/Chemistry-Machinery.dm @@ -204,6 +204,8 @@ var/bottlesprite = "1" //yes, strings var/pillsprite = "1" var/client/has_sprites = list() + var/waiting = null //Fix for spamming 'create multiple pills' + var/max_pill_count = 20 /obj/machinery/chem_master/New() var/datum/reagents/R = new/datum/reagents(100) @@ -348,23 +350,32 @@ icon_state = "mixer0" else if (href_list["createpill"] || href_list["createpill_multiple"]) var/count = 1 - if (href_list["createpill_multiple"]) count = isgoodnumber(input("Select the number of pills to make.", 10, pillamount) as num) - if (count > 20) count = 20 //Pevent people from creating huge stacks of pills easily. Maybe move the number to defines? + if (href_list["createpill_multiple"] && !waiting) + waiting = 1 + count = Clamp(isgoodnumber(input("Select the number of pills to make.", 10, pillamount) as num),1,max_pill_count) + var/amount_per_pill = reagents.total_volume/count if (amount_per_pill > 50) amount_per_pill = 50 - var/name = reject_bad_text(input(usr,"Name:","Name your pill!","[reagents.get_master_reagent_name()] ([amount_per_pill] units)")) - while (count--) - var/obj/item/weapon/reagent_containers/pill/P = new/obj/item/weapon/reagent_containers/pill(src.loc) - if(!name) name = "[reagents.get_master_reagent_name()] ([amount_per_pill] units)" - P.name = "[name] pill" - P.pixel_x = rand(-7, 7) //random position - P.pixel_y = rand(-7, 7) - P.icon_state = "pill"+pillsprite - reagents.trans_to(P,amount_per_pill) - if(src.loaded_pill_bottle) - if(loaded_pill_bottle.contents.len < loaded_pill_bottle.storage_slots) - P.loc = loaded_pill_bottle - src.updateUsrDialog() + + if(waiting < 2) + var/name = reject_bad_text(input(usr,"Name:","Name your pill!","[reagents.get_master_reagent_name()] ([amount_per_pill] units)")) + waiting = 2 + while (count--) + var/obj/item/weapon/reagent_containers/pill/P = new/obj/item/weapon/reagent_containers/pill(src.loc) + if(!name) name = "[reagents.get_master_reagent_name()] ([amount_per_pill] units)" + P.name = "[name] pill" + P.pixel_x = rand(-7, 7) //random position + P.pixel_y = rand(-7, 7) + P.icon_state = "pill"+pillsprite + reagents.trans_to(P,amount_per_pill) + if(src.loaded_pill_bottle) + if(loaded_pill_bottle.contents.len < loaded_pill_bottle.storage_slots) + P.loc = loaded_pill_bottle + src.updateUsrDialog() + + spawn(0) + waiting = null + else if (href_list["createbottle"]) if(!condi) var/name = reject_bad_text(input(usr,"Name:","Name your bottle!","[reagents.get_master_reagent_name()] ([reagents.total_volume] units)"))