Posts ID:264638
ID:264638

Code:
 ```proc battle(mob/attacker, mob/victim) if(victim.stats) // if the victim's stats are null then it can't be attacked because it's a non attackable NPC //the attacks strength plus a times a random number of 0.5 through 1.5 plus a random number 1 through 3 var/dmg = round(attacker.stats["Strength"] * rand(1/2, 3/2) + rand(1, 3)- \ //minus the same formula for the victims defense victim.stats["Defense"] * rand(1/2, 3/2) + rand(1, 3)) //same formula for their speed var/dodge = round(attacker.stats["Speed"] * rand(1/2, 3/2) + rand(1, 3)- \ victim.stats["Speed"] * rand(1/2, 3/2) + rand(1, 3)) //if dodge variable ended up being 0 or less the victim dodged the attack if(dodge <= 0) chat("[_m] [pick(dodgemessages)] [m]'s attack.", "battleoutput", view()) //if not attempt to block else //if the dmg is 0 or less the victim blocked the attack if(dmg <= 0) chat("[_m] [pick(blockmessages)] [m]'s attack.", "battleoutput", view()) //if not do the damage else victim.stats["Health"] -= dmg chat("[m] [pick(attackmessages)] [_m].", "battleoutput", view()) ```

Problem description:
I made some messages that output the dodge and dmg variables to me. Even when the dmg variable is 0 the dmg line runs instead of the block line(last if/else statement).
 #1 Jan 30 2010, 5:52 pm Does the dodge line work?
 #2 Jan 31 2010, 11:31 pm The dmg value might not be what you expect. Try performing a "world << dmg" before the last condition check. Make pure dmg is a valid number and that it truly is less than 1. ts
 #3 Feb 1 2010, 11:45 am In response to Tsfreaks (#2) Tsfreaks wrote: The dmg value might not be what you expect. Try performing a "world << dmg" before the last condition check. Make pure dmg is a valid number and that it truly is less than 1. ts I wrote: I made some messages that output the dodge and dmg variables to me. Even when the dmg variable is 0 the dmg line runs instead of the block line(last if/else statement). The dmg variable indeed comes to zero. The block line will only run if it is below 0. The dmg var is -1 and still doing the same thing. As for dodge it always comes out to around 6. I haven't tweeked the stats to test this out, but I will look and see.
 #4 Feb 1 2010, 8:02 pm In response to Ultima Anime (#3) I don't know it seems pretty strange if the variable is 0 or below it should be working. Also, are you aware that you are using attacker and victim for the procedure, then calling m and _m in the outputs?
 #5 Feb 1 2010, 8:09 pm In response to Ulterior Motives (#4) Okay, just tried the dodge var and tweeked other vars. The dmg var no matter how far below 0 it doesn't work same with the block var. I have no clue what is wrong. Yes, I know about using m and _m, I had to break the code down to make it readable and just kept the basic outputs the same. Just so people could get the basic idea when I placed it in Design Philosophy.