So i made an item that heals the entire party for a specific amount, i put the scope as all alies, but when i use the item with ally 1 it keeps healing ally 1 4 times, instead of the whole party.
i tried to play around with the formula but i cannot seem to get it.
I put : a.gainHp(a.hp + 500)
now party member 1 gets 500 health four times upon using the item, how can i distribute this 500 to the other 3 party members?
your mistake is to use the script to override the targeting.
a is the placeholder for the skill user, b is the placeholder for the skill target.
So you're telling the skill that for every target, the skill user shouuld be healed
why didn't you just put in 500 as HP Recover? There is no need to use gainHP at all.
then use a random function with a direct number result.
the key is to not use the gainhp but the default number functions of the skill, then you won't override the target either.
Generally the formula should only be used to calculate values, not do things.
There's a Variance setting. For example, if you use a formula 500 with Variance = 20% (default), the result will range from 400~600, i.e. 80% to 120% of the formula value.
Alternatively you can use something like Math.randomInt(500), which rolls a random integer from 0~499.
The formula gets evaluated once per target, that's why your original attempt ("heal the user by their current HP plus 500") healed the user 4 times. So any randomness will also be rerolled per target.