ID:1281692
 
(See the best response by Jittai.)
Code:
mob/var
life = 100
accuracy = 6
speed = 5
strength = 4

mob/verb
attack(accuracy % 4)
if (accuracy >= 1)
life - attack
else
life = life


Problem description:I'm currently trying to code a combat system that works on percentages for accuracy. I am thinking first I have to define accuracy, speed, strength and all that. Once that's done I have to make it so that there is a base accuracy all players have, and to hit you have to reach a certain integer, when they attack a random number from 1-10 is generated and added to their base accuracy and if the integer is met then the attack hits. I guess speed of the target would decrease from the attacking players roll, while the players roll would add to it.

I can see it, but I'm not particularly sure how to code it. I know I'm not doing it right, because
Do you want the attack to have a set accuracy percentage, or do you want players to be able to train their accuracy later on?

As i see it, the attack verb got a set acc to 4%, no matter what stats the player have.
In the attack verb you say: if the accuracy is Equal or greater then 1, then life - attack, who´s life - who´s attack?
else someones life = someone life.
Which dont make any sense to me, but is this how you want it to be?
you could use prob() which works on a 0-100 % probability. Also, I don't think you should have a accuracy stat. It makes much more sense to create a formula based on the attacker and defender's speeds.
@Sleaze
I want players to all start with a set accuracy, but for it to increase if they want to train it.

I want it so that when they attack it runs a few procs that adds the attackers speed to his accuracy, then divides it by four. If the number it gets is 1 or higher the attack hit,

I also want it that all attacks aren't going to hit, so a random number from 1-10 is generated and added to the players accuracy when they attack, and when the attack is over that number is deleted.

I hope I've clarified, idk?

Um I want the targets life to decrease by the usr.strength and the targets life to = their life if it misses

@Jittai

Thank you, can you provide me an example of the context in which to use it? like

TakeDamage(var/Damage,var/mob/Attacker)
src.HP-=Damage
src.DeathCheck(Attacker)

mob/verb
attack()
flick("Attack",src)
for(var/mob/M in get_step(src,src.dir))
prob(accuracy)
if(accuracy >= 60)
var/damage=max(0, src.stregnth-M.life)
M.TakeDamage(Damage,src)
Best response
prob(accuracy) return a 1 or 0 (true or false), think of it rolling a dice. so you don't need the if(accuracy>=60).

mob/verb/attack()
flick("Attack",src)
for(var/mob/M in get_step(src,src.dir))
if(prob(accuracy))
var/damage=max(0, src.stregnth-M.life)
M.TakeDamage(Damage,src)


I recommend sitting down and figuring out what kind of numbers you want to be dealing with in terms of stats. What is a high "str" or considered low and choosing how your system calculates based off that.