Initial commit
This commit is contained in:
809
scripting/include/store/store-backend.inc
Normal file
809
scripting/include/store/store-backend.inc
Normal file
@@ -0,0 +1,809 @@
|
||||
#if defined _store_backend_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _store_backend_included
|
||||
|
||||
#define STORE_MAX_NAME_LENGTH 32
|
||||
#define STORE_MAX_DISPLAY_NAME_LENGTH 64
|
||||
#define STORE_MAX_DESCRIPTION_LENGTH 128
|
||||
#define STORE_MAX_TYPE_LENGTH 32
|
||||
#define STORE_MAX_REQUIREPLUGIN_LENGTH 32
|
||||
|
||||
#define STORE_MAX_LOADOUTSLOT_LENGTH 32
|
||||
#define STORE_MAX_LOADOUTGAME_LENGTH 32
|
||||
#define STORE_MAX_LOADOUTCLASS_LENGTH 32
|
||||
|
||||
#define STORE_MAX_ATTRIBUTES_LENGTH 1024
|
||||
|
||||
functag Store_GetItemsCallback public(items[], count, any:data);
|
||||
functag Store_GetUserItemsCallback public(useritems[], bool:equipped[], useritemCount[], count, loadoutId, any:data);
|
||||
|
||||
functag Store_GetCreditsCallback public(credits, any:data);
|
||||
functag Store_GiveCreditsCallback public(accountId, any:data);
|
||||
|
||||
functag Store_BuyItemCallback public(bool:success, any:data);
|
||||
functag Store_EquipItemCallback public(accountId, itemId, loadoutId, any:data);
|
||||
functag Store_UseItemCallback public(accountId, itemId, any:data);
|
||||
functag Store_GetUserItemCountCallback public(count, any:data);
|
||||
|
||||
forward Store_OnDatabaseInitialized();
|
||||
|
||||
forward Store_OnReloadItems();
|
||||
forward Store_OnReloadItemsPost();
|
||||
|
||||
enum Store_AquireMethod
|
||||
{
|
||||
Store_Shop,
|
||||
Store_Trade,
|
||||
Store_Gift,
|
||||
Store_Admin,
|
||||
Store_Web,
|
||||
Store_Unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a player in the database:
|
||||
*
|
||||
* - If the player is already in the database, his name will be updated according
|
||||
* to the 'name' parameter provided.
|
||||
*
|
||||
* - If the player is not in the database (for example, a new player who just joined
|
||||
* the server for the first time), he will be added using the account ID and name
|
||||
* provided.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param name The name of the player.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_Register(accountId, const String:name[] = "");
|
||||
|
||||
/**
|
||||
* Registers a player in the database, provided his client index only.
|
||||
*
|
||||
* This method converts the client index provided to an account id, retrieves
|
||||
* the player's name, and calls Store_Register using that information.
|
||||
*
|
||||
* The logic of registering a player is explained in the Store_Register documentation.
|
||||
*
|
||||
* The store-core module calls this method every time a player joins the server.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param client Client index.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_RegisterClient(client);
|
||||
|
||||
/**
|
||||
* Retrieves all item categories from the database.
|
||||
*
|
||||
* The store-backend module builds a cache of the categories retrieved the first time
|
||||
* this method is called, for faster access the next time it's called.
|
||||
*
|
||||
* You can set the loadFromCache parameter of this method to false to retrieve categories
|
||||
* from the database and not from the cache.
|
||||
*
|
||||
* The store-core module calls this method when it is loaded to build a cache of
|
||||
* categories.
|
||||
*
|
||||
* It also provides the store_reloaditems command to reload items and categories
|
||||
* from the database.
|
||||
*
|
||||
* To use this method, you can provide a callback for when the categories are loaded.
|
||||
* The callback will provide an array of the categories' IDs. You can then loop the array,
|
||||
* and find info about each category using the Store_GetCategory* methods.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* Store_GetCategories(OnCategoriesLoaded);
|
||||
*
|
||||
* public OnCategoriesLoaded(categories[], count, any:data)
|
||||
* {
|
||||
* for (new category = 0; category < count; category++)
|
||||
* {
|
||||
* decl String:displayName[32];
|
||||
* Store_GetCategoryDisplayName(categories[category], displayName, sizeof(displayName));
|
||||
*
|
||||
* PrintToServer(displayName);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param callback A callback which will be called when the categories are loaded.
|
||||
* @param loadFromCache Whether to load categories from cache. If false, the method will
|
||||
* query the database and rebuild its cache.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetCategories(Store_GetItemsCallback:callback = Store_GetItemsCallback:INVALID_HANDLE, bool:loadFromCache = true, any:data = 0);
|
||||
|
||||
/**
|
||||
* Retrieves a category's display name by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all categories.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param displayName Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetCategoryDisplayName(id, String:displayName[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves a category's description by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all categories.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param description Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetCategoryDescription(id, String:description[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves the plugin name that is required for a specific category.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all categories.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param pluginRequired Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetCategoryPluginRequired(id, String:pluginRequired[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves items from the database.
|
||||
*
|
||||
* The store-backend module builds a cache of the items retrieved the first time
|
||||
* this method is called, for faster access the next time it's called.
|
||||
*
|
||||
* You can set the loadFromCache parameter of this method to false to retrieve categories
|
||||
* from the database and not from the cache.
|
||||
*
|
||||
* You can use the filter parameter to filter items returned by the following properties:
|
||||
* - category_id (cell)
|
||||
* - is_buyable (cell)
|
||||
* - is_tradeable (cell)
|
||||
* - is_refundable (cell)
|
||||
* - type (string)
|
||||
*
|
||||
* To use it, set it to a trie with some or all of the above properties.
|
||||
* IMPORTANT: You are *not* resposible for closing the filter trie's handle,
|
||||
* the store-backend module is.
|
||||
*
|
||||
* The store-backend module calls this method when it is loaded to build a cache of
|
||||
* categories. It also provides the store_reloaditems command to reload items and categories
|
||||
* from the database.
|
||||
*
|
||||
* To use this method, you can provide a callback for when the items are loaded.
|
||||
* The callback will provide an array of the items' IDs. You can then loop the array,
|
||||
* and find info about each item using the Store_GetItem* methods.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* new Handle:filter = CreateTrie();
|
||||
* SetTrieString(filter, "type", "equipment");
|
||||
* SetTrieValue(filter, "is_buyable", 1);
|
||||
*
|
||||
* Store_GetItems(filter, OnItemsLoaded);
|
||||
*
|
||||
* public OnItemsLoaded(items[], count, any:data)
|
||||
* {
|
||||
* for (new item = 0; item < count; item++)
|
||||
* {
|
||||
* decl String:displayName[32];
|
||||
* Store_GetItemDisplayName(items[item], displayName, sizeof(displayName));
|
||||
*
|
||||
* PrintToServer(displayName);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param filter A trie which will be used to filter the loadouts returned.
|
||||
* @param callback A callback which will be called when the items are loaded.
|
||||
* @param loadFromCache Whether to load items from cache. If false, the method will
|
||||
* query the database and rebuild its cache.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetItems(Handle:filter = INVALID_HANDLE, Store_GetItemsCallback:callback = Store_GetItemsCallback:INVALID_HANDLE, bool:loadFromCache = true, any:data = 0);
|
||||
|
||||
/**
|
||||
* Retrieves an item's name by its ID.
|
||||
*
|
||||
* The difference between an item's name and an item's display name is
|
||||
* that its name is a lowered-case unique identifier of it, and
|
||||
* its display name is what actually displayed in the store UI (which
|
||||
* doesnt has to be unique).
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param name Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetItemName(id, String:name[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves an item's display name by its ID.
|
||||
*
|
||||
* The difference between an item's name and an item's display name is
|
||||
* that its name is a lowered-case unique identifier of it, and
|
||||
* its display name is what actually displayed in the store UI (which
|
||||
* doesnt has to be unique).
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param displayName Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetItemDisplayName(id, String:displayName[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves an item's description by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param description Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetItemDescription(id, String:description[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves an item's type by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param type Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetItemType(id, String:type[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves an item's loadout slot by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param loadoutSlot Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetItemLoadoutSlot(id, String:loadoutSlot[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves an item's price by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
*
|
||||
* @return The item's price.
|
||||
*/
|
||||
native Store_GetItemPrice(id);
|
||||
|
||||
/**
|
||||
* Retrieves an item's category by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
*
|
||||
* @return The item's category ID.
|
||||
*/
|
||||
native Store_GetItemCategory(id);
|
||||
|
||||
/**
|
||||
* Determines whether or not an item is buyable.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Item's ID.
|
||||
*
|
||||
* @return True if buyable, false otherwise.
|
||||
*/
|
||||
native bool:Store_IsItemBuyable(id);
|
||||
|
||||
/**
|
||||
* Determines whether or not an item is tradeable.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Item's ID.
|
||||
*
|
||||
* @return True if tradeable, false otherwise.
|
||||
*/
|
||||
native bool:Store_IsItemTradeable(id);
|
||||
|
||||
/**
|
||||
* Determines whether or not an item is refundable.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all items.
|
||||
*
|
||||
* @param id Item's ID.
|
||||
*
|
||||
* @return True if refundable, false otherwise.
|
||||
*/
|
||||
native bool:Store_IsItemRefundable(id);
|
||||
|
||||
/**
|
||||
* Retrieves loadouts from the database.
|
||||
*
|
||||
* The store-backend module builds a cache of the loadouts retrieved the first time
|
||||
* this method is called, for faster access the next time it's called.
|
||||
*
|
||||
* You can set the loadFromCache parameter of this method to false to retrieve loadouts
|
||||
* from the database and not from the cache.
|
||||
*
|
||||
* You can use the filter parameter to filter loadouts returned by the following properties:
|
||||
* - game (string)
|
||||
* - team (cell)
|
||||
* - class (string)
|
||||
*
|
||||
* To use it, set it to a trie with some or all of the above properties.
|
||||
* IMPORTANT: You are *not* resposible for closing the filter trie's handle,
|
||||
* the store-backend module is.
|
||||
*
|
||||
* The store-loadout module calls this method when it is loaded to build a cache of
|
||||
* loadouts.
|
||||
*
|
||||
* To use this method, you can provide a callback for when the items are loaded.
|
||||
* The callback will provide an array of the loadouts' IDs. You can then loop the array,
|
||||
* and find info about each item using the Store_GetLoadout* methods.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* new Handle:filter = CreateTrie();
|
||||
* SetTrieString(filter, "game", "tf");
|
||||
* SetTrieValue(filter, "team", GetClientTeam(client));
|
||||
*
|
||||
* Store_GetLoadouts(filter, OnLoadoutsLoaded);
|
||||
*
|
||||
* public OnLoadoutsLoaded(loadouts[], count, any:data)
|
||||
* {
|
||||
* for (new loadout = 0; loadout < count; loadout++)
|
||||
* {
|
||||
* decl String:displayName[32];
|
||||
* Store_GetLoadoutDisplayName(loadouts[loadout], displayName, sizeof(displayName));
|
||||
*
|
||||
* PrintToServer(displayName);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param filter A trie which will be used to filter the loadouts returned.
|
||||
* @param callback A callback which will be called when the items are loaded.
|
||||
* @param loadFromCache Whether to load items from cache. If false, the method will
|
||||
* query the database and rebuild its cache.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetLoadouts(Handle:filter = INVALID_HANDLE, Store_GetItemsCallback:callback, bool:loadFromCache = true, any:data = 0);
|
||||
|
||||
/**
|
||||
* Retrieves a loadout's display name by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all loadouts.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param displayName Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetLoadoutDisplayName(id, String:displayName[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves a loadout's game by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all loadouts.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param game Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetLoadoutGame(id, String:game[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves a loadout's class by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all loadouts.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
* @param class Buffer to store string in.
|
||||
* @param maxlength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetLoadoutClass(id, String:class[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves a loadout's team by its ID.
|
||||
*
|
||||
* IMPORTANT: This method only works if the store-backend module has a cache
|
||||
* of all loadouts.
|
||||
*
|
||||
* @param id Category's ID.
|
||||
*
|
||||
* @return The loadout's team.
|
||||
*/
|
||||
native Store_GetLoadoutTeam(id);
|
||||
|
||||
/**
|
||||
* Retrieves items of a specific player in a specific category.
|
||||
*
|
||||
* To use this method, you can provide a callback for when the items are loaded.
|
||||
* The callback will provide an array of the items' IDs. You can then loop the array,
|
||||
* and find info about each item using the Store_GetItem* methods.
|
||||
*
|
||||
* You can use the filter parameter to filter items returned by the following properties:
|
||||
* - category_id (cell)
|
||||
* - is_buyable (cell)
|
||||
* - is_tradeable (cell)
|
||||
* - is_refundable (cell)
|
||||
* - type (string)
|
||||
*
|
||||
* To use it, set it to a trie with some or all of the above properties.
|
||||
* IMPORTANT: You are *not* resposible for closing the filter trie's handle,
|
||||
* the store-backend module is.
|
||||
*
|
||||
* The items returned by this method are grouped by the item's name. That means that
|
||||
* if a player has multiple items with the same name (the unique identifier of the item, NOT its
|
||||
* display name), then the array will only have one element of that item.
|
||||
*
|
||||
* To determine how many items the player has of the same name, the callback provides the
|
||||
* itemCount[] array.
|
||||
*
|
||||
* To deremine whether or not an item is equipped in the loadout specified, the callback
|
||||
* provides the equipped[] array.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* new Handle:filter = CreateTrie();
|
||||
* SetTrieString(filter, "type", "equipment");
|
||||
* SetTrieValue(filter, "is_refundable", 1);
|
||||
*
|
||||
* Store_GetUserItems(filter,
|
||||
* Store_GetClientAccountID(client),
|
||||
* Store_GetClientLoadout(client),
|
||||
* GetUserItemsCallback);
|
||||
*
|
||||
* public GetUserItemsCallback(items[], bool:equipped[], itemCount[], count, loadoutId, any:data)
|
||||
* {
|
||||
* PrintToServer("Player's Inventory");
|
||||
*
|
||||
* for (new item = 0; item < count; item++)
|
||||
* {
|
||||
* decl String:displayName[32];
|
||||
* Store_GetItemDisplayName(items[item], displayName, sizeof(displayName));
|
||||
*
|
||||
* PrintToServer("Item: %s, Equipped: %b, Count: %d", displayName, equipped[item], itemCount[item]);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* For a full example of a usage of this method, see the store-inventory module.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param filter A trie which will be used to filter the loadouts returned.
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param loadoutId The loadout which will be used to determine whether an item is equipped or not.
|
||||
* @param callback A callback which will be called when the items are loaded.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetUserItems(Handle:filter, accountId, loadoutId, Store_GetUserItemsCallback:callback, any:data = 0);
|
||||
|
||||
/**
|
||||
* Retrieves the amount of the same item a user has.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param itemName The name of the item.
|
||||
* @param callback A callback which will be called when the items are loaded.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetUserItemCount(accountId, const String:itemName[], Store_GetUserItemCountCallback:callback, any:data = 0);
|
||||
|
||||
/**
|
||||
* Retrieves the amount of credits that a player currently has.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param callback A callback which will be called when the credits amount is loaded.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetCredits(accountId, Store_GetCreditsCallback:callback, any:data = 0);
|
||||
|
||||
/**
|
||||
* Gives a player a specific amount of credits.
|
||||
*
|
||||
* You can also set the credits parameter to a negative value to take credits
|
||||
* from the player.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param credits The amount of credits to give to the player.
|
||||
* @param callback A callback which will be called when the operation is finished.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GiveCredits(accountId, credits, Store_GiveCreditsCallback:callback = Store_GiveCreditsCallback:INVALID_HANDLE, any:data = 0);
|
||||
|
||||
/**
|
||||
* Gives multiple players a specific amount of credits.
|
||||
*
|
||||
* You can also set the credits parameter to a negative value to take credits
|
||||
* from the players.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountIds The account IDs of the players, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param accountIdsLength Players count.
|
||||
* @param credits The amount of credits to give to the players.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GiveCreditsToUsers(accountIds[], accountIdsLength, credits);
|
||||
|
||||
/**
|
||||
* Gives multiple players different amounts of credits.
|
||||
*
|
||||
* You can also set the credits parameter to a negative value to take credits
|
||||
* from the players.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountIds The account IDs of the players, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param accountIdsLength Players count.
|
||||
* @param credits Amount of credits per player.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GiveDifferentCreditsToUsers(accountIds[], accountIdsLength, credits[]);
|
||||
|
||||
/**
|
||||
* Gives player an item.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param itemId The ID of the item to give to the player.
|
||||
* @param aquireMethod
|
||||
* @param callback A callback which will be called when the operation is finished.
|
||||
* @param plugin The plugin owner of the callback.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GiveItem(accountId, itemId, Store_AquireMethod:aquireMethod = Store_Unknown, Store_GiveCreditsCallback:callback = Store_GiveCreditsCallback:INVALID_HANDLE, any:data = 0);
|
||||
|
||||
/**
|
||||
* Buys an item for a player, using his credits.
|
||||
*
|
||||
* To determine whether or not the process of buying that item was successful,
|
||||
* use the 'success' parameter that is provided by the callback.
|
||||
* A false value of that parameter probably means that the user didn't have enough credits.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param itemId The ID of the item to buy.
|
||||
* @param callback A callback which will be called when the operation is finished.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_BuyItem(accountId, itemId, Store_BuyItemCallback:callback, any:data = 0);
|
||||
|
||||
/**
|
||||
* Removes one copy of an item from a player's inventory.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param itemId The ID of the item to use.
|
||||
* @param callback A callback which will be called when the operation is finished.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_RemoveUserItem(accountId, itemId, Store_UseItemCallback:callback, any:data = 0);
|
||||
|
||||
/**
|
||||
* Changes item equipped state in a specific loadout for a player.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param itemId The ID of the item to change equipped state to.
|
||||
* @param loadoutId The loadout to equip the item in.
|
||||
* @param isEquipped Whether or not the item is equipped in the specified loadout.
|
||||
* @param callback A callback which will be called when the operation is finished.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_SetItemEquippedState(accountId, itemId, loadoutId, bool:isEquipped, Store_EquipItemCallback:callback, any:data = 0);
|
||||
|
||||
/**
|
||||
* Retrieves equipped items of a specific player in a specific type.
|
||||
*
|
||||
* To use this method, you can provide a callback for when the items are loaded.
|
||||
* The callback will provide an array of the items' IDs. You can then loop the array,
|
||||
* and find info about each item using the Store_GetItem* methods.
|
||||
*
|
||||
* The items returned by this method are grouped by the item's name. That means that
|
||||
* if a player has multiple items with the same name (the unique identifier of the item, NOT its
|
||||
* display name), then the array will only have one element of that item.
|
||||
*
|
||||
* To determine how many items the player has of the same name, the callback provides the
|
||||
* itemCount[] array.
|
||||
*
|
||||
* To deremine whether or not an item is equipped in the loadout specified, the callback
|
||||
* provides the equipped[] array.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* Store_GetUserItems(Store_GetClientAccountID(client),
|
||||
* categoryId,
|
||||
* Store_GetClientLoadout(client),
|
||||
* GetUserItemsCallback);
|
||||
*
|
||||
* public GetUserItemsCallback(items[], bool:equipped[], itemCount[], count, loadoutId, any:data)
|
||||
* {
|
||||
* PrintToServer("Player's Inventory");
|
||||
*
|
||||
* for (new item = 0; item < count; item++)
|
||||
* {
|
||||
* decl String:displayName[32];
|
||||
* Store_GetItemDisplayName(items[item], displayName, sizeof(displayName));
|
||||
*
|
||||
* PrintToServer("Item: %s, Equipped: %b, Count: %d", displayName, equipped[item], itemCount[item]);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* For a full example of a usage of this method, see the store-inventory module.
|
||||
*
|
||||
* As with all other store-backend methods, this method is completely asynchronous.
|
||||
*
|
||||
* @param accountId The account ID of the player, use Store_GetClientAccountID to convert a client index to account ID.
|
||||
* @param type The category of the items you want to retrieve.
|
||||
* @param loadoutId The loadout which will be used to determine whether an item is equipped or not.
|
||||
* @param callback A callback which will be called when the items are loaded.
|
||||
* @param data Extra data value to pass to the callback.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetEquippedItemsByType(accountId, const String:type[], loadoutId, Store_GetItemsCallback:callback, any:data = 0);
|
||||
|
||||
/**
|
||||
* Query the database for items and categories, so that
|
||||
* the store-backend module will have a cache of them.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_ReloadItemCache();
|
||||
|
||||
stock Store_GetAccountIDFromAuthString(String:authString[])
|
||||
{
|
||||
decl String:toks[3][16];
|
||||
ExplodeString(authString, ":", toks, sizeof(toks), sizeof(toks[]));
|
||||
|
||||
new odd = StringToInt(toks[1]);
|
||||
new halfAID = StringToInt(toks[2]);
|
||||
|
||||
return (halfAID*2) + odd;
|
||||
}
|
||||
|
||||
stock Store_GetClientAccountID(client)
|
||||
{
|
||||
decl String:buffer[32];
|
||||
GetClientAuthString(client, buffer, sizeof(buffer));
|
||||
|
||||
return Store_GetAccountIDFromAuthString(buffer);
|
||||
}
|
||||
|
||||
public SharedPlugin:__pl_store_backend =
|
||||
{
|
||||
name = "store-backend",
|
||||
file = "store-backend.smx",
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined REQUIRE_PLUGIN
|
||||
public __pl_store_backend_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("Store_Register");
|
||||
MarkNativeAsOptional("Store_RegisterClient");
|
||||
|
||||
MarkNativeAsOptional("Store_GetCategories");
|
||||
MarkNativeAsOptional("Store_GetCategoryDisplayName");
|
||||
MarkNativeAsOptional("Store_GetCategoryDescription");
|
||||
|
||||
MarkNativeAsOptional("Store_GetItems");
|
||||
MarkNativeAsOptional("Store_GetItemDisplayName");
|
||||
MarkNativeAsOptional("Store_GetItemDescription");
|
||||
MarkNativeAsOptional("Store_GetItemType");
|
||||
MarkNativeAsOptional("Store_GetItemLoadoutSlot");
|
||||
MarkNativeAsOptional("Store_GetItemPrice");
|
||||
MarkNativeAsOptional("Store_GetItemAttributes");
|
||||
MarkNativeAsOptional("Store_IsItemTradeable");
|
||||
MarkNativeAsOptional("Store_IsItemBuyable");
|
||||
MarkNativeAsOptional("Store_IsItemRefundable");
|
||||
|
||||
MarkNativeAsOptional("Store_GetUserItems");
|
||||
MarkNativeAsOptional("Store_GetUserItemCount");
|
||||
MarkNativeAsOptional("Store_GetCredits");
|
||||
|
||||
MarkNativeAsOptional("Store_GiveCredits");
|
||||
MarkNativeAsOptional("Store_GiveCreditsToUsers");
|
||||
MarkNativeAsOptional("Store_GiveDifferentCreditsToUsers");
|
||||
|
||||
MarkNativeAsOptional("Store_BuyItem");
|
||||
MarkNativeAsOptional("Store_RemoveUserItem");
|
||||
|
||||
MarkNativeAsOptional("Store_SetItemEquippedState");
|
||||
MarkNativeAsOptional("Store_GetEquippedItemsByType");
|
||||
|
||||
MarkNativeAsOptional("Store_ReloadItemCache");
|
||||
}
|
||||
#endif
|
64
scripting/include/store/store-core.inc
Normal file
64
scripting/include/store/store-core.inc
Normal file
@@ -0,0 +1,64 @@
|
||||
#if defined _store_core_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _store_core_included
|
||||
|
||||
#define STORE_VERSION "1.1-alpha"
|
||||
#define STORE_PREFIX "\x04[Store] \x01"
|
||||
|
||||
funcenum Store_MenuItemClickCallback
|
||||
{
|
||||
public(client, const String:value[])
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the main menu for a player.
|
||||
*
|
||||
* @param client Client Index
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_OpenMainMenu(client);
|
||||
|
||||
/**
|
||||
* Adds an item to the main menu.
|
||||
*
|
||||
* @param displayName The text of the item, as it is shown to the player.
|
||||
* @param description A short description of the item.
|
||||
* @param value Item information string that will be sent to the callback.
|
||||
* @param callback Callback to the item click event.
|
||||
* @param order Preferred position of the item in the menu.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_AddMainMenuItem(const String:displayName[], const String:description[] = "", const String:value[] = "", Store_MenuItemClickCallback:callback, order = 32);
|
||||
|
||||
/**
|
||||
* Retrieve currency name as it is defined in the core condig file.
|
||||
*
|
||||
* @param currencyName Buffer to store the currency name in.
|
||||
* @param maxLength Maximum length of string buffer.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_GetCurrencyName(String:currencyName[], maxLength);
|
||||
|
||||
public SharedPlugin:__pl_store =
|
||||
{
|
||||
name = "store",
|
||||
file = "store-core.smx",
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined REQUIRE_PLUGIN
|
||||
public __pl_store_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("Store_OpenMainMenu");
|
||||
MarkNativeAsOptional("Store_AddMainMenuItem");
|
||||
MarkNativeAsOptional("Store_GetCurrencyName");
|
||||
}
|
||||
#endif
|
99
scripting/include/store/store-inventory.inc
Normal file
99
scripting/include/store/store-inventory.inc
Normal file
@@ -0,0 +1,99 @@
|
||||
#if defined _store_inventory_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _store_inventory_included
|
||||
|
||||
enum Store_ItemUseAction
|
||||
{
|
||||
Store_EquipItem,
|
||||
Store_UnequipItem,
|
||||
Store_DeleteItem,
|
||||
Store_DoNothing
|
||||
}
|
||||
|
||||
functag Store_ItemGetAttributesCallback public(const String:itemName[], const String:attrs[]);
|
||||
functag Store_ItemUseCallback Store_ItemUseAction:public(client, itemId, bool:equipped);
|
||||
|
||||
/**
|
||||
* Opens the inventory menu for a client.
|
||||
*
|
||||
* @param client Client index.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_OpenInventory(client);
|
||||
|
||||
/**
|
||||
* Opens the inventory menu for a client in a specific category.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param categoryId The category that you want to open.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_OpenInventoryCategory(client, categoryId);
|
||||
|
||||
/**
|
||||
* Registers an item type.
|
||||
*
|
||||
* A type of an item defines its behaviour. Once you register a type,
|
||||
* the store will provide two callbacks for you:
|
||||
* - Use callback: called when a player selects your item in his inventory.
|
||||
* - Attributes callback: called when the store loads the attributes of your item (optional).
|
||||
*
|
||||
* It is recommended that each plugin registers *one* item type.
|
||||
*
|
||||
* @param type Item type unique identifer - maximum 32 characters, no whitespaces, lower case only.
|
||||
* @param useCallback Called when a player selects your item in his inventory.
|
||||
* @param attrsCallback Called when the store loads the attributes of your item.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_RegisterItemType(const String:type[], Store_ItemUseCallback:useCallback, Store_ItemGetAttributesCallback:attrsCallback = Store_ItemGetAttributesCallback:0);
|
||||
|
||||
/**
|
||||
* Determines whether or not a specific item type string is registered.
|
||||
*
|
||||
* @param type Item type unique identifer.
|
||||
*
|
||||
* @return True if registered, false otherwise.
|
||||
*/
|
||||
native bool:Store_IsItemTypeRegistered(const String:type[]);
|
||||
|
||||
/**
|
||||
* Calls item type's attributes callback.
|
||||
*
|
||||
* This method is designed for store-database, that loads attributes from the database.
|
||||
* It shouldn't be used anywhere else.
|
||||
*
|
||||
* @param type Item type unique identifer.
|
||||
* @param itemName
|
||||
* @param attrs
|
||||
*
|
||||
* @return True if successful, false otherwise.
|
||||
*/
|
||||
native bool:Store_CallItemAttrsCallback(const String:type[], const String:itemName[], const String:attrs[]);
|
||||
|
||||
public SharedPlugin:__pl_store_inventory =
|
||||
{
|
||||
name = "store-inventory",
|
||||
file = "store-inventory.smx",
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined REQUIRE_PLUGIN
|
||||
public __pl_store_inventory_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("Store_OpenInventory");
|
||||
MarkNativeAsOptional("Store_OpenInventoryCategory");
|
||||
|
||||
MarkNativeAsOptional("Store_RegisterItemType");
|
||||
MarkNativeAsOptional("Store_IsItemTypeRegistered");
|
||||
|
||||
// MarkNativeAsOptional("Store_CallItemAttrsCallback");
|
||||
}
|
||||
#endif
|
43
scripting/include/store/store-loadout.inc
Normal file
43
scripting/include/store/store-loadout.inc
Normal file
@@ -0,0 +1,43 @@
|
||||
#if defined _store_loadout_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _store_loadout_included
|
||||
|
||||
forward Store_OnClientLoadoutChanged(client);
|
||||
|
||||
/**
|
||||
* Opens the loadout menu for a client.
|
||||
*
|
||||
* @param client Client index.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_OpenLoadoutMenu(client);
|
||||
|
||||
/**
|
||||
* Gets client current loadout.
|
||||
*
|
||||
* @param client Client index.
|
||||
*
|
||||
* @return Loadout index.
|
||||
*/
|
||||
native Store_GetClientLoadout(client);
|
||||
|
||||
public SharedPlugin:__pl_loadout_store =
|
||||
{
|
||||
name = "store-loadout",
|
||||
file = "store-loadout.smx",
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined REQUIRE_PLUGIN
|
||||
public __pl_store_loadout_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("Store_OpenLoadoutMenu");
|
||||
MarkNativeAsOptional("Store_GetClientLoadout");
|
||||
}
|
||||
#endif
|
46
scripting/include/store/store-loadouts.inc
Normal file
46
scripting/include/store/store-loadouts.inc
Normal file
@@ -0,0 +1,46 @@
|
||||
#if defined _store_loadouts_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _store_loadouts_included
|
||||
|
||||
//Forwards
|
||||
forward void Store_OnClientLoadoutChanged(int client);
|
||||
|
||||
/**
|
||||
* Opens the loadout menu for a client.
|
||||
*
|
||||
* @param client Client index.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native void Store_OpenLoadoutMenu(int client);
|
||||
|
||||
/**
|
||||
* Gets client current loadout.
|
||||
*
|
||||
* @param client Client index.
|
||||
*
|
||||
* @return Loadout index.
|
||||
*/
|
||||
native int Store_GetClientCurrentLoadout(int client);
|
||||
native int Store_GetClientLoadout(int client);
|
||||
|
||||
public SharedPlugin __pl_store_loadouts =
|
||||
{
|
||||
name = "store-loadouts",
|
||||
file = "store-loadouts.smx",
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined REQUIRE_PLUGIN
|
||||
public __pl_store_loadouts_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("Store_OpenLoadoutMenu");
|
||||
MarkNativeAsOptional("Store_GetClientCurrentLoadout");
|
||||
MarkNativeAsOptional("Store_GetClientLoadout");
|
||||
}
|
||||
#endif
|
116
scripting/include/store/store-logging.inc
Normal file
116
scripting/include/store/store-logging.inc
Normal file
@@ -0,0 +1,116 @@
|
||||
#if defined _store_logging_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _store_logging_included
|
||||
|
||||
/**
|
||||
* Logging levels
|
||||
*/
|
||||
enum Store_LogLevel
|
||||
{
|
||||
Store_LogLevelNone = 0, /**< Logging disabled */
|
||||
Store_LogLevelError, /**< Log only errors */
|
||||
Store_LogLevelWarning, /**< Log errors and warnings */
|
||||
Store_LogLevelInfo, /**< Log errors, warnings and info messages */
|
||||
Store_LogLevelDebug, /**< Log errors, warnings, info and debug messages */
|
||||
Store_LogLevelTrace /**< Log errors, warnings, info, debug and trace messages */
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the current logging level.
|
||||
*
|
||||
* @return Current logging level
|
||||
*/
|
||||
native Store_LogLevel:Store_GetLogLevel();
|
||||
|
||||
/**
|
||||
* Logs a message to the Store log file. Depending on the log level provided, this is equivalent
|
||||
* to calling any of the logging functions below (Store_LogError(), Store_LogWarning(), etc).
|
||||
*
|
||||
* @param log_level The severity of the message being logged.
|
||||
* @param format A format string. See http://wiki.alliedmods.net/Format_Class_Functions_(SourceMod_Scripting)
|
||||
* @param ... Variable number of format parameters.
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_Log(Store_LogLevel:log_level, const String:format[] , any:...);
|
||||
|
||||
/**
|
||||
* Logs an error message to the Store log file. Error logs are either fatal unrecoverable errors
|
||||
* or notifications about major problems that significantly hinder a plugin's functionality. For
|
||||
* example, not being able to connect to the Store service.
|
||||
*
|
||||
* @param format A format string. See http://wiki.alliedmods.net/Format_Class_Functions_(SourceMod_Scripting)
|
||||
* @param ... Variable number of format parameters.
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_LogError(const String:format[] , any:...);
|
||||
|
||||
/**
|
||||
* Logs a warning message to the Store log file. Warnings should notify the server operator of
|
||||
* malfunctions that are not critical to the plugin's operation but do require attention. For
|
||||
* example, too much text disaplyed in a menu (and truncated).
|
||||
*
|
||||
* @param format A format string. See http://wiki.alliedmods.net/Format_Class_Functions_(SourceMod_Scripting)
|
||||
* @param ... Variable number of format parameters.
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_LogWarning(const String:format[] , any:...);
|
||||
|
||||
/**
|
||||
* Logs an info message to the Store log file. Info messages should enable the server operator
|
||||
* to drill in and track activity that occured on his server in details. For example, client
|
||||
* dis/connections, client billing operations, awards granted to clients, etc.
|
||||
*
|
||||
* @param format A format string. See http://wiki.alliedmods.net/Format_Class_Functions_(SourceMod_Scripting)
|
||||
* @param ... Variable number of format parameters.
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_LogInfo(const String:format[] , any:...);
|
||||
|
||||
/**
|
||||
* Logs a debug message to the Store log file. Debug logs are low-level messages primarily used
|
||||
* by developers to debug the execution of their plugins. Debug logs typically describe the
|
||||
* parameters and outcome of some algorithmic computation, or some event that occured. Debug logs
|
||||
* may generate large volumes of data.
|
||||
*
|
||||
* @param format A format string. See http://wiki.alliedmods.net/Format_Class_Functions_(SourceMod_Scripting)
|
||||
* @param ... Variable number of format parameters.
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_LogDebug(const String:format[] , any:...);
|
||||
|
||||
/**
|
||||
* Logs a particularly low-level trace message to the Store log file. Trace logs are low-level
|
||||
* messages primarily used by developers to trace the execution of their plugins. They typically
|
||||
* describe a position in the code and the value of surrounding parameters. Trace logs WILL generate
|
||||
* large volumes of data quickly.
|
||||
*
|
||||
* @param format A format string. See http://wiki.alliedmods.net/Format_Class_Functions_(SourceMod_Scripting)
|
||||
* @param ... Variable number of format parameters.
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_LogTrace(const String:format[] , any:...);
|
||||
|
||||
public SharedPlugin:__pl_store_logging =
|
||||
{
|
||||
name = "store-logging",
|
||||
file = "store-logging.smx",
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined REQUIRE_PLUGIN
|
||||
public __pl_store_logging_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("Store_GetLogLevel");
|
||||
MarkNativeAsOptional("Store_Log");
|
||||
MarkNativeAsOptional("Store_LogError");
|
||||
MarkNativeAsOptional("Store_LogWarning");
|
||||
MarkNativeAsOptional("Store_LogInfo");
|
||||
MarkNativeAsOptional("Store_LogDebug");
|
||||
MarkNativeAsOptional("Store_LogDebug2");
|
||||
}
|
||||
#endif
|
42
scripting/include/store/store-shop.inc
Normal file
42
scripting/include/store/store-shop.inc
Normal file
@@ -0,0 +1,42 @@
|
||||
#if defined _store_shop_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _store_shop_included
|
||||
|
||||
/**
|
||||
* Opens the shop menu for a client.
|
||||
*
|
||||
* @param client Client index.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_OpenShop(client);
|
||||
|
||||
/**
|
||||
* Opens the shop menu for a client in a specific category.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param categoryId The category that you want to open.
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native Store_OpenShopCategory(client, categoryId);
|
||||
|
||||
public SharedPlugin:__pl_store_shop =
|
||||
{
|
||||
name = "store-shop",
|
||||
file = "store-shop.smx",
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined REQUIRE_PLUGIN
|
||||
public __pl_store_shop_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("Store_OpenShop");
|
||||
MarkNativeAsOptional("Store_OpenShopCategory");
|
||||
}
|
||||
#endif
|
142
scripting/include/store/store-stocks.inc
Normal file
142
scripting/include/store/store-stocks.inc
Normal file
@@ -0,0 +1,142 @@
|
||||
#if defined _store_stocks_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _store_stocks_included
|
||||
|
||||
//////////////////////////////////////////////
|
||||
//General Stocks for the Store system to use. Some are from SMLib, some are from other places.
|
||||
|
||||
#define SIZE_OF_INT 2147483647 // without 0
|
||||
|
||||
//From SMLib
|
||||
stock int String_GetRandom(char[] buffer, int size, int length = 32, const char[] chrs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234556789")
|
||||
{
|
||||
int random; int len;
|
||||
size--;
|
||||
|
||||
if (chrs[0] != '\0')
|
||||
{
|
||||
len = strlen(chrs) - 1;
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
while (n < length && n < size)
|
||||
{
|
||||
if (chrs[0] == '\0')
|
||||
{
|
||||
random = Math_GetRandomInt(33, 126);
|
||||
buffer[n] = random;
|
||||
}
|
||||
else
|
||||
{
|
||||
random = Math_GetRandomInt(0, len);
|
||||
buffer[n] = chrs[random];
|
||||
}
|
||||
|
||||
n++;
|
||||
}
|
||||
|
||||
buffer[length] = '\0';
|
||||
}
|
||||
|
||||
//From SMLib
|
||||
stock Math_GetRandomInt(min, max)
|
||||
{
|
||||
new random = GetURandomInt();
|
||||
|
||||
if (random == 0) {
|
||||
random++;
|
||||
}
|
||||
|
||||
return RoundToCeil(float(random) / (float(SIZE_OF_INT) / float(max - min + 1))) + min - 1;
|
||||
}
|
||||
|
||||
//My own Invention (Drixevel) (Designed for handles)
|
||||
stock bool ClearArray2(Handle hGlobalArray)
|
||||
{
|
||||
if (hGlobalArray != null)
|
||||
{
|
||||
for (int i = 0; i < GetArraySize(hGlobalArray); i++)
|
||||
{
|
||||
Handle hArray = GetArrayCell(hGlobalArray, i);
|
||||
|
||||
if (hArray != null)
|
||||
{
|
||||
CloseHandle(hArray);
|
||||
hArray = null;
|
||||
}
|
||||
}
|
||||
|
||||
ClearArray(hGlobalArray);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Debug Stock... Don't ask why.
|
||||
stock void GenerateDebugPrint(const char[] sFunc = "N/A")
|
||||
{
|
||||
char sName[64];
|
||||
GetPluginFilename(INVALID_HANDLE, sName, sizeof(sName));
|
||||
PrintToServer("Name: %s - Function Call: %s", sName, sFunc);
|
||||
}
|
||||
|
||||
//Because Useful (Kappas all around to KissLick)
|
||||
stock void PushMenuCell(Handle hndl, const char[] id, int data)
|
||||
{
|
||||
char DataString[64];
|
||||
IntToString(data, DataString, sizeof(DataString));
|
||||
AddMenuItem(hndl, id, DataString, ITEMDRAW_IGNORE);
|
||||
}
|
||||
|
||||
stock int GetMenuCell(Handle hndl, const char[] id, int DefaultValue = 0)
|
||||
{
|
||||
int ItemCount = GetMenuItemCount(hndl);
|
||||
char info[64]; char data[64];
|
||||
|
||||
for (int i = 0; i < ItemCount; i++)
|
||||
{
|
||||
GetMenuItem(hndl, i, info, sizeof(info), _, data, sizeof(data));
|
||||
|
||||
if (StrEqual(info, id))
|
||||
{
|
||||
return StringToInt(data);
|
||||
}
|
||||
}
|
||||
|
||||
return DefaultValue;
|
||||
}
|
||||
|
||||
stock bool AddMenuItemFormat(Handle &menu, const char[] info, int style = ITEMDRAW_DEFAULT, const char[] format, any...)
|
||||
{
|
||||
char display[128];
|
||||
VFormat(display, sizeof(display), format, 5);
|
||||
|
||||
return AddMenuItem(menu, info, display, style);
|
||||
}
|
||||
|
||||
stock void PushMenuString(Handle hndl, const char[] id, const char[] data)
|
||||
{
|
||||
AddMenuItem(hndl, id, data, ITEMDRAW_IGNORE);
|
||||
}
|
||||
|
||||
stock bool GetMenuString(Handle hndl, const char[] id, char[] Buffer, int size)
|
||||
{
|
||||
int ItemCount = GetMenuItemCount(hndl);
|
||||
char info[64]; char data[64];
|
||||
|
||||
for (int i = 0; i < ItemCount; i++)
|
||||
{
|
||||
GetMenuItem(hndl, i, info, sizeof(info), _, data, sizeof(data));
|
||||
|
||||
if (StrEqual(info, id))
|
||||
{
|
||||
strcopy(Buffer, size, data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user