customshop.inc
Original include source with line numbers.
| 1 | #if defined _customshop_included |
| 2 | #endinput |
| 3 | #endif |
| 4 | |
| 5 | #include <cshop_settings> |
| 6 | |
| 7 | #define _customshop_included |
| 8 | |
| 9 | /** |
| 10 | * Used in cshop_item_selected() to prevent buying an item |
| 11 | */ |
| 12 | #define DONT_BUY PLUGIN_HANDLED |
| 13 | |
| 14 | /** |
| 15 | * Used in cshop_item_selected() to allow buying an item |
| 16 | */ |
| 17 | #define BUY_ITEM PLUGIN_CONTINUE |
| 18 | |
| 19 | /** |
| 20 | * Used in cshop_menu_opened() to prevent opening the shop |
| 21 | */ |
| 22 | #define SHOP_CLOSE PLUGIN_HANDLED |
| 23 | |
| 24 | /** |
| 25 | * Used in cshop_menu_opened() to allow opening the shop |
| 26 | */ |
| 27 | #define SHOP_OPEN PLUGIN_CONTINUE |
| 28 | |
| 29 | /** |
| 30 | * Typically used for registering an item variable, nothing fancy |
| 31 | */ |
| 32 | #define additem new |
| 33 | |
| 34 | /** |
| 35 | * Data types for cshop_get_item_data() |
| 36 | */ |
| 37 | enum _:CshopData |
| 38 | { |
| 39 | CSHOP_DATA_ID = 0, |
| 40 | CSHOP_DATA_NAME, |
| 41 | CSHOP_DATA_PRICE, |
| 42 | CSHOP_DATA_LIMIT, |
| 43 | CSHOP_DATA_SOUND, |
| 44 | CSHOP_DATA_DURATION, |
| 45 | CSHOP_DATA_TEAM, |
| 46 | CSHOP_DATA_FLAGS |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Registers a new item. |
| 51 | * |
| 52 | * @param id Item short name (id). |
| 53 | * @param name Item name. |
| 54 | * @param price Item price. |
| 55 | * @param limit Item limit. |
| 56 | * @param sound Sound when buying the item. |
| 57 | * @param duration If you want the item to be removed after X seconds, instead of right away. |
| 58 | * @param points If you want to change the price with points. |
| 59 | * @param team If you want it to be available for a specific team only. |
| 60 | * @param flag If you want only players with a specific flag to be able to buy the item. |
| 61 | * @return Item ID. |
| 62 | */ |
| 63 | native cshop_register_item(id[], name[], price, limit = 0, sound[] = DEFAULT_SOUND, Float:duration = 0.0, points = 0, team = 0, flag[] = "") |
| 64 | #define cshopRegisterItem cshop_register_item |
| 65 | |
| 66 | /** |
| 67 | * Checks whether a player has an item or not. |
| 68 | * |
| 69 | * @param id Player's index. |
| 70 | * @param item Item ID. |
| 71 | * @return True if he has, false if he hasn't. |
| 72 | */ |
| 73 | native bool:cshop_has_item(id, item) |
| 74 | #define cshopHasItem cshop_has_item |
| 75 | |
| 76 | /** |
| 77 | * Checks whether the points system is enabled. |
| 78 | * |
| 79 | * @return True if it is, false if it isn't. |
| 80 | */ |
| 81 | native bool:cshop_points_enabled() |
| 82 | #define cshopPointsEnabled cshop_points_enabled |
| 83 | |
| 84 | /** |
| 85 | * Checks player's item limit. |
| 86 | * |
| 87 | * @param id Player's index. |
| 88 | * @param item Item ID. |
| 89 | * @return Player's item limit. |
| 90 | */ |
| 91 | native cshop_get_limit(id, item) |
| 92 | #define cshopGetLimit cshop_get_limit |
| 93 | |
| 94 | /** |
| 95 | * Removes a player's item. |
| 96 | * |
| 97 | * @param id Player's index. |
| 98 | * @param item Item ID. |
| 99 | * @noreturn |
| 100 | */ |
| 101 | native cshop_remove_item(id, item) |
| 102 | #define cshopRemoveItem cshop_remove_item |
| 103 | |
| 104 | /** |
| 105 | * Called right before an item is purchased. |
| 106 | * |
| 107 | * @param id Player's index. |
| 108 | * @param item Item ID. |
| 109 | * @noreturn |
| 110 | */ |
| 111 | forward cshop_item_selected(id, item) |
| 112 | #define cshopItemBought cshop_item_selected |
| 113 | |
| 114 | /** |
| 115 | * Called when an item is removed. |
| 116 | * |
| 117 | * @param id Player's index. |
| 118 | * @param item Item ID. |
| 119 | * @noreturn |
| 120 | */ |
| 121 | forward cshop_item_removed(id, item) |
| 122 | #define cshopItemRemoved cshop_item_removed |
| 123 | |
| 124 | /** |
| 125 | * Called right before the menu is opened. |
| 126 | * |
| 127 | * @param id Player's index. |
| 128 | * @noreturn |
| 129 | */ |
| 130 | forward cshop_menu_opened(id, item) |
| 131 | |
| 132 | /** |
| 133 | * Plays the error sound on a player. |
| 134 | * |
| 135 | * @param id Player's index. |
| 136 | * @noreturn |
| 137 | */ |
| 138 | native cshop_error_sound(id) |
| 139 | #define cshopErrorSound cshop_error_sound |
| 140 | |
| 141 | /** |
| 142 | * Gets the total number of loaded items. |
| 143 | * |
| 144 | * @return Total number of loaded items. |
| 145 | */ |
| 146 | native cshop_total_items() |
| 147 | #define cshopTotalItems cshop_total_items |
| 148 | |
| 149 | /** |
| 150 | * Give/take points to/from a player. |
| 151 | * |
| 152 | * @param id Player's index. |
| 153 | * @param points Amount of points. |
| 154 | * @noreturn |
| 155 | */ |
| 156 | native cshop_give_points(id, points) |
| 157 | #define cshopGivePoints cshop_give_points |
| 158 | |
| 159 | /** |
| 160 | * Return player points. |
| 161 | * |
| 162 | * @param id Player's index. |
| 163 | * @return Player's points. |
| 164 | */ |
| 165 | native cshop_get_points(id) |
| 166 | #define cshopGetPoints cshop_get_points |
| 167 | |
| 168 | /** |
| 169 | * Gets the plugin prefix. |
| 170 | * |
| 171 | * @param prefix Buffer. |
| 172 | * @param len Max buffer length. |
| 173 | * @noreturn |
| 174 | */ |
| 175 | native cshop_get_prefix(prefix[], len) |
| 176 | |
| 177 | /** |
| 178 | * Tries to open the shop menu. |
| 179 | * |
| 180 | * @param id Player's id. |
| 181 | * @noreturn |
| 182 | */ |
| 183 | native cshop_open(id) |
| 184 | |
| 185 | /** |
| 186 | * Registers an integer setting for a specific item. |
| 187 | * |
| 188 | * @param item Item id. |
| 189 | * @param setting Setting's name. |
| 190 | * @param value Setting's default value. |
| 191 | * @noreturn |
| 192 | */ |
| 193 | native cshop_set_int(item, setting[], value) |
| 194 | |
| 195 | /** |
| 196 | * Registers a float setting for a specific item. |
| 197 | * |
| 198 | * @param item Item id. |
| 199 | * @param setting Setting's name. |
| 200 | * @param value Setting's default value. |
| 201 | * @noreturn |
| 202 | */ |
| 203 | native cshop_set_float(item, setting[], Float:value) |
| 204 | |
| 205 | /** |
| 206 | * Registers a string setting for a specific item. |
| 207 | * |
| 208 | * @param item Item id. |
| 209 | * @param setting Setting's name. |
| 210 | * @param value Setting's default value. |
| 211 | * @noreturn |
| 212 | */ |
| 213 | native cshop_set_string(item, setting[], value[]) |
| 214 | |
| 215 | /** |
| 216 | * Returns an integer value from a specific item's setting. |
| 217 | * |
| 218 | * @param item Item id. |
| 219 | * @param setting Setting's name. |
| 220 | * @return Setting's value. |
| 221 | */ |
| 222 | native cshop_get_int(item, setting[]) |
| 223 | |
| 224 | /** |
| 225 | * Returns a float value from a specific item's setting. |
| 226 | * |
| 227 | * @param item Item id. |
| 228 | * @param setting Setting's name. |
| 229 | * @return Setting's value. |
| 230 | */ |
| 231 | native Float:cshop_get_float(item, setting[]) |
| 232 | |
| 233 | /** |
| 234 | * Returns a string value from a specific item's setting. |
| 235 | * |
| 236 | * @param item Item id. |
| 237 | * @param setting Setting's name. |
| 238 | * @param value Buffer for the value. |
| 239 | * @param len Buffer length. |
| 240 | * @noreturn |
| 241 | */ |
| 242 | native cshop_get_string(item, setting[], value[], len) |
| 243 | |
| 244 | /** |
| 245 | * Returns item's unique id. |
| 246 | * |
| 247 | * @param id Item id (string). |
| 248 | * @return Item id (integer). |
| 249 | */ |
| 250 | native cshop_find_item_by_id(id[]) |
| 251 | |
| 252 | /** |
| 253 | * Returns item data. |
| 254 | * |
| 255 | * @param item Item id. |
| 256 | * @param type Data type. |
| 257 | * @param buffer Buffer to store string data in. |
| 258 | * @param buffer Buffer length. |
| 259 | * @return Integer or float type data. -1 on failure. |
| 260 | */ |
| 261 | native any:cshop_get_item_data(item, any:type, buffer[] = "", len = 0) |
| 262 | #define cshop_get_name(%1,%2,%3) cshop_get_item_data(%1, CSHOP_DATA_NAME, %2, %3) |
| 263 | |
| 264 | /** |
| 265 | * Called before a menu price is set. |
| 266 | * |
| 267 | * @param id Player's index. |
| 268 | * @param ite, Item's id. |
| 269 | * @param price Item's price. |
| 270 | * @noreturn |
| 271 | */ |
| 272 | forward cshop_set_price(id, item, price) |