Wouldn't a solution be to save C.use(hitcost) to a variable and then use
the variable in the check? Or is it enough to remove the second C.use?

Den lördagen den 11:e januari 2014 skrev MrPerson:

> In code/game/objects/items/weapons/melee/energy.dm:
>
> > @@ -129,6 +129,19 @@
> >  		else
> >  			user << "<span class='warning'>It's already fabulous!</span>"
> >
> > +/obj/item/weapon/melee/energy/sword/cyborg
> > +	var/hitcost = 500
> > +
> > +/obj/item/weapon/melee/energy/sword/cyborg/attack(mob/M, var/mob/living/silicon/robot/R)
> > +	if(R.cell)
> > +		var/obj/item/weapon/cell/C = R.cell
> > +		if(active && !(C.use(hitcost)))
> > +			attack_self()
> > +			R << "<span class='notice'>It's out of charge!</span>"
> > +			return
> > +		C.use(hitcost)
> > +		..()
> > +	return
>
> Actually yes, this does in fact drain the cell twice. You're calling
> if(!(C.use(hitcost)). This runs use() which for reference is
>
> // use power from a cell
> /obj/item/weapon/cell/proc/use(var/amount)
> if(rigged && amount > 0)
> explode()
> return 0
>
> if(charge < amount) return 0
> charge = (charge - amount)
> return 1
>
> Let's assume charge > hitcost (ie the cell has enough power), so charge is
> decreased by hitcost and returns 1, which violates the if check and
> continues on. The next thing is another use(hitcost), so charge is once
> again decreased by hitcost.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/tgstation/-tg-station/pull/2244/files#r8809333>
> .
>