Raised This Month: $ Target: $400
 0% 

Achievements API


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
hLiaS
Senior Member
Join Date: Aug 2011
Location: In My Holly Dreams
Old 01-28-2013 , 09:45   Re: Achievements API
Reply With Quote #4

PHP Code:
// includes, duh...
#include < amxmodx >
#include < csx >
#include < achievement_api >
#include < cstrike >

// declaring the max client size
const MaxClients 32;
// max steamid characters
const MaxSteamIdChars 35;
// random number for the set_task
const TaskIdDelayConnect 3799;

// to make it easier to retrieve the achievement data, we make an enumeration; making it a "structure"
enum _:AchievementDataStruct
{
    
_NameMaxClients ], // the name of the achievement
    
_Description256 ], // the description of the achievement (cannot exceed 255 chars - limit set in api)
    
_Save_NameMaxClients ], // the save key of the achievement
    
_Max_Value // and finally the max value (also referred to as objective value in other achievement plugins)
};

// an array built from the struct
new const AchievementInfoAchievementDataStruct ] = 
{
    
"Grenade Kills"// the name of the achievement
    
"Kill an enemy with a Grenade 50 times"// the description of the achievement (cannot exceed 255 chars - limit set in api)
    
"progress_grenade"// the save key of the achievement
    
50 // and finally the max value (also referred to as objective value in other achievement plugins)
};

// create a variable
new AchievementPointer;
// this variable will hold the unique index that the achievement has in the API, allowing you to use it to retrieve data

// variable to hold the steamid of a client
// 33 cells (for the 32 users) and 35 cells (for the steamid)
// const MaxClients = 32;
// const MaxSteamIdChars = 35;
new SteamIdMaxClients ][ MaxSteamIdChars ];

// our objective counter, will hold the current kills of a client
// 33 cells (for all the 32 users)
new GrenadeKillsMaxClients ];

// variable holding the max players (not max slots)
new MaxPlayers;

public 
plugin_init( ) // self explanatory
{
    
// register plugin
    
register_plugin"Achievement API: Grenade Kills""0.0.1""Xellath" );
    
    
// register achievement to api
    // in the order: Achievement Name, Description, Save Key and Max Value
    
AchievementPointer RegisterAchievementAchievementInfo_Name ], AchievementInfo_Description ], AchievementInfo_Save_Name ], AchievementInfo_Max_Value ] );
    
// will return index of achievement (stored in AchievementPointer)

    // assign max players (not max slots)
    
MaxPlayers get_maxplayers( );
    
    
// the achievement is now registered to the API, lets start with the grenade kill thingy
}

public 
client_connectClient // called when client connects
{
    
// set a 10 sec task to check if user has completed or has data for the achievement
    
set_task10.0"TaskDelayConnect"Client TaskIdDelayConnect );
}

public 
TaskDelayConnectTaskId )
{
    
// our client id (Client) = (TaskId - TaskIdDelayConnect (3799))
    
new Client TaskId TaskIdDelayConnect;
    
    
// get steamid of client
    
get_user_authidClientSteamIdClient ], charsmaxSteamId ) );
    
    
// check if our client has objective data
    
GrenadeKillsClient ] = GetAchievementDataSteamIdClient /* our key */AchievementInfo_Save_Name /* save name for achievement (declared in the array) */ );
    
    
// check if client already completed achievement
    
if( GetClientAchievementStatusAchievementPointerGrenadeKillsClient ] ) == _In_Progress )
    {
        
// achievement not completed
        
        // save objective data to clients steamid
        
SetAchievementDataSteamIdClient /* our key */AchievementInfo_Save_Name /* save name for achievement */GrenadeKillsClient /* data */ );
    }
    else 
//if( GetClientAchievementStatus( AchievementPointer, Connections[ Client ] ) == _Unlocked )
    
{
        
// client has completed achievement already
        // send completed to api, but don't announce (or else every client would get all achievements everytime the connect)
        
ClientAchievementCompletedClientAchievementPointer, .Announce false );
    }
    
    
// remove task
    
remove_taskClient TaskIdDelayConnect );
}

public 
client_disconnectClient )
{
    
// reset variable in case played indexes are magically switched and another client gets another set of connections
    
GrenadeKillsClient ] = 0;
}

public 
client_deathKillerVictimWeaponIndexHitplaceTeamKill // called when a client dies
{
    
// check whether victim and killer are actual players (index above or equal 1 but lower or equal to 32)
    
if( <= Victim <= MaxPlayers 
    
&& <= Killer <= MaxPlayers )
    {
        
// victim did not kill himself
        
if( Victim != Killer )
        {
            
// was the weapon a hegrenade?
            
if( WeaponIndex == CSW_HEGRENADE )
            {
                
// yes it was
                // check if client has unlocked the achievement
         
if( cs_get_user_team(Killer) == CS_TEAM_T)
         {
                if( 
GetClientAchievementStatusAchievementPointerGrenadeKillsKiller ] ) == _In_Progress )
                {
                    
// increment the objective value
                    
GrenadeKillsKiller ]++;
                    
// save data
                    
SetAchievementDataSteamIdKiller /* our key */AchievementInfo_Save_Name /* save name for achievement */GrenadeKillsKiller /* data */ );
                    
                    
// check if client just unlocked the achievement
                    
if( GetClientAchievementStatusAchievementPointerGrenadeKillsKiller ] ) == _In_Progress )
                    {
                        
// client unlocked the achievement
                        
                        // send completed to api, and announce
                        
ClientAchievementCompletedKillerAchievementPointer, .Announce true ); // true is default, but just to clarify
                        // the forward below is now called, so to award extra stuff, do something in the forward
                    
}
                }
            }
       else
       return 
PLUGIN_CONTINUE
        
}
    }
}

public 
Forward_ClientEarnedAchievement( const AchiPointer, const Client // called when client earned the achievement
{
    if( 
AchiPointer == AchievementPointer )
    {
        
// this forward can be used to reward people stuff
        // perhaps a model or just something extra (like ie. cash from cashmod, pointsystem etc.)
    
}

sorry for the second post something like that??
hLiaS is offline
Send a message via Skype™ to hLiaS
 



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 20:37.


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