-
Notifications
You must be signed in to change notification settings - Fork 2
/
map-tools.js
49 lines (42 loc) · 1.62 KB
/
map-tools.js
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
// Sample script that adds functions for manipulating the park
// #3526: Make vandalism
var destroyAllFootpathItems = function() {
// Iterate every tile in the map
for (var y = 0; y < map.size.y; y++) {
for (var x = 0; x < map.size.x; x++) {
var tile = map.getTile(x, y);
// Iterate every element on the tile
for (var i = 0; i < tile.numElements; i++) {
var element = tile.getElement(i);
// If the element is a footpath, set the broken flag to true
if (element.type === 'footpath') {
element.isAdditionBroken = true;
}
}
}
}
}
var main = function() {
// In JavaScript, the var keyword is used to define a new variable in the current closure. Functions
// are the only closure in ES5, braces do not create new scope. You can think of var as an equivalent
// of the local keyword from other scripting languages such as LUA.
// If we do not use the var keyword then the variable acts as a global shared between all plugins and
// the console. The following code allows the console and other plugins to use our functions.
if (typeof samples === 'undefined') {
samples = {};
}
samples.map_tools = {
destroyAllFootpathItems: destroyAllFootpathItems
};
// Add a menu item under the map icon on the top toolbar
ui.registerMenuItem("Destroy all footpaths", function() {
destroyAllFootpathItems();
});
};
registerPlugin({
name: 'Map Tools',
version: '1.0',
authors: ['OpenRCT2'],
type: 'remote',
main: main
});