ID:2103928
 
(See the best response by Nadrew.)
Code:
testutil//NewSkill
icon_state = "magic"
lvlgain = list("soldier" = 10000)
MP = 0
outbattle = 0
difficulty = 4
magictype = Evil

NPC_AI(var/mob/m)
Target_Attack_Ai(m)

Random_Mob(mob/M)
Random_Enemy(M)

Battle_Select_Target(var/mob/M)
if (!M)
M = usr
if (Check_MP(M))
Battle_Group_Select(M)

Cast(var/mob/M)
if (!M)
M = usr
if (Use_Check_MP(M))
Consume_Magic(M)
var/hp
var/base = 20
if (prob(101-M:Fire_skill))
hp = rand(0,5) + base
else
hp = rand(5,10) + base
GSay("<font color = \"#ff8f4f\">\icon[M][M.name] readies \icon[src][src.name].")
Noise()
hp = Damage(hp,target,M)
target.health -= hp
if (hp)
GSay("<font color = red>\icon[target][target.name] is hit by the attack for [hp] points of damage.")
target.FlashMob(target,1,3)
Hit()
else
GSay("<font color = blue>\icon[src][src.name] fails!")
for (var/mob/mm in M.target_mob)
if (prob(65))
mm.totdef = round(mm.totdef*0.85)
GSay("<font color = \"#CC0000\"><b>\icon[mm][mm.name]'s defense is reduced to [mm.totdef]!","CombatLog")
if (mm.lvl<=50)
if (mm.totdef <=50)
GSay("<font color = \"#CC0000\"><b>\icon[mm][mm.name]'s defense cannot go down any further!","CombatLog")
return 0
if (mm.lvl<=10)
if (mm.totdef <= 1)
GSay("<font color = \"#CC0000\"><b>\icon[mm][mm.name]'s defense cannot go down any further!","CombatLog")
return 0


Problem description:
I am the main GM and content creator on this project, but I am not the main programmer. I can do simple grunt work and figure things out given enough time in source, but this has stumped me for months. Also be forewarned: this source is old. As for why I'm not asking the main programmer, he's extremely busy at the moment.

What this skill SHOULD be doing: Deals nominal damage to the target mob. Reduces target mob defense by 15% and caps said defense debuff by a certain determined amount. In this case, target mob's DEF drops to 50 for mobs level 50 and below. If target mob is level 10 or below, capped debuff is to 1 DEF.

What the skill currently is doing: Damage element of the skill is fine. It always seems to just default to allowing mob defense to be reduced to 1.

I'm fully prepared to be told I'm missing something so utterly simple to fix this.
If your level is at 10 or below, BOTH of those if() checks will be true, you probably want to use 'else if' here so that only one of the conditions can trigger and not all of them. I didn't really read over the code though since it's fairly messy. That's just what I picked up at a glance.
I'm committing a sin by working with not only old code, but old code that isn't mine. I'll try that though, thanks.
Still seems to be a crapshoot whether or not defense is prevented from being reduced.

TestMob attacks!
Missed Rodile!
Rodile readies testutil.
TestMob is hit by the attack for 37 points of damage.
TestMob's defense is reduced to 30!
--------------------------------------------
TestMob attacks!
Missed Rodile!
Rodile readies testutil.
TestMob is hit by the attack for 33 points of damage.
TestMob's defense cannot go down any further!
--------------------------------------------
TestMob attacks!
Missed Rodile!
Rodile readies testutil.
TestMob is hit by the attack for 39 points of damage.
TestMob's defense is reduced to 25!
Best response
Ah, I see the issue. The flow of your logic is wrong, you'd want the defense checks BEFORE the prob() call, otherwise you're never actually preventing the prob() block from triggering if that 65% check passes.

With your current code you're doing:

1) Do a 65% check, if it passes reduce their defense.
2) Check their level and defense and prevent it from going any further.


In this code there's nothing that actually prevents the defense from going below a certain point.

You want to switch things around to flow like:

1) Check their level and defense and prevent it from going further.
2) Otherwise (in an else block), reduce their defense.
make sure you do that lvl 10 check before the lvl 50 too
Right, good catch. Although in a proper else if block it wouldn't really make a difference
Thanks a bunch guys, that did it. I'd rep both of you if I could.