I took a shot at combining the health and experience bar plugins into a single, one-window plugin. So far, I have met with a lot of success! I have, however, hit one snag. I can't figure out how to separate the draw_the_bars function in a way that will let me draw the hp/sp/ep gauges whenever I get the prompt, while also drawing the experience/money gauges whenever I use the commands that display my XP and CP. With no prompt configuration available, I can't use the easy route of a single trigger. So! I made a lot of triggers. The triggers work, they all return the values I need, and the draw_the_bars function is sending the right information to the DoGauge function. How do I separate it all out to redraw the xp/cp bars without erasing the hp/sp/ep bars?
Here are a couple snips from my script.
These triggers grab the values I need to level.
<trigger
enabled="y"
match="^LEVEL (\d+) ADVANCEMENT$"
regexp="y"
script="do_prompt_level"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="^Advancement will cost (\d+) experience and (\d+) coppers\.$"
regexp="y"
script="do_prompt_cost"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="^You will need (\d+) more experience and (\d+) more coppers\.$"
regexp="y"
script="do_prompt_tnl"
sequence="100"
>
</trigger>
These functions store the values.
function do_prompt_level (name, line, wildcards)
next_level = tonumber (wildcards [1])
level = next_level - 1
end -- do_prompt_level
function do_prompt_cost (name, line, wildcards)
max_xp = tonumber (wildcards [1])
max_cp = tonumber (wildcards [2])
end -- do_prompt_cost
function do_prompt_tnl (name, line, wildcards)
tnl_xp = tonumber (wildcards [1])
tnl_cp = tonumber (wildcards [2])
xp = max_xp - tnl_xp
cp = max_cp - tnl_cp
end -- do_prompt_tnl
This function draws it all, and is only called by my hp/sp/ep functions.
function draw_the_bars ()
-- fill entire box to clear it
check (WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR)) -- fill entire box
-- Edge around box rectangle
check (WindowCircleOp (win, 3, 0, 0, 0, 0, BORDER_COLOUR, 0, 2, 0, 1))
vertical = 6 -- pixel to start at
DoGauge ("HP: ", hp, max_hp, ColourNameToRGB "darkgreen")
DoGauge ("SP: ", sp, max_sp, ColourNameToRGB "mediumblue")
DoGauge ("EP: ", ep, max_ep, ColourNameToRGB "red")
DoGauge ("XP: ", xp, max_xp, ColourNameToRGB "darkviolet")
DoGauge ("CP: ", cp, max_cp, ColourNameToRGB "gold")
WindowShow (win, true)
end -- draw_the_bars
I tried splitting out the xp and cp parts into a second draw_the_xp_bars function, but when that was called it would erase my hp/sp/ep bars, which I don't want to do. I'd also like to somehow get the XP bar display to show "L5: " (or whatever my current level is) instead of "XP: ", which is why that first trigger and function is in there. Any idea how I can get this mess to work?
edit: Something I tried earlier was having the xp/cp triggers also call the draw_the_bars function, but when first installing the plugin, those values aren't all there, so it can't draw the bars! |