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(iAchievementId, hClient, iAddProgress = 1, iSpecialFlags = 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(iMilestoneId, hClient, iSpecialFlags = 0, iPartProgress = -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], hClient, iAddProgress = 1, iSpecialFlags = 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], hClient, iSpecialFlags = 0, iPartProgress = -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(iAchievementId, hClient);
/**
* @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(iAchievementId, hClient);
/**
* @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(iAchievementId, String: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(iAchievementId, String:strAchievementUniqueName[64], iClient, iSpecialFlags);
/**
* @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(iAchievementId, String:strAchievementUniqueName[64], iClient, iProgress, iOldProgress, iMaxProgress, iSpecialFlags);
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.
__________________
Last edited by Flyflo; 12-05-2010 at 08:32.
|