[ANY] Money system
1 Attachment(s)
Money system core
This plugin provides the API to operate the money of your clients. It also provides a buy menu that you can populate with buyable items, so you don't have to reinvent the wheel. It was designed to be mod-independent, minimalistic and as customizable as possible. It doesn't have any way to earn money on it's own and doesn't have any way to spend them. It's up to you to code them. The buying process is handled in a fashion similar to console commands. You register item and when client is trying to buy it, a callback you provided earlier is called, so you can bind an item to any code. The money are stored in clientprefs db. Almost everything can be configured via ConVars and almost all outputted text can be changed by simply editing the translation file. You can create submenus inside buy menu and they can be nested allowing you to create very complex hierarchy with many items.
Requirements:
ConVars:- ftz_money_version: The version of money system core. Default: "1.0.0.0".
- ftz_money_cookie_name: The name of the cookie to store money in. Default: "Money".
- ftz_buymenu_title: The title of buy menu. Default: "Buy menu".
- ftz_money_user_get_command_name: The name of the command to check money. Default: "money".
- ftz_buy_command_name: The name of the command to buy items. Default: "buy".
Client commands:
Note: Set respective cvar to empty string to disable. - value of ftz_money_user_get_command_name: Displays the client their money.
- value of ftz_buy_command_name [item alias]: Buys specified item or displays buy menu if no item was specified.
Admin commands:- ftz_getmoney <#userid|name>: Displays the client money.
- ftz_setmoney <#userid|name> <value>: Sets client money.
- ftz_addmoney <#userid|name> <value>: Adds client money.
- ftz_giveitem <#userid|name> <alias>: Gives an item to the specified client.
money.inc
PHP Code:
#if defined _money_included
#endinput
#endif
#define _money_included
#define INVALID_MONEY_VALUE 0x80000000 /**< Used to indicate errors. */
#define MONEY_LIBRARY_NAME "ftz_money"
/**
* Returns client money.
*
* @param client Client index.
* @return Client money on success, INVALID_MONEY_VALUE otherwise.
* @error Invalid client index or clientprefs error.
*/
native GetClientMoney(const client);
/**
* Sets client money to a given value. Passing INVALID_MONEY_VALUE will always
* return false.
*
* @param client Client index.
* @param value Money to set to.
* @return True on success, false otherwise.
* @error Invalid client index or clientprefs error.
*/
native bool:SetClientMoney(const client, const value);
/**
* Adds specified amount to client money. Passing INVALID_MONEY_VALUE will
* always return false.
*
* @param client Client index.
* @param value Money to add.
* @return True on success, false otherwise.
* @error Invalid client index or clientprefs error.
*/
native bool:AddClientMoney(const client, const value);
/**
* Called when buy menu becomes ready to accept new items. All buy menu
* functions called before buy menu is ready will return false.
*
* @noreturn
*/
forward OnBuyMenuReady();
/**
* Returns whether buy menu is ready. You can use it to determine if your plugin
* is loaded late.
*
* @return True on success, false otherwise.
*/
native bool:IsBuyMenuReady();
/**
* Called when client is trying to buy an item. At this point it is determined
* that client has enough money to buy an item. You only have to give it and
* return true if it was successful.
*
* @param client Client index.
* @param alias Alias of the item.
* @return Return true to charge the price off client money and
* false otherwise.
*/
functag public bool:ItemHandler(const client, const String:alias[]);
/**
* Adds an item to the buy menu. It can be later referred to by it's alias.
*
* @param name Name of the item. It will be shown in the buy menu and
* chat. You can use any characters in it.
* @param alias Alias of the item. It is used in other buy menu natives
* and in buy command. You can use only lowercase
* alphamuneric characters and underscore (_) in it.
* @param price Price of the item. It can't be negative.
* @param callback A function to call when a client will try to buy the
* item.
* @param parentalias Alias of the menu to add the item to. Empty string means
* top menu.
* @return True on success, false if buy menu is not ready, parent
* doesn't exist or item already exists.
* @error Invalid item alias, price, callback or parent.
*/
native bool:AddBuyMenuItem(const String:name[], const String:alias[], const price, const ItemHandler:callback, const String:parentalias[] = "");
/**
* Changes the price of the item in the buy menu.
*
* @param alias Alias of the item.
* @param price Price of the item. It can't be negative.
* @return True on success, false if buy menu is not ready, item
doesn't exist or owned by another plugin.
* @error Invalid item alias or price.
*/
native bool:ChangeBuyMenuItemPrice(const String:alias[], const price);
/**
* Removes the item from the buy menu. This function is also used to remove
* submenus. When called on submenu, it will first try to recursively remove all
* items in that menu. If all items have been removed or menu was empty, it will
* remove menu itself. Therefore, if you have all your items in a submenu, you
* can remove them all in a single function call on that submenu.
*
* @param alias Alias of the item.
* @return True on success, false if buy menu is not ready, item
* doesn't exist, owned by another plugin or submenu has
* items owned by another plugins.
* @error Invalid item alias.
*/
native bool:RemoveBuyMenuItem(const String:alias[]);
/**
* Creates a submenu in the buy menu. It can be later referred to by it's alias.
* Submenus can be shared so this function will succeed even if another plugin
* has already registered submenu with the same alias and parent.
*
* @param title Title of the submenu. It will be shown in the buy menu.
* You can use any characters in it.
* @param alias Alias of the submenu. It is used in other buy menu
* natives and in buy command. You can use only lowercase
* alphamuneric characters and underscore (_) in it.
* @param parentalias Alias of the menu to add the submenu to. Empty string
* means top menu.
* @return True on success, false if buy menu is not ready, parent
* doesn't exist, an item with specified alias already
* exists or another submenu with the same alias but
* another parent already exists.
* @error Invalid item alias or parent.
*/
native bool:CreateBuyMenuSubMenu(const String:title[], const String:alias[], const String:parentalias[] = "");
public SharedPlugin:__pl_money =
{
name = MONEY_LIBRARY_NAME,
file = "ftz_money.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};
Compile requirements:
Known issues:- Tabulation symbols are shown as black squares since the recent update (at least in TF2).
- Due to a bug in SM translation system some phrases are done a bit awkwardly.
ToDo:- Make buy menu fully translatable.
Examples:
Here's how to register buy menu items correctly:
PHP Code:
public OnConfigsExecuted() //Replace with OnPluginStart if you don't hold your prices in ConVars.
{
if (IsBuyMenuReady())
{
OnBuyMenuReady();
}
}
public OnBuyMenuReady()
{
//Register here
}
Thanks to:- Psychonic for telling me about private forwards and providing example code.
|