ID:167207
 
Okay, what I need to know is how to display a survival rate variable as a percent by looking at the mobs kills, deaths, and total_battles var(s). Since I know thats to vague to be of help, heres an example of what I mean.

Lets say a mob(/mob/player) has fought a total of 71 battles(total_battles=71), and out of those 71 battles, he died 22 times(deaths=22) and won the other 49(kills=49). Now, what I need to know is how to get a percent of survival by comparing the kills to the deaths, and calculating how many times out of the total_battles var that the mob won(wins being defined as kills) and expressing it as a percent.

Thanks In advance for help
Ok, first, you'll want to figure out kill percentage. Divide 49 by 71, giving you the percent of wins, then divide 22 by 77, giving you the pecent of losses. Then subtract the losses from the wins.

mob
var
win = 49
loss = 22
total_battles = 71 //just an example, don't copy this exactly
survival_rate

mob/proc/find_percentage()
var/W = src.win/src.total_battles
var/L = src.loss/src.total_battles
src.survival_rate = W - L


I think that should do it.
var/mob/Player/P
round((P.Kills/P.TotalBattles)*100)

P.Kills/P.TotalBattles will give you the decimal percent. Then we multiply that by 100 so it is in the form of a percent, and round off any remaining decimals.
In response to DarkCampainger
Yeah, that's actually a better approach than mine.