Has anybody ever tried making a percentage/stat system?
Say you have a stamina stat, and as you do something, that stamina stat goes down...by percent.
So if your stamina stat is 2, and you did a little bit of exercise, your stamina percent would be 85%. I can't really think of how to do this. Any suggestions/comments welcome.
-ST
Copyright © 2025 BYOND Software.
All rights reserved.
A percentage can always be found by the following:
var/percentage = (currentval/maxval)*100
The percentage will be returned as a number from 0-100. (Actually, it can easily go out of that range... but those are the normal values.)
It can be converted back into a real number in similar fashion.
var/currentval = (percentage/100)*maxval
Thus, for example, say you want to subtract 15% from the user's stamina (which has a value of 2).
src.stamina -= (15/100)*max_stamina
if(src.stamina < 0) src.stamina = 0
The user's stamina will now have a value of 1.7. Converting that back to a percent...
src << "[(src.stamina/src.max_stamina)*100]% stamina"
...you'll indeed find that it works out to 85%.
(Note: I used the parentheses liberally. var/currentval = percentage/100*maxval will also work fine, but the "percentage/100" is a ratio and it's better to keep it in parentheses so it's more visible.)