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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354 |
<html>
<head>
<title>MappyWin32 Lua scripting documentation</title>
</head>
<body bgcolor="#cccccc" text="#000000" link="#0000ff" vlink="#0000aa">
<p><a name="topod"></a></p>
<h2>MappyWin32 Lua scripting documentation</h2>
<br>
<strong>Lua scripts</strong>. Added in 1.3.22, you can write
scripts to perform functions in the editor such as exporting/importing
graphics, maps and other data from custom formats, editing the map or
blocks, performing a custom task and
many other things. The scripts are written in a language called LUA
(see www.lua.org), see the copyright notice in the luascr folder.
Lua scripts can either be put in the luascr folder, and then set
the LUA values in the mapwin.ini file to add them to the Custom menu.
Alternatively, you can drag and drop a file ending with '.lua'
onto MappyWin32 to run it.<br><br>
I'd like to thank Robbob (Autofringe, Random distribution) and
Jerzy Kut (Export binary file) for their help with lua.
I have included some example scripts in the luascr folder (not all
of these are listed in the custom menu), look
at them in a text editor to see how they work, I am a novice with
Lua, so they are quite basic.
Load a test map and run them to see what they do, most of them
give a brief summary of what they do before they start.
You do not need to restart Mappy if you modify a script. You can
override the functions in the file menu with lua scripts to fully
customize loading and saving of maps (see mapwin.ini).
MappyWin32 extends LUA with these functions (don't forget
to prefix functions and values with 'mappy.' see the .lua files in
the luascr folder):<br><br>
<strong>General functions:</strong><br>
R = getValue (VALUE_ID)<br>
where VALUE_ID is one of:<br>
MAPWIDTH,
MAPHEIGHT,
BLOCKDEPTH,
BLOCKWIDTH,
BLOCKHEIGHT,
NUMBLOCKSTR,
NUMBLOCKGFX,
BLOCKGAPX,
BLOCKGAPY,
BLOCKSTAGGERX,
BLOCKSTAGGERY,
CLICKMASK,
TRANS8,
TRANSRED,
TRANSGREEN,
TRANSBLUE,
CURLAYER,
CURBLOCK,
CURANIM,
CURBRUSH,
MOUSEBLOCKX,
MOUSEBLOCKY,
GETBLOCKMODE,
PALETTEARGB+index,
NUMBLOCKANIM,
XMAPOFFSET,
YMAPOFFSET,
MAPFILENAME,
MAPWINPATH,
MAPTYPE,
MAPWINVERSION,
NUMBRUSHES,
NUMLAYERS,
CUROBJECT,
NUMOBJECTS,
CMDLINE,
NUMCHUNKS,
CURGFX<br><br>
setValue (VALUE_ID, SETVALUE)<br>
where VALUE_ID is one of:<br>
TRANS8,
TRANSRED,
TRANSGREEN,
TRANSBLUE,
PALETTEARGB+index,
GETBLOCKMODE,
CURLAYER,
CURBLOCK,
CURANIM,
CURBRUSH,
XMAPOFFSET,
YMAPOFFSET,
MAPFILENAME,
CUROBJECT,
MAPTYPE,
CURGFX<br><br>
R = shiftVal (VALUE, SHIFT) negative shift is left, positive is right<br>
R = andVal (VALUE1, VALUE2)<br>
R = orVal (VALUE1, VALUE2)<br><br>
<strong>Block functions:</strong><br>
R = getBlock (X, Y [,L])<br>
where X is the x coord in blocks,
and Y is y coord in blocks, L is the optional layer number, omit it for current layer<br><br>
setBlock (X, Y, B [,L])<br>
where X is the x coord in blocks, and Y is y coord in blocks, and B is the block index,
L is the optional layer number, omit it for current layer (see 'Solid rectangle.lua' for an example)<br><br>
R = getBlockValue (B, VALUE_ID)<br>
where B is the block index, and VALUE_ID is one of:<br>
BLKBG,
BLKFG1,
BLKFG2,
BLKFG3,
BLKUSER1,
BLKUSER2,
BLKUSER3,
BLKUSER4,
BLKUSER5,
BLKUSER6,
BLKUSER7,
BLKFLAG1,
BLKFLAG2,
BLKFLAG3,
BLKFLAG4,
BLKFLAG5,
BLKFLAG6,
BLKFLAG7,
BLKFLAG8<br><br>
setBlockValue (B, VALUE_ID, VALUE)<br>
where B is the block index, and VALUE_ID is one of:<br>
BLKBG,
BLKFG1,
BLKFG2,
BLKFG3,
BLKUSER1,
BLKUSER2,
BLKUSER3,
BLKUSER4,
BLKUSER5,
BLKUSER6,
BLKUSER7,
BLKFLAG1,
BLKFLAG2,
BLKFLAG3,
BLKFLAG4,
BLKFLAG5,
BLKFLAG6,
BLKFLAG7,
BLKFLAG8<br>
and VALUE is the value to write (flags are 0 or 1) see 'Tile graphic test.lua'<br><br>
createBlock (B)<br>
where B is the block index to insert the new block at<br><br>
deleteBlock (B)<br>
where B is the block index to remove<br>
R = getBlockSort (index)<br>
Gets the block number from the sortlist<br>
setBlockSort (index, B)<br>
If sortblocks=1 in mapwin.ini, the script luascr/BlockSort.lua is called when the
Blocks in the Block Editor window are refreshed. You can filter blocks however
you want, and put the blocks you want to display in the list<br>
<br>
<br><br>
<strong>Layer functions:</strong><br>
copyLayer (SOURCE, DEST)<br>
where SOURCE is the layer to copy from (0 to 7 or MPY_UNDO), and DEST is the
layer to copy to (0 to 7 or MPY_UNDO) if you are changing the current layer, use:<br>
mappy.copyLayer(mappy.getValue(mappy.CURLAYER),mappy.MPY_UNDO)<br>
to enable undo.<br><br>
createLayer (layer)<br>
deleteLayer (layer)<br>
<br>
<strong>Graphics functions:</strong><br>
createGraphic (G)<br>
where G is the graphic index to insert the new graphic at<br><br>
deleteGraphic (G)<br>
where G is the graphic index to remove<br><br>
In the following A is Alpha, R is Red, G is Green, B is Blue, all values between
0 (none) and 255 (max), 0 Alpha is transparent, 255 is solid.<br>
A,R,G,B = getPixel (X, Y, G)<br>
where X, Y is pixel coord within the graphic, G is the graphic index<br><br>
setPixel (X, Y, G, A, R, G, B) or<br>
setPixel (X, Y, G, INDEX)<br>
where INDEX is the palette index 0 to 255)<br><br>
R = importGraphics ("FILENAME", GFXPOS, AMOUNT)<br>
where GFXPOS is the graphic number to start importing at, and AMOUNT
is the number of tiles to import. AMOUNT can be 0 for all.<br><br>
<strong>Dialogue/Requester functions:</strong><br>
R = msgBox ("TITLE", "MESSAGE", TYPE, ICON)<br>
where TYPE is one of:<br>
MMB_OK,
MMB_OKCANCEL,
MMB_YESNOCANCEL,<br>
and ICON is one of:<br>
MMB_ICONNONE,
MMB_ICONINFO,
MMB_ICONQUESTION,
MMB_ICONEXCLAMATION<br>
returns one of:<br>
MMB_CANCEL,
MMB_YES,
MMB_NO<br><br>
R, "FILENAME" = fileRequester ("PATH", "DESCRIPTION", "EXTENSION", TYPE)<br>
where PATH is the starting folder (try "."), DESCRIPTION is what
appears in the 'Save as type' box, EXTENSION is a properly formatted mask
for file extensions (ie: "*.FMP" or "*.FMP;*.MAP"). And TYPE is either
MMB_OPEN or MMB_SAVE<br>
returns R, either MMB_OK or MMB_CANCEL, also "FILENAME"<br><br>
R = doDialogue ("TITLE", "MESSAGE", "STRING", TYPE)<br>
where TYPE is either MMB_DIALOGUE1 or MMB_DIALOGUE2, type 1 returns
MMB_OK or MMB_CANCEL and one string, type 2 returns MMB_OK or MMB_CANCEL
and as many strings as there were commas plus 1 (ie: hello,1,2,3 would
return four strings "hello" "1" "2" and "3")<br>
<strong>Complex dialogue boxes:</strong><br>
R = doDialogue ("DLGPROC")<br>
"DLGPROC" is the name of the handler for dialogue messages.
See the scripts
'Dialogue Example.lua' and 'Dialogue Proc.lua'. Some knowledge of Win32
dialogues is required.<br>
createDialogue ("Title", STYLE, X, Y, W, H, NUMCONTROLS)<br>
creates a custom dialogue, STYLE can be 0 for default. See the scripts
'Dialogue Example.lua' and 'Dialogue Proc.lua'. Some knowledge of Win32
dialogues is required.<br>
addDialogueItem ("Title", STYLE, X, Y, W, H, IDC, TYPE)<br>
See defines in 'Dialogue Example.lua'<br>
hwnd, msg, wParam, lParam = getDialogueParam ()<br>
See 'Dialogue Proc.lua', note: Proc is sent idc == 99 on creation so
lists can be populated and labels changed etc<br>
checkDlgButton (IDC, STATUS)<br>
Sets button IDC to STATUS<br>
R = isDlgButtonChecked (IDC)<br>
R is STATUS of button IDC<br>
R = getDlgItemText (IDC)<br>
R is text of item as a string<br>
setDlgItemText (IDC, "TEXT")<br>
TEXT is new text of item as a string<br>
R = sendDlgItemMessage (IDC, MSG, WPARAM, LPARAM)<br>
Get and Set information for all types of buttons etc. Allows
setting and retrieving see
any tutorial on Win32 dialogues and DlgItemMessage<br>
<br><br>
<strong>Anim functions:</strong><br>
createAnim (animnum)<br>
deleteAnim (animnum)<br>
R = getAnimFrame (animnum, framenum)<br>
'framenum' can be ANMREFFRAME<br>
setAnimFrame (animnum, framenum, blockval)<br>
'framenum' can be ANMREFFRAME<br>
R = numAnimFrames (animnum)<br>
insertAnimFrame (animnum, framenum, blockval)<br>
cutAnimFrame (animnum, framenum)<br>
R = numAnimFrames (animnum)<br>
R = getAnimValue (VAL)<br>
VAL is:<br>
ANMDELAY, ANMCOUNT, ANMTYPE, ANMUSER, ANMCURFRAME<br>
setAnimValue (VAL, val)<br>
VAL is:<br>
ANMDELAY, ANMCOUNT, ANMTYPE, ANMUSER, ANMCURFRAME<br>
<br>
<strong>Brush functions:</strong><br>
createBrush (brshnum, x, y, w, h)<br>
deleteBrush (brshnum)<br>
renameBrush (brshnum, "Brushname")<br>
R = getBrushBlock (brshnum, x, y)<br>
setBrushBlock (brshnum, x, y, blk)<br>
R = getBrushValue (VAL)<br>
VAL is:<br>
BRUSHWIDTH, BRUSHHEIGHT, BRUSHNAME<br>
<br>
<strong>TextString functions:</strong><br>
getTextString (index)<br>
setTextString (index, "Text")<br>
<br>
<strong>Map/System functions:</strong><br>
newMap (mapwidth, mapheight, mapdepth, tilewidth, tileheight, [tilegapx, tilegapy, tilestaggerx, tilestaggery, maptype])<br>
closeMap ()<br>
openFMP (["FILENAME"])<br>
saveFMP (["FILENAME"])<br>
if no "filename" supplied, current filename is used. On saving,
use mappy.setValue(mappy.MAPFILENAME, "filename") if you want to change the name<br>
resizeMap (WIDTH, HEIGHT, CENTERING)<br>
CENTERING is from 1 to 9 as in the MapTools:Resize dialogue<br>
updateScreen ()<br>
call this to refresh the display after altering a layer<br><br>
shellExecute (action, file, params, dir, style)<br>
call an external programme, example:
mappy.shellExecute ("open", "notepad", "mapwin.ini", "c:/mapwin148/", 0)<br>
sendMessage (code, 0)<br>
code is one of the key shortcuts listed in mapwin.htm<br>
for example sendMessage (119, 0) shows the helpfile<br>
renameMenuItem (code, "Name")<br>
code is one of the key shortcuts listed in mapwin.htm. "Name" is the new name for the menu item<br>
moveWindow (WINDOW, x, y, width, height)<br>
added (WINDOW = MPY_MAINWINDOW, MPY_MAPWINDOW or MPY_BLOCKWINDOW)<br>
<br>
<strong>Object functions (Pro only):</strong><br>
createObject (position)<br>
deleteObject (objnum)<br>
R = getObjectValue (objnum, VALUE_ID)<br>
setObjectValue (objnum, VALUE_ID, objval)<br>
VALUE_ID for the above can be one of:
OBJXPOS,
OBJYPOS,
OBJGFXID,
OBJTILEID,
OBJGXOFF,
OBJGYOFF,
OBJGWIDTH,
OBJGHEIGHT,
OBJGHANDLEXOFF,
OBJGHANDLEYOFF,
OBJSHOW,
OBJUSER1,
OBJUSER2,
OBJUSER3,
OBJUSER4,
OBJUSER5,
OBJUSER6,
OBJUSER7,
OBJFLAGS<br>
R = getObjectFilename (index)<br>
Gets the string for the image filename displayed in the Object Properties dialogue,
'index' is the position in the list<br>
setObjectFilename (index, "Filename")<br>
Sets the string for the image filename displayed in the Object Properties dialogue,
'index' is the position in the list<br>
R = getObjectSort (index)<br>
Gets the object number from the sortlist<br>
setObjectSort (index, objnum)<br>
If sortobjects=1 in mapwin.ini, the script luascr/ObjectSort.lua is called when the
Objects in the Block Editor window are refreshed. You can filter objects however
you want, and put the objects you want to display in the list<br>
<br>
<strong>Chunk functions:</strong><br>
Warning: for custom chunks only, incorrect use can corrupt map file<br>
createChunk ("CHNK", size, position)<br>
"CHNK" is a four character string NOT used by the editor, size is
the size of the chunk in bytes, position is where in custom chunks it is
inserted (use 0 to put it at the front)<br>
deleteChunk (chunknum)<br>
R = getChunkValue (chunknum, offset)<br>
setChunkValue (chunknum, offset, value)<br><br>
<p><a href="#topod">(top of doc)</a> </p>
<p><a href="mapwin.htm">(Back to main documentation)</a> </p>
</body>
</html> |