ID:394311
 
Code:
mob
verb
Punch() //the verb name
if(usr.attacking == 0)
for(var/mob/M in get_step(usr,usr.dir))
flick("Attack",usr)
M.killlist += src.name
switch(rand(1,10))
if(1)
var/damage = usr.ad
M.hp -= damage
usr<<output("You attack [M] for [damage] damage!","Game")
F_damage(M, damage, "#ff0000")
DeathCheck(M)
if(2)
var/damage = round(usr.ad+rand(5,10))
M.hp -= damage
usr<<output("You attack [M] for [damage] damage!","Game")
F_damage(M, damage, "#ff0000")
DeathCheck(M)
if(3)
var/damage = round(usr.ad+rand(5,10))
M.hp -= damage
usr<<output("You attack [M] for [damage] damage!","Game")
F_damage(M, damage, "#ff0000")
DeathCheck(M)
if(4)
var/damage = 1000
M.hp -= damage
usr<<output("<font color=red>You attack [M] for [damage] damage!","Game")
F_damage(M, damage, "#ff0000")
DeathCheck(M)
if(5)
var/damage = round(usr.ad+rand(5,10))
M.hp -= damage
usr<<output("You attack [M] for [damage] damage!","Game")
F_damage(M, damage, "#ff0000")
DeathCheck(M)
if(6)
usr<<output("You attempt to attack [M] but he dodged","Game")
if(7)
var/damage = round(usr.ad+rand(5,10))
M.hp -= damage
usr<<output("You attack [M] for [damage] damage!","Game")
F_damage(M, damage, "#ff0000")
DeathCheck(M)
if(8)
var/damage = round(usr.ad+rand(5,10))
M.hp -= damage
usr<<output("You attack [M] for [damage] damage!","Game")
F_damage(M, damage, "#ff0000")
DeathCheck(M)
if(9)
var/damage = round(usr.ad+rand(5,10))
M.hp -= damage
usr<<output("You attack [M] for [damage] damage!","Game")
F_damage(M, damage, "#ff0000")
DeathCheck(M)
if(10)
var/damage = round(usr.ad+rand(5,10))
M.hp -= damage
usr<<output("You attack [M] for [damage] damage!","Game")
F_damage(M, damage, "#ff0000")
DeathCheck(M)
usr.attacking = 1
sleep(5)
usr.attacking = 0


Problem description:
How to avoid switch(rand)? I want to make that there will be 90% for normal attack 5 % for crit and 5 % for dodge. Ty for help
if(prob(5))
world << "Critical Attack."
else
world << "Normal Attack."


Have a look at prob() proc in reference for further information.
i know about prob(). And I try coded like this :
if(prob(90))
world << "Normal Attacl."
else
world << "Blocked."
if(prob(10))
world << "Critical Attack."
else
world << "Blocked."

and sometimes spawns bought of them. And thats why i used random :/



You are using prob() proc incorrectly.

Lets read your code step by step:

if(prob(90))
world << "Normal Attack."
else
world << "Blocked."
if(prob(10))
world << "Critical Attack."
else
world << "Blocked."


Output Normal Attack if prob(90) returns 1 (90% chance of happening), otherwise (prob(10) 10% chance of happening) output Blocked.

Then output Critical Attack if prob(10) returns 1 (10% chance of happening), otherwise (prob(90) 90% chance of happening) output Blocked.

That's not what we want right? It will either output Normal Attack with a Critical Attack, will output Blocked two times or produce other weird results.

Lets try this:

if(prob(5))       world << "Blocked."
else if(prob(10)) world << "Critical Attack."
else world << "Normal Attack."


Now lets read it.

If prob(5) returns 1, (5% chance of happening) output Blocked. But if it does not return 1 then call prob(10) and check its return value. If it is 1, (10% chance of happening) output Critical Attack but if it is 0, output Normal Attack. (85% chance of happening)

My explanation may be incorrect because I don't have much experience with prob() proc nor I have used it much. If anyone else finds my explanation wrong, please do come and correct it and help both the OP and me. =)
I wouldn't use prob because I'd need to check it twice and that's no good if I want precise probabilities.
I'd go for:

var/roll = rand(1,100)
if (roll >= 95)
// critical
else if (roll >5)
// normal
else
// dodge