Raised This Month: $ Target: $400
 0% 

[Any] Hub (a modular store)


Post New Thread Reply   
 
Thread Tools Display Modes
Author
databomb
Veteran Member
Join Date: Jun 2009
Location: california
Plugin ID:
3509
Plugin Version:
1.0.7
Plugin Category:
General Purpose
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Hub is a central plugin where credits are managed; it's designed to be an open !store plugin where you can easily modify existing plugins or add new plugins for use with the Hub.
    Old 02-02-2013 , 09:55   [Any] Hub (a modular store)
    Reply With Quote #1

    [ANY] Hub

    Hub is a central plugin where credits are managed; it's designed to be an open !store plugin where you can easily modify existing plugins or add new plugins for use with the Hub.

    Hub Menu Options
    Users who access the !hub menu will see the following 3 options by default:
    1. Purchase Item
    2. Gift Item
    3. Refund Item
    Cvars
    sm_hub_vbulletin (this provides vBulletin integration for forums with steam_code linked to their vb_user table)
    sm_hub_database (provides the databases.cfg entry to use to connect)
    sm_hub_link_url (if vBulletin integration is set, this will bring users to this website when !hub is entered and they don't have a steam_code linked to the forum)
    sm_hub_sell_rate (this is the percentage of credits a user will get returned to them when they sell an item from the hub)
    sm_hub_chat_prefix (self explanatory, the color codes are included)

    Features Config [addons/sourcemod/configs/hub/features.cfg]
    These entries will populate into the Sell, Gift, and Purchase options in the Hub. Each feature name should be unique. The menus can be 3 layers deep. Category names are allowed to better organize features but each actual feature needs to have a "Cost" value associated with it. The names for these features should match exactly the plugin that it's integrating with. For instance, using Zephyrus's Hats plugin, you would copy each entry in the hats.txt config over and add a Cost for all the hats. A sample is provided.

    Menus Config [addons/sourcemod/configs/hub/menus.cfg]
    These entries will add custom menus below the three default Hub options of Purchase, Sell, and Gift. The menus can be 2 layers deep. Category names are allowed to better organize menus but each menu entry should have a "command" value associated with it. The command is the console command the client would need to enter to access that feature. For instance, using Zephyrus's Hats plugin, the command entry would have "sm_hats" associated with it. A sample is provided.

    Optional Updating
    This will work with GoD-Tony's Updater plugin, if present.

    User Commands
    !hub / !store / !perks / !features -> All of these link to the main hub menu.

    Admin Commands
    sm_credit <client> [optional:amount]
    When the amount is left blank, it returns the credits for the targeted client; otherwise, it will add the amount specified of credits to the users account.

    Special Thanks
    Zephyrus for suggestions and efficient cvar handling
    GoD-Tony for helping to get the Updater plugin working
    Whoever wrote BuildDynamicMenu

    Changelog
    1.0.6 Initial Private Release (3 July 2012)
    1.0.7 Forwards added (11 August 2012)
    --- Moved to Public Plugins (2 February 2013)
    Attached Files
    File Type: smx hub.smx (22.1 KB, 660 views)
    File Type: sp Get Plugin or Get Source (hub.sp - 618 views - 41.7 KB)
    File Type: inc hub.inc (2.0 KB, 644 views)
    File Type: txt hub.phrases.txt (2.0 KB, 646 views)
    File Type: cfg features.cfg (305 Bytes, 823 views)
    File Type: cfg menus.cfg (77 Bytes, 813 views)
    __________________

    Last edited by databomb; 02-02-2013 at 11:11.
    databomb is offline
    databomb
    Veteran Member
    Join Date: Jun 2009
    Location: california
    Old 02-02-2013 , 09:56   Re: [Any] Hub
    Reply With Quote #2

    How To Link Plugins to the Hub

    Review the API

    PHP Code:
    // Double include protection
    #if defined _Hub_Included_
        #endinput
    #endif
    #define _Hub_Included_

    public SharedPlugin:__pl_hub =
    {
        
    name "hub",
        
    file "hub.smx",
        
    #if defined REQUIRE_PLUGIN
        
    required 1,
        
    #else
        
    required 0,
        
    #endif
    };

    public 
    __pl_hub_SetNTVOptional()
    {
        
    MarkNativeAsOptional("Debit");
        
    MarkNativeAsOptional("Credit");
        
    MarkNativeAsOptional("ClientHasFeature");
        
    MarkNativeAsOptional("Inquire");
    }

    /**
     * Requests a debit from a client. If they have enough money it will return 1
     * otherwise it won't deduct anything and will return 0.
     *
     * @param client        Client index
     * @param amount        Number of credits to deduct
     * @return                Successful charge
     */
    native bool:Debit(clientamount);

    /**
     * Credits a given amount to a client
     *
     * @param client        Client index
     * @param amount        Number of credits to add
     * @noreturn            
     */
    native void:Credit(clientamount);

    /**
     * Detects whether a given client has been given access to a given feature.
     *
     * @param client        Client index
     * @param feature        A feature text, as found in hub/features.cfg
     * @return                Whether the client has given feature        
     */
    native bool:ClientHasFeature(clientString:feature[]);

    /**
     * Determines how many credits a player currently has.
     *
     * @param client        Client index
     * @return                Number of credits
     */
    native Inquire(client); 
    Integrating the Plugins
    The main idea is to check the title text for each AddMenuItem to see if the client has access to that feature. If the client does, then it draws it like normal, but otherwise it will draw it with ITEMDRAW_DISABLED so the option is not selectable by clients. So the steps would be:

    • Add the include file for hub. Use #undef REQUIRE_PLUGIN to prevent problems with plugin loading order.
    • Identify where the Title text for the AddMenuItem's are located. Is it a translation file? A config file? (e.g. for Zephyrus's Hat's plugin, the main config file is sourcemod/configs/hats.txt)
    • Add a check for if a client has a feature. You can optionally add text to indicate that it's unowned. Below is an example inside [ANY] Hat's CreateHatsMenu:
    PHP Code:
                if (ClientHasFeature(clientg_eHats[i][Name]))
                {
                    if (
    i==g_iHatCache[client][g_eHats[i][Category]])
                    {
                        
    decl String:sName[100];
                        
    Format(sNamesizeof(sName), "%s (equipped)"g_eHats[i][Name]);
                        
    AddMenuItem(hMenuidsNameITEMDRAW_DISABLED);
                    }
                    else
                    {
                        
    AddMenuItem(hMenuidg_eHats[i][Name]);
                    }
                }
                else
                {
                    
    AddMenuItem(hMenuidg_eHats[i][Name], ITEMDRAW_DISABLED);
                } 
    • Add all of the title names to features.cfg under the category name of your choosing. For instance, copying all of hats.txt into features.cfg is the easy solution.
    • Assign costs to all the features inside the features.cfg file.
    More Reserved

    __________________
    databomb is offline
    databomb
    Veteran Member
    Join Date: Jun 2009
    Location: california
    Old 02-02-2013 , 09:57   Re: [Any] Hub
    Reply With Quote #3

    Plugins Using Hub

    Player Trails (databomb)
    __________________
    databomb is offline
    xrefresh
    SourceMod Donor
    Join Date: Apr 2011
    Old 02-02-2013 , 13:59   Re: [Any] Hub (a modular store)
    Reply With Quote #4

    Quote:
    Originally Posted by databomb View Post
    Credits would be given for whatever you want.. a basic plugin will have a timer and then call Credit() to give users points every minute for activity.
    Could you provide a example?
    xrefresh is offline
    shavit
    AlliedModders Donor
    Join Date: Dec 2011
    Location: Israel
    Old 02-02-2013 , 14:25   Re: [Any] Hub (a modular store)
    Reply With Quote #5

    Quote:
    Originally Posted by xrefresh View Post
    Could you provide a example?
    PHP Code:
    #include <sourcemod>
    #include <hub>

    #pragma semicolon 1

    public OnPluginStart()
    {
        
    CreateTimer(180.0pay_TIMER_REPEAT);
    }

    public 
    Action:pay(Handle:timer)
    {
        for(new 
    i<= MaxClientsi++)
        {
            if(
    && IsClientInGame(i))
            {
                if(!
    IsClientObserver(i))
                {
                    
    Credit(i10);
                    
                    
    PrintToChat(i"\x04You've earned 10 Hub credits.");
                }
            }
        }

    __________________
    retired

    Last edited by shavit; 02-02-2013 at 14:26.
    shavit is offline
    NameUser
    Senior Member
    Join Date: Apr 2012
    Location: Bay Area, California
    Old 02-02-2013 , 14:55   Re: [Any] Hub (a modular store)
    Reply With Quote #6

    About time this was released. Good work.
    __________________
    NameUser is offline
    Send a message via Skype™ to NameUser
    xrefresh
    SourceMod Donor
    Join Date: Apr 2011
    Old 02-02-2013 , 19:22   Re: [Any] Hub (a modular store)
    Reply With Quote #7

    Quote:
    Originally Posted by shavit View Post
    PHP Code:
    #include <sourcemod>
    #include <hub>

    #pragma semicolon 1

    public OnPluginStart()
    {
        
    CreateTimer(180.0pay_TIMER_REPEAT);
    }

    public 
    Action:pay(Handle:timer)
    {
        for(new 
    i<= MaxClientsi++)
        {
            if(
    && IsClientInGame(i))
            {
                if(!
    IsClientObserver(i))
                {
                    
    Credit(i10);
                    
                    
    PrintToChat(i"\x04You've earned 10 Hub credits.");
                }
            }
        }

    Is it possible to use a convar with a timer? I tried but couldn't get it to work.
    xrefresh is offline
    Jackmaster
    SourceMod Donor
    Join Date: May 2011
    Old 02-04-2013 , 07:33   Re: [Any] Hub (a modular store)
    Reply With Quote #8

    Nice to see you finally made it public. Keep up the good work.
    __________________

    Minigames - the way forward
    Visit our Minigame Server: 37.157.252.236:27015
    Jackmaster is offline
    Mooni
    SourceMod Donor
    Join Date: Dec 2012
    Location: Sweden
    Old 02-04-2013 , 19:58   Re: [Any] Hub (a modular store)
    Reply With Quote #9

    Hello im trying to add a adminflag check to the features but i cant get it to work so im here and asking for help.
    It compiles without any problems.
    I have mainly been looking at the sm_hats.sp to understand how it works.
    And i got the check to work in sm_hats with this code:
    PHP Code:
    if(g_eHats[i][Flags] != && (!(GetUserFlagBits(client) & g_eHats[i][Flags]) && !(GetUserFlagBits(client) & ADMFLAG_ROOT)))
    {
    decl String:sName[100];
    Format(sNamesizeof(sName), "%s (VIP ONLY)"g_eHats[i][Name]);
    AddMenuItem(hMenuidsNameITEMDRAW_DISABLED);

    Below is what i currently got.

    What i added:
    PHP Code:
    /********************************************/
    Somewhere around line 95
    /********************************************/

    enum Test
    {
        
    Flags
    };

    new 
    g_iFeatureCost[MAX_FEATURES];
    new 
    g_eFeatureFlag[MAX_FEATURES][Test];
    new 
    g_iFeatureType[MAX_FEATURES] = {-2, ...};
    new 
    String:g_sFeatureName[MAX_FEATURES][64];

    /********************************************/
    Somewhere around line 1085
    /********************************************/

    if (g_bClientHasFeature[client][idx])
    {
    Format(sTitlesizeof(sTitle), "%s %t"g_sFeatureName[idx], "Owned Menu Item Suffix");
    AddMenuItem(submenusInfosTitleITEMDRAW_DISABLED);
    }
    else if(
    g_eFeatureFlag[idx][Flags] != && (!(GetUserFlagBits(client) & g_eFeatureFlag[idx][Flags]) && !(GetUserFlagBits(client) & ADMFLAG_ROOT)))
    {
    Format(sTitlesizeof(sTitle), "%s %t"g_sFeatureName[idx], "VIP Menu Item Suffix");
    AddMenuItem(submenusInfosTitleITEMDRAW_DISABLED);
    }

    /********************************************/
    Somewhere around line 1360
    /********************************************/

    decl String:sBuffer[64];
    decl String:sFlag[2];

    /********************************************/
    Somewhere around line 1518
    /********************************************/

    KvGetString(hFeatures"Flag"sFlagsizeof(sFlag));
    g_eFeatureFlag[g_iFeatures][Flags] = ReadFlagString(sFlag);
    KvGetString(hFeatures"Cost"sBuffersizeof(sBuffer)); 
    What i added in hub.phrases.txt
    Code:
    	"VIP Menu Item Suffix"
    	{
    		"#format"	""
    		"en"		"(VIP ONLY)"
    	}
    How my features.cfg look like:
    Code:
    "Features"
    {
    	"Accesories"
    	{
    		"Hats"
    		{
    			"No hat"
    			{
    				"Cost" "0"
    				"Flag" ""
    			}
    
    			"Antlers"
    			{
    				"Cost" "15000"
    				"Flag" "r"
    			}
    			
    			"Car Tire"
    			{
    				"Cost" "15000"
    				"Flag" "r"
    			}
    			
    			"Watermelon"
    			{
    				"Cost" "15000"
    				"Flag" ""
    			}
    		}
    	}
    }

    Last edited by Mooni; 02-04-2013 at 20:18.
    Mooni is offline
    databomb
    Veteran Member
    Join Date: Jun 2009
    Location: california
    Old 02-04-2013 , 20:19   Re: [Any] Hub (a modular store)
    Reply With Quote #10

    edit: misunderstood

    I'm not convinced hub should be handling flags in addition to cost. It's really up to the hats plugin how that gets displayed.. if you want to check there to first see if a client has a specific flag before checking ClientHasFeature from hub, that would have the same effect. You could simply not list these VIP hats in the features.cfg.
    __________________

    Last edited by databomb; 02-04-2013 at 20:26.
    databomb 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 08:19.


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