Raised This Month: $51 Target: $400
 12% 

[TF2] Custom Achievements Api


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Flyflo
Senior Member
Join Date: Jun 2008
Location: Grenoble, France
Plugin ID:
1584
Plugin Version:
Beta1
Plugin Category:
Gameplay
Plugin Game:
Team Fortress 2
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Provide a programming interface to include achievements in your plugins.
    Old 04-02-2010 , 04:41   [TF2] Custom Achievements Api
    Reply With Quote #1

    Historical:
    This plugin is based on Gachl and linux_lover Custom Achievements plugin.
    I rewrote it from scratch, and added a lot of new features.
    Commands and Cvars:

    sm_ca_api_enabled : default to 1.
    sm_ca_api_db : Database configuration to use (located in database.cfg, default achievements)
    sm_ca_api_db_tableprefix : Prefix for tables (default ca_)
    sm_ca_api_storenames : If set to 1, store players name and steamid in the database (useful for a web interface, default to 1).
    sm_ca_api_achurl : Used to open a webpage ingame, useful to show an achievement page (default to NULL).

    sm_ca_api_list : Print in the console the achievements stored in the database (admin command).
    achievements : Open the page specified in sm_ca_api_achurl and add the steamid of the player calling this command at the end.

    Natives:

    PHP Code:
    // iSpecialFlags
    #define ACHIEVEMENT_CHEAT_ENABLED        (1 << 0)                                // Achievement can progress/be achieved when sv_cheats = 1
    #define ACHIEVEMENT_UNIQUE                (1 << 1)                                // Achievement can be achieved by only one player
    #define ACHIEVEMENT_NOTEXT                (1 << 2)                                // Disable achievement text in chat
    #define ACHIEVEMENT_NOPARTICLE            (1 << 3)                                // Disable achievement particles
    #define ACHIEVEMENT_NOSOUND                (1 << 4)                                // Disable achievement sound
    #define ACHIEVEMENT_SILENT                ((1 << 2) | (1 << 3) | (1 << 4))
    #define ACHIEVEMENT_DEBUG                (1 << 5)                                // Verbose mode for development
    #define ACHIEVEMENT_HAS_TRANSLATION        (1 << 6)                                // The achievement has a translation in achievements_api.phrases.txt

    //

    /**
     * @brief Process an Achievement
     * 
     * @param iAchievementId                The Achievement ID
     * @param hClient                        The target client
     * @param iAddProgress                    Progress Amount (default 1)
     * @param iSpecialFlags                    Specified above
     * @return 0 on continue, -1 on error
     */
    native CA_ProcessAchievement(iAchievementIdhClientiAddProgress 1iSpecialFlags 0);

    /**
     * @brief Check if we should trigger a milestone
     * 
     * @param iMilestoneId                    The Milestone ID
     * @param hClient                        The target client
     * @param iSpecialFlags                    Specified above
     * @param iPartProgress                    If specified, trigger the milestone if the player achieved this number of achievements on the total set
     * @return 0 on continue, -1 on error
     */
    native CA_CheckForMilestone(iMilestoneIdhClientiSpecialFlags 0iPartProgress = -1);

    /**
     * @brief Process an Achievement by name
     * 
     * @param strAchievementUniqueName        The Achievement Name
     * @param hClient                        The target client
     * @param iAddProgress                    Progress Amount (default 1)
     * @param iSpecialFlags                    Specified above
     * @param iPartProgress                    If specified, trigger the milestone if the player achieved this number of achievements on the total set
     * @return 0 on continue, -1 on error
     */
    native CA_ProcessAchievementByName(String:strAchievementUniqueName[64], hClientiAddProgress 1iSpecialFlags 0);

    /**
     * @brief Check if we should trigger a milestone by name
     * 
     * @param strMilestoneUniqueName        The Milestone ID
     * @param hClient                        The target client
     * @param iSpecialFlags                    Specified above
     * @return 0 on continue, -1 on error
     */
    native CA_CheckForMilestoneByName(String:strMilestoneUniqueName[64], hClientiSpecialFlags 0iPartProgress = -1);

    /**
     * @brief Return the progress of an Achievement (Non threaded query)
     * 
     * @param iAchievementId                The Achievement ID
     * @param hClient                        The target client
     * @return                                 The progress, -1 on error
     */
    native CA_GetAchievementProgress(iAchievementIdhClient);

    /**
     * @brief Say if a Client achieved the specified Achievement (Non threaded query)
     * 
     * @param iAchievementId                The Achievement ID
     * @param hClient                        The target client
     * @return                                 1 if achieved, 0 if not, -1 on error
     */
    native CA_IsAchievedByClient(iAchievementIdhClient);

    /**
     * @brief Return the unique name of the specified Achievement (Non threaded query)
     * 
     * @param iAchievementId                The Achievement ID
     * @param strAchievementName            Strint to write the name to.
     * @return                                 0 on success, -1 on error
     */
    native CA_IdToName(iAchievementIdString:strAchievementName[64]);

    /**
     * @brief Return the unique name of the specified Achievement (Non threaded query)
     *
     * @param strAchievementName            The Achievement Unique Name
     * @return                                 The Achievement id on success -1 on error.
     */
    native CA_NameToId(String:strAchievementName[64]); 
    Forwards:

    PHP Code:
    /**
     * @brief Called whenever a client triggers an Achievement
     *
     * @param iAchievementId                The Achievement ID
     * @param strAchievementUniqueName        The Achievement Unique Name ("" if not specified)
     * @param hClient                        The target client
     * @param iSpecialFlags                    Flags used
     * @noreturn
     */
    forward AchievementTriggered(iAchievementIdString:strAchievementUniqueName[64], iClientiSpecialFlags);

    /**
     * @brief Called whenever a client progresses an Achievement
     *
     * @param iAchievementId                The Achievement ID
     * @param strAchievementUniqueName        The Achievement Unique Name ("" if not specified)
     * @param hClient                        The target client
     * @param iProgress                        Progress Added
     * @param iOldProgress                    Old Progress
     * @param iMaxProgress                    Maximum Progress
     * @param iSpecialFlags                    Flags used
     * @noreturn
     */
    forward AchievementProgressed(iAchievementIdString:strAchievementUniqueName[64], iClientiProgressiOldProgressiMaxProgressiSpecialFlags); 
    Setup:

    Add your database configuration to the configs/database.cfg file corresponding to the previous cvars.
    Example:
    Code:
    	"achievements"
    	{
    		"driver"			"default"
    		"host"				"127.0.0.1"
    		"database"			"achievements"
    		"user"				"blabla"
    		"pass"				"omnomnomnom"
    	}
    Database structure:
    Code:
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
    
    --
    -- Base de données: `achievements`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `ca_achievements`
    --
    
    CREATE TABLE IF NOT EXISTS `ca_achievements` (
      `id` int(10) NOT NULL auto_increment,
      `unique_name` varchar(64) NOT NULL,
      `name` varchar(64) NOT NULL,
      `description` varchar(200) NOT NULL,
      `picture` varchar(250) NOT NULL,
      `amount` int(10) NOT NULL,
      `FLAGS` varchar(255) NOT NULL,
      UNIQUE KEY `id` (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `ca_milestones`
    --
    
    CREATE TABLE IF NOT EXISTS `ca_milestones` (
      `milestone_id` int(10) NOT NULL,
      `milestone_unique_name` varchar(64) NOT NULL,
      `achievements_list` varchar(128) NOT NULL,
      PRIMARY KEY  (`milestone_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `ca_players`
    --
    
    CREATE TABLE IF NOT EXISTS `ca_players` (
      `steamid` varchar(50) NOT NULL,
      `name` varchar(100) NOT NULL,
      PRIMARY KEY  (`steamid`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    -- --------------------------------------------------------
    
    --
    -- Structure de la table `ca_progress`
    --
    
    CREATE TABLE IF NOT EXISTS `ca_progress` (
      `steamid` varchar(50) NOT NULL,
      `achievement_id` int(10) NOT NULL,
      `progression` int(10) NOT NULL,
      `achieved` timestamp NULL default NULL,
      PRIMARY KEY  (`steamid`,`achievement_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    Usage/Example:

    Look at ca_exemple.sp (the plugin will compile with the forum but wont do anything, you have to compile it yourself or use the attached smx).
    The translation example needs you to add this to the achievements_api.phrases.txt:
    Code:
    	"1"
    	{
    		"fr"			"Unlock Test"
    		"en"			"Unlock Test"
    	}
    And of course you'll need an entry in your database.

    Translations:

    When using the ACHIEVEMENT_HAS_TRANSLATION flag:
    If you pass the achievement by id, the translation will look like this (1 is the achievement id):
    Code:
    	"1"
    	{
    		"fr"			"fu"
    		"en"			"bar"
    	}
    If you pass the achievement by name, the translation will look like this (TF_FU_BAR is the achievement unique name):
    Code:
    	"TF_FU_BAR"
    	{
    		"fr"			"fu"
    		"en"			"bar"
    	}

    If the ACHIEVEMENT_HAS_TRANSLATION flag is not used, the name will be the same as the one in the achievement table.
    Milestones:

    When you create an a milestone, first you have to create a normal achievement, then in the milestone table you have to create an entry with the same id and unique_name (if specified).
    The achievement_id field contains each achievements of the set separated by a |.
    Changelog :
    Code:
    Beta1 (04/02/2010) :
    - First public version.
    Beta2 (10/28/2010) :
    - Fixed a bug spamming errors.
    - Usage of TF2_GetPlayerConditionFlags()
    Note:
    I've been using my plugin for quite a long time now, but because I'm not using all of its functions and the partial rewrite due to the public release, some bugs might be presents.
    I think I'm not good at making manuals, so don't hesitate to ask me things.
    Attached Files
    File Type: sp Get Plugin or Get Source (achievements_api.sp - 1857 views - 61.5 KB)
    File Type: inc CA_api.inc (5.3 KB, 839 views)
    File Type: txt achievements_api.phrases.txt (135 Bytes, 840 views)
    File Type: smx ca_exemples.smx (3.4 KB, 601 views)
    File Type: sp Get Plugin or Get Source (ca_exemples.sp - 1743 views - 2.6 KB)
    __________________

    Last edited by Flyflo; 12-05-2010 at 08:32.
    Flyflo is offline
    Thrawn2
    Veteran Member
    Join Date: Apr 2009
    Old 04-02-2010 , 05:15   Re: [TF2] Custom Achievements Api
    Reply With Quote #2

    awesome. i'm looking forward to see this grow.
    Thrawn2 is offline
    SatlaN
    Member
    Join Date: Sep 2009
    Old 05-31-2010 , 06:02   Re: [TF2] Custom Achievements Api
    Reply With Quote #3

    How do I create an achievements?
    I didn't got it if you said that.
    SatlaN is offline
    TricH
    New Member
    Join Date: Oct 2010
    Old 10-28-2010 , 00:09   Re: [TF2] Custom Achievements Api
    Reply With Quote #4

    Hey guys,

    I'm completely new to sourcemod. I made 5 achievements from the flyflo's achievement API. I would like to know if it is better to have 1 plugin per achievement or all of them in one plugin.

    Continue your great work Flyflo!
    TricH is offline
    Flyflo
    Senior Member
    Join Date: Jun 2008
    Location: Grenoble, France
    Old 10-28-2010 , 05:01   Re: [TF2] Custom Achievements Api
    Reply With Quote #5

    The plugin can handle one or multiple plugins but I personally use 1 plugin for all my achievements (it takes least space in the plugin folder :p). On the other side, using more plugins enable you to debug and update your achievements more easily.

    I just made a little update to the plugin to fix a bug that could spam the error log.
    __________________

    Last edited by Flyflo; 10-28-2010 at 05:03.
    Flyflo is offline
    Droganis
    Junior Member
    Join Date: Nov 2009
    Old 11-14-2010 , 17:39   Re: [TF2] Custom Achievements Api
    Reply With Quote #6

    Trying to figure out how to use this, added the smx files and trying to understand how to make the database. Do I just make a php file and use the codes supplied in the first post to create the achievements?
    __________________
    Droganis is offline
    Leonardo
    Veteran Member
    Join Date: Feb 2010
    Location: 90's
    Old 11-25-2010 , 09:18   Re: [TF2] Custom Achievements Api
    Reply With Quote #7

    sm_ca_api_storenames just enable/disable storing names in standalone table, right? and can someone post example with milestone? ._.
    __________________

    Last edited by Leonardo; 11-25-2010 at 10:20.
    Leonardo is offline
    Flyflo
    Senior Member
    Join Date: Jun 2008
    Location: Grenoble, France
    Old 11-25-2010 , 10:56   Re: [TF2] Custom Achievements Api
    Reply With Quote #8

    Quote:
    Originally Posted by Leonardo View Post
    sm_ca_api_storenames just enable/disable storing names in standalone table, right?
    Yes it stores players names in a standalone table.

    For the milestone:
    If you have two achievements X and Y; and you want to make a milestone Z which triggers when X and Y are completed, you have to:
    - Create 3 achievements X, Y and Z in the achievements table.
    - Create a milestone in the milestones table with Z id in milestone_id and X and Y ids separated by a | in achievements_list
    Then, in your plugin, you'll have to call CA_CheckForMilestone with Z id each time you want to check if a player achieved it.
    __________________
    Flyflo is offline
    Leonardo
    Veteran Member
    Join Date: Feb 2010
    Location: 90's
    Old 11-26-2010 , 02:23   Re: [TF2] Custom Achievements Api
    Reply With Quote #9

    Quote:
    CREATE TABLE IF NOT EXISTS `ca_milestones` (
    `milestone_id` int(11) NOT NULL,
    `milestone_unique_name` varchar(64) NOT NULL,
    `achievement_id` int(11) NOT NULL COMMENT 'Separate each achievement by a pipe',
    KEY `milestone_id` (`milestone_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    huh?
    __________________
    Leonardo is offline
    Flyflo
    Senior Member
    Join Date: Jun 2008
    Location: Grenoble, France
    Old 11-26-2010 , 04:58   Re: [TF2] Custom Achievements Api
    Reply With Quote #10

    Oops, some old code.
    The good version is the one with achievements_list as a varchar.
    I updated the OP, thanks
    __________________
    Flyflo 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 21:49.


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