ID:162780
 
I want to make skills cost a % of a person's max energy(mana,chakra,MP) or whatever. Anyone know how to do that?
// in this example im using a obj as the control for the skill
obj
skill
var
mp_amount = 0
mp_usage_type = 0 // 0 = use only set amount, 1 = use % of amount
tmp
mob
skillcaster = null
// example (where mp_usage_type = 1)
// var/totalused = (skillcaster.maxmp/100)*mp_amount
proc
cast()
if(skillcaster)
var/totalused = 0
switch(mp_usage_type)
if(0) totalused = mp_amount
if(1) totalused = (skillcaster.maxmp/100)*mp_amount
if(totalused <= skillcaster.mp)
// and so on...

(use at your own risk ^_^)
In response to Redlion
Ok, you just confused the hell out of me...
In response to Lundex
Its simple math

if the skill takes 10% and you have 300 mp

You would want to do 300/100 and then * by 10

300/100 because cent is 100

and then 10 because you want 10 per 100

and then you would subtract that from 300

X = src.mp/100*10
then src.mp - = X


to shorten it is 10/100 with is .1

so that means
X = src.mp/.1
src.mp - =X

which also means that you can do it the most effencet way.
src.mp - = src.mp*.1


You try now, Do 23%