Thanks to everyone here and a bit of hard work on my part my NPC generator is getting more complex and more useful with each version. I'd like to add damage counters to each generator. I have the maths to do it, but I'm unsure of how to start. So in GURPS your damage, as in most games, is based off of HP. However there are some differences as you can survive if you make rolls at certain HP levels
Less than 1/3 HP offers some penalties
0 HP or Less
-1xHP
-2xHP
-3xHP
-4xHP
So a character with 10 HP I'd like to be able to make something that might look like this
HP -1xHP -2xHP -3xHP -4xHP
OOOOO OOOOO OOOOO OOOOO OOOOO
OOOOO OOOOO OOOOO OOOOO OOOOO
I know IPP can do colours, green, black, and Red is enough for me. So how would I go about getting IPP to pick 10 "O's@ then properly colour them? Probably asking too much but I'm going to start to look into it.
Comments
That gives a result like this:
12 hp, one third is 4
OOOOOOOO OOOO
14 hp, one third is 5
OOOOOOOOO OOOOO
Having said that, I've been having a bit of fun with it. First wrote this: RepeatWithColor wants 3 parameters: quantity of repeats, color, and string to repeat.
Kind of interesting, but calling it is not much more attractive than just writing the HTML yourself.
So here's another (more complex, but a bit cooler) option: Colorize wants two parameters:
1) A string defining the colors. Each "chunk" is separated by dashes. A chunk can be:
a) a number, in which case the following chunk is expected to be a color
2) The string to be repeatedb) a color, or
c) a string to be printed in standard black. This string can not contain spaces (confuses "eachchar" -- use instead) or commas (confuses "with") or of course dashes (confuses Colorize).
Maybe one of those will for for you.
So within the table I want to create there would be 6 rows, the HP or FP would be taken from the results of a different table so {$FP} or {$HP} to get say 10 or 29
HP 0 HP -1xHP -2xHP -3xHP -4xHP
In each row there would be up to 5 'O' of various colors. The first row will always be Green except the last 1/3 which is Red. I'd like the Second row (0 HP) to be all yellow, the next three rows to be Orange, and the last row to be all Red. This is an example of 10 HP.
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO
However if it was say 29 HP then in the first row would have 20 green and 9 red 'O' as 1/3 of 29 is 9 and the red starts to indicate penalties I need to apply. and the -4xHP Row is always red right through. The ... was just to line them up in the forums.
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOO
OOOO.. OOOO.. OOOO. OOOO.. OOOO... OOOO
One of the things I want to do is keep each row with 5 'O' as it makes for easier counting.
This is one way I thought of doing it but once you start getting to 15+ HP the coding gets damn long.
I'm having a heck of a time understanding your solution.
You would think I'd be able to find a way to just take the HP number from the character generator I made and plug it into 6 rows with 5 sub rows in each as shown above. Then it would only be a matter of the first row taking 2/3 green and the last 1/3 red. But I'll be damned if I can figure out how to do it in any way that makes sense and doesn't make my eyes go cross.
So how do I add this to my table? Here is an example of my code for my Fallout Games. As you can see HP is based off of ST with the option of having bonuses or penalties being added by Class and Difficulty which I select from a dropdown list.
Do I just add {$Start} to my table? Also, if I'm reading this right, you have HP being 1d30 {hp==1d30}& would I be able to substitute that with {hp=={$HP}}&
I'm still trying to work out all your expressions as this is way above what I can do.
I'm going to print out your code and deconstruct it while I'm on my 12 hour overnight shift tonight. I need the same thing for the FP but with only two rows FP and 0 FP
This will save me much time in gaming sessions!
I'll see if I have time to write up a point-by-point deconstruction of the code.
The table "HPDots" only has one entry, so it's really more of a function or procedure. It expects the variable {hp} to already be defined. The first thing it does is set up the variables that CalcRows (called later) is going to need: In retrospect, I didn't really need the variable {lastThird}; it's only used in the following line which calculates the {firstTwoThirds}.
{firstTwoThirds} will tell CalcRows how many green dots to print.
{totRows} is just the total number of dot rows that will be created. It will define how many times CalcRows will be called.
{mod} is just the result of modulo arithmetic, that is, the remainder after doing division. This is intended to be the number of dots in the last row.
A bit of a cheat is required, though, because if I allow {mod} to be zero then a whole row of dots will be skipped. So in that case I set {mod} to the value of the divisor (5), normally an impossible outcome of a modulo expression.
CalcRows will be producing rows for an HTML-table, so this part: a) sets {rowNumber} which CalcRows will increment, to zero.
b) defines the beginning and end of the HTML table
c) calls CalcRows {totRows} times.
Now, on to the CalcRows table. Its purpose is to determine how many green and read dots to produce, and then write them into a row of the HTML table.
First increment {rowNumber}. Then figure out how many {greenDots} we need for the row: {greenDots} at this point is the total number of green dots we want to print -- {firstTwoThirds} -- minus the number of dots we've already printed.
It only makes sense for {greenDots} on a given row to be 0, 5, or somewhere in between, so: ...and {redDots} for this row will be five minus {greenDots}: Of course, it's no guarantee that we'll want the red dots to continue to the end of the line. That can be controlled for with: ...which basically says, "when we're on the last row -- {rowNum}={totRows} -- set the number of red dots as needed, to: {mod} (the total number of dots on the last line) minus {greenDots} (which will typically be zero, but for small {hp} could be nonzero).
This line is pretty hacky and I don't like it, but it was required for a couple of circumstances that I don't remember:
Finally, we write out the row of dots in a HTML table row: Next up, how Colorize works.