Raised This Month: $ Target: $400
 0% 

[ANY] Money system


Post New Thread Reply   
 
Thread Tools Display Modes
Author
FaTony
Veteran Member
Join Date: Aug 2008
Plugin ID:
2249
Plugin Version:
1.0.0.0
Plugin Category:
Technical/Development
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Adds money system and buy menu natives for use in your plugins
    Old 02-26-2011 , 17:53   [ANY] Money system
    Reply With Quote #1

    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:
    • Clientprefs extension.

    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.
    Attached Files
    File Type: zip ftz_money.zip (27.4 KB, 635 views)
    __________________
    FaTony is offline
    luki1412
    Veteran Member
    Join Date: Oct 2008
    Location: OnPluginStart()
    Old 10-15-2013 , 08:26   Re: [ANY] Money system
    Reply With Quote #2

    Author is banned so plugin should be unapproved right?
    __________________
    luki1412 is offline
    Leonardo
    Veteran Member
    Join Date: Feb 2010
    Location: 90's
    Old 10-15-2013 , 08:37   Re: [ANY] Money system
    Reply With Quote #3

    Quote:
    Originally Posted by luki1412 View Post
    Author is banned so plugin should be unapproved right?
    No, it should be unapproved left.
    Also, if it's working good and shouldn't be updated - everything is ok?
    Leonardo is offline
    RedSword
    SourceMod Plugin Approver
    Join Date: Mar 2006
    Location: Quebec, Canada
    Old 10-16-2013 , 12:53   Re: [ANY] Money system
    Reply With Quote #4

    Quote:
    Originally Posted by luki1412 View Post
    Author is banned so plugin should be unapproved right?
    Nop. Mainly if it's failing (i.e. errors). There are some plugins out there with an inactive author, still being used & marked as approved.
    __________________
    My plugins :
    Red Maze
    Afk Bomb
    RAWR (per player/rounds Awp Restrict.)
    Kill Assist
    Be Medic

    You can also Donate if you appreciate my work
    RedSword is offline
    SkinnyBruv
    AlliedModders Donor
    Join Date: Feb 2013
    Location: Straya
    Old 10-17-2013 , 01:26   Re: [ANY] Money system
    Reply With Quote #5

    i could continue his work if you allow me. It would make my coding skills better and become more advanced.
    __________________
    www.ancientgaming.net is my story.
    Everything happens for a reason.
    Nothing is random...
    #Do you even AGN...
    SkinnyBruv is offline
    Send a message via Skype™ to SkinnyBruv
    ddhoward
    Veteran Member
    Join Date: May 2012
    Location: California
    Old 10-17-2013 , 02:01   Re: [ANY] Money system
    Reply With Quote #6

    You don't need anyone's permission to modify plugins...
    __________________
    ddhoward is offline
    Reply



    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 11:44.


    Powered by vBulletin®
    Copyright ©2000 - 2024, vBulletin Solutions, Inc.
    Theme made by Freecode