settings_api.inc
Original include source with line numbers.
| 1 | #if defined _settings_api_included |
| 2 | #endinput |
| 3 | #endif |
| 4 | |
| 5 | #define _settings_api_included |
| 6 | |
| 7 | // Comment this to disable debug messages |
| 8 | // #define PRINT_DEBUG_MESSAGES |
| 9 | |
| 10 | #include <settings_util> |
| 11 | |
| 12 | #define MAX_OPTION_LENGTH 32 |
| 13 | #define MAX_STR_VALUE_LENGTH 64 |
| 14 | |
| 15 | #define RESERVER_OPTION_END "#reserved_option_end" |
| 16 | |
| 17 | enum OptionFieldType { |
| 18 | FIELD_TYPE_INT, |
| 19 | FIELD_TYPE_FLOAT, |
| 20 | FIELD_TYPE_BOOL, |
| 21 | FIELD_TYPE_STRING, |
| 22 | }; |
| 23 | |
| 24 | /** |
| 25 | * Register option for players (int/float/bool value) |
| 26 | * note: should be called in plugin_precache |
| 27 | * |
| 28 | * @param optionName option name |
| 29 | * @param fieldType see `OptionFieldType` constants |
| 30 | * @param defaultValue default value |
| 31 | * |
| 32 | * @noreturn |
| 33 | */ |
| 34 | native register_players_option_cell(optionName[MAX_OPTION_LENGTH], OptionFieldType:fieldType, any:defaultValue = 0); |
| 35 | |
| 36 | /** |
| 37 | * Register option for players (string value) |
| 38 | * note: should be called in plugin_precache |
| 39 | * |
| 40 | * @param optionName option name |
| 41 | * @param defaultValue default value |
| 42 | * |
| 43 | * @noreturn |
| 44 | */ |
| 45 | native register_players_option_str(optionName[MAX_OPTION_LENGTH], defaultValue[MAX_STR_VALUE_LENGTH]); |
| 46 | |
| 47 | /** |
| 48 | * Get option id by its name |
| 49 | * note: should not be called in plugin_precache |
| 50 | * |
| 51 | * @param optionName option name |
| 52 | * |
| 53 | * @return -1 if option does not exist, id >= 0 otherwise |
| 54 | */ |
| 55 | native find_option_by_name(optionName[MAX_OPTION_LENGTH]); |
| 56 | |
| 57 | native get_option_cell(id, optionId); |
| 58 | |
| 59 | native set_option_cell(id, optionId, newValue, bool:notifyMysql = true); |
| 60 | |
| 61 | native get_option_string(id, optionId, buffer[MAX_STR_VALUE_LENGTH]); |
| 62 | |
| 63 | native set_option_string(id, optionId, buffer[MAX_STR_VALUE_LENGTH], bool:notifyMysql = true); |
| 64 | |
| 65 | /** |
| 66 | * Calls from `settings_mysql` when connection is ready |
| 67 | * |
| 68 | * @noreturn |
| 69 | */ |
| 70 | forward OnConnectionIsReady(); |
| 71 | |
| 72 | /** |
| 73 | * Calls after all options were created in database |
| 74 | * |
| 75 | * @noreturn |
| 76 | */ |
| 77 | forward OnOptionsInitialized(); |
| 78 | |
| 79 | /** |
| 80 | * Calls when option is ready to be initialized (after `OnConnectionIsReady`) |
| 81 | * |
| 82 | * @param optionName option name |
| 83 | * @param fieldType see `OptionFieldType` constants |
| 84 | * @param defaultValue default value |
| 85 | */ |
| 86 | forward OnRegisterOption(optionName[MAX_OPTION_LENGTH], OptionFieldType:fieldType, defaultValue[MAX_STR_VALUE_LENGTH]); |
| 87 | |
| 88 | forward OnCellValueChanged(id, optionId, newValue); |
| 89 | |
| 90 | forward OnStringValueChanged(id, optionId, newValue[MAX_STR_VALUE_LENGTH]); |
| 91 | |
| 92 | forward OnNotifyMysqlCellValue(id, optionId, newValue); |
| 93 | |
| 94 | forward OnNotifyMysqlStringValue(id, optionId, newValue[MAX_STR_VALUE_LENGTH]); |