ID:142187
 
Code:
        Attack(mob/M in get_step(usr,dir))
set category = "Combat"
var/num = usr.str
num -= M.def
if(usr.dead == 1)
usr << "<b><font color = green>You cannot attack because you are dead.</b></font>"
else
if(M == usr)
usr << "<font color = green>You cannot attack yourself!</font>"
else
var/random = rand(1,3)
if(random == 1)
flick("Punch Left",usr)
view()<<sound('sfxpunch1.wav')
M.powerlevel -= num
s_damage(M, num)
M.Updatehp()
deathcheck()
if(random == 2)
flick("Punch Right",usr)
view()<<sound('sfxpunch2.wav')
M.powerlevel -= num
s_damage(M, num)
M.Updatehp()
deathcheck()
if(random == 3)
flick("Kick",usr)
view()<<sound('sfxkick1.wav')
M.powerlevel -= num
s_damage(M, num)
M.Updatehp()
deathcheck()


Problem description:

Heres a simple melee code I made that uses strength and defense var's.

It works perfect and everything but the only problem is that if the persons defense is higher then the others strength,you'll end up doing negative damage.

So my question is,how would I make it so if your doing negative damage,it'll round off to 1?

I'd much rather be doing 1 dmg at least then -573 lol :P

Look up the min() function.

[Edit]
...err, for this is should be max(), but you already have that sorted out.
In response to Popisfizzy
Popisfizzy wrote:
Look up the min() function.
Ok,it seems to make sense,but I'm not sure whether I just put it into the lines in of what I made,after editing it of course,or making a proc to check if the num is under 0?
In response to Kinotsu
min(0, damage)

You can also use max() to do the same(i usually use max)

max(0, damage)

or if you want to be fancy.

max(0, min( M.hp, damage))

That limites the damage to a minimum of 0 and a maximum of M's hp.
In response to Axerob
Axerob wrote:
min(0, damage)

You can also use max() to do the same(i usually use max)

max(0, damage)

or if you want to be fancy.

max(0, min( M.hp, damage))

That limites the damage to a minimum of 0 and a maximum of M's hp.
Oh wow,thanks alot :]

I took your advice and started to make my own game from scratch,and wow,it feels pretty good and a sense of accomplishment when you write your own stuff and see how that it actually works the way you wanted to.

Still a learning coder xD

But its a start.
In response to Kinotsu
That's always a good thing. If you need any help with it, let me know.
In response to Axerob
Hmmm....it didn't seem to work for me that well,so I just ended up making this.
if(damage < 1)
damage = 1


Thanks alot though,you helped me get an idea of a different possible way to do the same effect. :]
In response to Kinotsu
damage = max(0, damage)