Short answer, yes, long answer, yes with a but
You didn't need any way (and for your purposes, still don't) till now to do damage to a person. You could have used code looking like:
That would reduce 23 health from a player. However, something I am committing shortly will adjust that. You can still use that method (and for your purposes, it being an item, that's fine) but there will be a better way for other characters to do damage, and that will be.
The [attacker] part is entirely optional, so if no character does the damage, you don't have to pass it. But if you do, it gets tracked that that player did the damage. There's also a Heal() varient that will be added too (healing is +=, not -=, btw).
And as for randomness, yes, dice exist. For your example there, it would be
Code: Select all
mChar.health -= RollDice( 3, 20, 0 );
RollDice takes 3 parameters (eg RollDice( a, b, c ) )
1) The number of die
2) The number of faces on each die
3) The number to add.
As a dice, the formula would be
aDb + c
Hope that helps.