-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc_methods.gml
288 lines (237 loc) · 8.49 KB
/
misc_methods.gml
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
// api_choose()
// choose randomly from a list of items
function sc_mod_api_choose(items) {
var choice = irandom(array_length(items)-1);
return items[choice];
}
// api_is_game_paused()
// is game paused y/n
function sc_mod_api_is_game_paused() {
return global.PAUSED;
}
// api_random_range()
// choose a random number between a range
function sc_mod_api_random_range(sn, en) {
return irandom_range(sn, en);
}
// api_random()
// choose a random number between 0 and x
function sc_mod_api_random(sn) {
return irandom(sn);
}
// api_measure_text()
// measures the size a piece of text will take up when drawn with api_draw_text()
function sc_mod_api_measure_text(text, tw) {
return sc_measure_text(text, tw == undefined ? 0 : tw);
}
// api_toggle_menu()
// toggle a menu to be open or closed
function sc_mod_api_toggle_menu(menu_id, toggle) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(menu_id);
if (menu_id != undefined && instance_exists(menu_id) && menu_id.object_index == ob_menu) {
sc_menu_object_toggle(menu_id.obj, toggle, true);
return "Success";
} else {
sc_mod_log(mod_name, "api_toggle_menu", "Error: Invalid Menu Instance", undefined);
return undefined;
}
}
// api_destroy_inst()
// destroy a given inst
function sc_mod_api_destroy_instance(inst_id) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(inst_id);
if (inst_id != undefined) {
if (inst_id == global.PLAYER) {
sc_mod_log(mod_name, "api_destroy_inst", "Error: Why Would You Even Try That? :(", undefined);
return undefined;
} else if (variable_instance_exists(inst_id, "oid") && inst_id.oid == "scenery1") {
sc_mod_log(mod_name, "api_destroy_inst", "Error: Why Would You Do That To Poor Skipper? :(", undefined);
return undefined;
} else {
if (global.HIGHLIGHTED_OBJ == inst_id) global.HIGHLIGHTED_OBJ = "";
if (global.HIGHLIGHTED_ITEM == inst_id) global.HIGHLIGHTED_ITEM = "";
if (global.HIGHLIGHTED_MENU == inst_id) global.HIGHLIGHTED_MENU = "";
instance_destroy(inst_id);
return "Success";
}
} else {
sc_mod_log(mod_name, "api_destroy_inst", "Error: Invalid Instance ID", undefined);
return undefined;
}
}
// api_check_discovery()
// check for discovery of a iven oid
function sc_mod_api_check_discovery(oid) {
return ds_list_find_index(global.DISCOVERED, oid) != -1;
}
// api_play_sound()
// plays a sound effect from the base game
function sc_mod_api_play_sound(name) {
var vol = 0;
switch(name) {
case "break": vol = 0.2; break;
case "click": vol = 0.1; break;
case "confetti": vol = 0.2; break;
case "error": vol = 0.2; break;
case "jingle": vol = 0.3; break;
case "open": vol = 0.1; break;
case "plop": vol = 0.1; break;
case "pop": vol = 0.1; break;
case "rollover": vol = 0.1; break;
}
if (vol != 0) sc_play_sound(name, vol);
}
// api_unlock_quest()
// unlocks a quest based on the quest id
function sc_mod_api_unlock_quest(quest_id) {
var progress = global.QUEST_PROGRESS[? quest_id];
if (progress == undefined) return undefined;
global.QUEST_PROGRESS[? quest_id].unlocked = true;
global.PLAYER.book1_ref.defined = false;
sc_book_define(global.PLAYER.book1_ref, 0, true);
return "Success";
}
// api_blacklist_input()
// blacklists input for a given menu oid so vanilla key inputs are ignored while the menu is highlighted
function sc_mod_api_blacklist_input(menu_oid) {
if (ds_list_find_index(global.MOD_BLACKLIST, menu_oid) == -1) {
ds_list_add(global.MOD_BLACKLIST, menu_oid);
}
}
// api_remove_gui()
// lets you delete a gui you defined with api_define_gui()
function sc_mod_api_remove_gui(menu_id, gui_key) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(menu_id);
if (menu_id != undefined && instance_exists(menu_id) && menu_id.object_index == ob_menu) {
var existing = variable_instance_get(menu_id, gui_key);
if (existing != undefined && instance_exists(existing)) {
instance_destroy(existing);
variable_instance_set(menu_id, gui_key, undefined);
return "Success";
} else {
sc_mod_log(mod_name, "api_remove_gui", "Error: GUI Key Empty/Undefined", undefined);
}
} else {
sc_mod_log(mod_name, "api_remove_gui", "Error: Menu Instance Not Found", undefined);
return undefined;
}
}
// api_library_add_book()
// lets you add a book icon to the bottom library menu which can call a script you define when clicked
// this doesnt add any book functionality, you must provide that yourself (see the Sample Mod for an example book)
function sc_mod_api_library_add_book(book_name, book_script, book_sprite) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
var spr = sprite_add(working_directory + "mods/" + mod_name + "/" + book_sprite, 2, true, false, 0, 0);
if (spr == -1) {
sc_mod_log(mod_name, "api_library_add_book", "Error: Book Sprite Not Found", undefined);
return undefined;
} else {
if (global.MOD_BOOKS[? book_name] == undefined) {
global.MOD_BOOKS[? book_name] = book_script;
array_push(global.MOD_BOOK_LIST, book_name);
// add book gui to library
var b = array_length(global.MOD_BOOK_LIST) + 3;
var menu = global.PLAYER.menu_book;
var oid = "book" + string(b+1);
var book = instance_create_layer(menu.x + 5 + (b*18), menu.y + 4, "Menus", ob_button);
book.sprite_index = spr;
book.ox = 5 + (b*18)
book.oy = 4;
book.type = "BookMod";
book.text = book_name;
book.index = lua_current;
book.menu = menu.id;
variable_struct_set(menu.books, oid, book);
// update library
sc_library_update(menu);
return "Success";
} else {
sc_mod_log(mod_name, "api_library_add_book", "Error: Book Name Already Used", undefined);
return undefined;
}
}
}
// api_add_slot_to_menu()
// lets you add the contents of a slot to a given menu
// if there is room the slot is cleared, otherwise the remainder is left in the slot
function sc_mod_api_add_slot_to_menu(slot_id, menu_id) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
sc_mod_api_set_active(slot_id);
sc_mod_api_set_active(menu_id);
if (instance_exists(slot_id) && instance_exists(menu_id)) {
sc_menu_add(menu_id, slot_id);
try {
if (menu_id.obj != "X" && menu_id.obj != -1) {
sc_menu_change(menu_id.obj);
}
} catch(ex) {
log("sc_mod_api_add_slot_to_menu A", ex);
}
try {
if (slot_id.menu != "" && slot_id.menu.obj != "X" && slot_id.menu.obj != -1) {
sc_menu_change(slot_id.menu.obj);
}
} catch(ex) {
log("sc_mod_api_add_slot_to_menu B", ex);
}
return "Success";
} else {
sc_mod_log(mod_name, "api_add_slot_to_menu", "Error: Menu/Slot Instance Doesn't Exists", undefined);
return undefined;
}
}
// api_inst_exists()
// lets you check if a instance exists
// NB will return false if the instance is deactivated too!
function sc_mod_api_inst_exists(inst_id) {
sc_mod_api_set_active(inst_id);
return instance_exists(inst_id);
}
// api_update_tooltip()
// refreshes the tooltip cache
function sc_mod_api_refresh_tooltip() {
sc_util_update_tooltip();
}
// api_http_request()
// lets you send a http request
function sc_mod_api_http_request(url, method_type, header_keys, body, callback) {
var mod_name = global.MOD_STATE_IDS[? lua_current];
try {
var headers = ds_map_create();
var keys = variable_struct_get_names(header_keys);
for (var k = 0; k < array_length(keys); k++) {
ds_map_set(headers, keys[k], header_keys[$ keys[k]]);
}
var req = http_request(url, method_type, headers, body);
global.MOD_HTTP_API[$ mod_name + "_" + callback] = {
id: req,
name: mod_name,
state: lua_current,
callback: callback
}
ds_map_destroy(headers);
sc_mod_log(mod_name, "api_http_request", "Sent Request (" + url + ")", undefined);
return "Success";
} catch(ex) {
sc_mod_log(mod_name, "api_http_request", "Error: Failed To Send Request", ex.longMessage);
return undefined;
}
}
// api_has_incense()
// checks for an incense at a given position
function sc_mod_api_has_incense(tx, ty, incense_oid) {
return sc_util_has_incense(tx, ty, incense_oid);
}
// api_game_state()
// gets current game state
function sc_mod_api_game_state() {
return {
game_paused: global.PAUSED,
game_loading: global.LOADING,
game_saving: global.SAVING,
world_loading: global.WORLD_LOADING
}
}