forked from mike347/ATSPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATS_ExpBar.xml
266 lines (216 loc) · 6.57 KB
/
ATS_ExpBar.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Friday, May 23, 2014, 9:00 AM -->
<!-- MuClient version 4.84 -->
<!-- Plugin "ATS_Exp_Bar" generated by Plugin Wizard -->
<muclient>
<plugin
name="ATS_Exp_Bar"
author="Qon @ TrekMUSH"
id="3c628de45ada3cb07b9b1448"
language="Lua"
purpose="Shows Experience bar for ATS TrekMUSH"
date_written="2014-05-23 08:54:00"
requires="4.84"
version="1.0"
save_state="y"
>
<description trim="y">
<![CDATA[
This will generate an XP bar for use with ATS TrekMUSH.
You must first do a 'char sheet', or 'char attrib list' to setup the bar.
Anytime you level, you must do that again. (Until I am able to catch the level)
]]>
</description>
</plugin>
<!-- Get our standard constants -->
<include name="constants.lua"/>
<!-- Plugin help -->
<aliases>
<alias
script="OnHelp"
match="ATS_Exp_Bar:help"
enabled="y"
>
</alias>
</aliases>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
group="xpwindow"
match=" Experience * (* needed to level up)"
script="fun_xp_char_sheet"
sequence="100"
>
</trigger>
<trigger
enabled="y"
group="xpwindow"
match="Level * Experience * (* needed)"
script="fun_xp_attr_list"
sequence="100"
>
</trigger>
<trigger
enabled="y"
group="xpwindow"
match="You earn * experience points for *"
script="fun_xpearned"
sequence="100"
>
</trigger>
</triggers>
<script>
<![CDATA[
function OnHelp ()
world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
win = GetPluginID () -- get a unique name
current_xp = tonumber(GetVariable("ATS_CURRENT_XP"))
if not current_xp then
SetVariable("ATS_CURRENT_XP", "0")
current_xp = 0
end
max_xp = tonumber(GetVariable("ATS_XP_REQUIRED"))
if not max_xp then
SetVariable("ATS_XP_REQUIRED", "0")
max_xp = 0
end
level = tonumber(GetVariable("ATS_LEVEL"))
if not level then
level = 0
SetVariable("ATS_LEVEL", "0")
end
-- configuration
exp_table = { 1000, 3000, 6000, 10000, 15000, 21000, 28000, 36000, 45000, 55000, 66000, 78000, 91000, 105000, 120000, 136000, 153000, 171000, 190000 }
GAUGE_HEIGHT = 11
NUMBER_OF_TICKS = 20
BACKGROUND_COLOUR = ColourNameToRGB "gray"
BOX_COLOUR = ColourNameToRGB "dodgerblue"
-- draw the bar here, on getting the prompt, or window resize
function draw_bar ()
-- check numbers for validity
if not current_xp or
not max_xp or
current_xp < 0 or
max_xp <= 0 then
return
end -- if
-- cannot have more than max xp
if current_xp > max_xp then
current_xp = max_xp
end -- if
SaveState () -- Saves state so we don't have to call it in each of our functions., only when we redraw.
-- width is window width minus 2
local gauge_width = GetInfo (281) - 2
-- make room for the bar
local bottom_margin = GetInfo (275)
-- adjust text rectangle, keeping existing settings where possible
if bottom_margin == 0 or
(bottom_margin < 0 and math.abs (bottom_margin) < (GAUGE_HEIGHT + 2)) then
TextRectangle(GetInfo (272), GetInfo (273), -- left, top
GetInfo (274), -- right
- (GAUGE_HEIGHT + 2), -- bottom (gauge height plus 2 more)
GetInfo (276), GetInfo (282) or 0, GetInfo (277), -- BorderOffset, BorderColour, BorderWidth
GetInfo (278), GetInfo (279)) -- OutsideFillColour, OutsideFillStyle
end -- if
-- make the miniwindow
WindowCreate (win,
0, 0, -- left, top (auto-positions)
gauge_width, -- width
GAUGE_HEIGHT, -- height
10, -- auto-position: bottom left
0, -- flags
BACKGROUND_COLOUR)
WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR) -- fill entire box
-- how far through the level we are
local done = current_xp / max_xp
local bar_width = gauge_width * done
-- box size must be > 0 or WindowGradient fills the whole thing
if math.floor (bar_width) > 0 then
-- top half
WindowGradient (win, 0, 0,
bar_width, GAUGE_HEIGHT / 2,
0x000000, -- black
BOX_COLOUR,
2) -- vertical gradient
-- bottom half
WindowGradient (win, 0, GAUGE_HEIGHT / 2,
bar_width, 0,
BOX_COLOUR,
0x000000, -- black
2) -- vertical gradient
end -- any experience to speak of
-- show ticks
local ticks_at = gauge_width / NUMBER_OF_TICKS
-- ticks
for i = 1, NUMBER_OF_TICKS do
WindowLine (win, i * ticks_at, 0, i * ticks_at, GAUGE_HEIGHT, ColourNameToRGB ("silver"), 0, 1)
end -- for
-- draw a box around it
check (WindowRectOp (win, 1, 0, 0, 0, 0, ColourNameToRGB ("lightgrey"))) -- frame entire box
-- ensure window visible
WindowShow (win, true)
end -- draw_bar
function fun_xp_char_sheet(name, line, wildcards, styles)
level = findlevel(tonumber(wildcards[1]) + tonumber(wildcards[2])) -- Exp needed for level
if ( level >0) then
current_xp = (tonumber(wildcards[1] ) - exp_table[level == 1 and level or level-1])
max_xp = current_xp + tonumber(wildcards[2])
else
current_xp = tonumber(wildcards[1])
max_xp = tonumber(wildcards[2])
end
SetVariable("ATS_LEVEL", level)
SetVariable("ATS_CURRENT_XP", current_xp)
SetVariable("ATS_REQUIRED_XP", max_xp)
draw_bar ()
end
function fun_xp_attr_list(name,line,wildcards,styles)
level = tonumber(wildcards[1])
current_xp = (tonumber(wildcards[2]) - exp_table[level-1])
max_xp = (tonumber(wildcards[3]) - exp_table[level-1])
SetVariable("ATS_LEVEL", level)
SetVariable("ATS_CURRENT_XP", current_xp)
SetVariable("ATS_REQUIRED_XP", max_xp)
draw_bar()
end
function fun_xpearned(name,line,wildcards,styles)
current_xp = (current_xp + tonumber(wildcards[1]))
SetVariable("ATS_CURRENT_XP", current_xp)
draw_bar()
end
function fun_manualset(xp, maxxp)
current_xp = tonumber(xp)
max_xp = tonumber(maxxp)
draw_bar()
end
-- When called, returns the XP required for level (level).
-- E.g.
-- fun_xp_req(5) -- Will return 10000, the exp required to go from level 4 to level 5.
function findlevel(xp)
for i,v in ipairs(exp_table) do
if(v == xp) then
return i
end
end
end
function OnPluginConnect ()
draw_bar()
end -- function
function OnPluginWorldOutputResized ()
draw_bar ()
end -- function
-- hide window on removal
function OnPluginClose ()
WindowShow (win, false) -- hide it
end -- OnPluginClose
-- hide window on disable
function OnPluginDisable ()
WindowShow (win, false) -- hide it
end -- OnPluginDisable
draw_bar()
]]>
</script>
</muclient>