Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //================================= [ Includes ] ===============================
- #include <a_samp>
- #include <a_mysql>
- #include <sscanf2>
- #include <zcmd>
- //============================ [ MySQL Configuration] ==========================
- #define MySQL_Host "localhost" // Change this
- #define MySQL_User "root" // Change this
- #define MySQL_Pass "" // Change this
- #define MySQL_Data "TestDB" // Change this
- #define Achievements_ "tehachz1944" // Change this (optional)
- //================================= [ Defines ] ================================
- new FALSE = false;
- #define GivePlayerScore(%0,%1) SetPlayerScore(%0,GetPlayerScore(%0)+%1)
- #define SendFormattedMessageToAll(%1,%2,%3) do{new _str[190]; format(_str,150,%2,%3); SendClientMessageToAll(%1,_str);}while(FALSE)
- #define function%0(%1) forward%0(%1);public%0(%1)
- //==============================================================================
- enum AchievementInfo
- {
- Username[24], Ach1, Ach2, Ach3, AchsCompleted
- };
- new AInfo[MAX_PLAYERS][AchievementInfo], gName[MAX_PLAYER_NAME], gQuery[520], MySQL;
- //==============================================================================
- public OnFilterScriptInit()
- {
- MySQL = mysql_connect(MySQL_Host, MySQL_User, MySQL_Data, MySQL_Pass);
- mysql_log(LOG_ALL);
- // Let's create the table if it doesn't exist
- mysql_tquery(MySQL, "CREATE TABLE IF NOT EXISTS `"Achievements_"` (" \
- "`Username` varchar(24) NOT NULL," \
- "`Ach1` int(5) NOT NULL," \
- "`Ach2` int(5) NOT NULL," \
- "`Ach3` int(5) NOT NULL," \
- "`AchsCompleted` int(5) NOT NULL," \
- "PRIMARY KEY (`Username`)" \
- ") ENGINE=InnoDB DEFAULT CHARSET=latin1;");
- // We'll use this if there are players connected when filterscript is loaded
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i))
- {
- // Reseting the achievement variables
- AInfo[i][Ach1] = 0, AInfo[i][Ach2] = 0, AInfo[i][Ach3] = 0, AInfo[i][AchsCompleted] = 0;
- // Let's check if there is a row with this username
- mysql_format(MySQL, gQuery, 256, "SELECT * FROM `"Achievements_"` WHERE Username = '%s' LIMIT 1", GetPName(i));
- mysql_tquery(MySQL, gQuery, "CheckAchievements", "i", i);
- }
- }
- // Let's check if the connection was successful
- if(mysql_errno(MySQL) == 0) print("ACHS: Connection established to the database!");
- else print("ACHS: Connection couldn't be established to the database!");
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i))
- {
- // Saving the achievements
- mysql_format(MySQL, gQuery, 256, "UPDATE `"Achievements_"` SET Ach1 = '%i', Ach2 = '%i', Ach3 = '%i', AchsCompleted = '%i' WHERE Username = '%s'",
- AInfo[i][Ach1], AInfo[i][Ach2], AInfo[i][Ach3], AInfo[i][AchsCompleted], GetPName(i));
- mysql_tquery(MySQL, gQuery, "", "");
- // Reseting the achievement variables
- AInfo[i][Ach1] = 0, AInfo[i][Ach2] = 0, AInfo[i][Ach3] = 0, AInfo[i][AchsCompleted] = 0;
- }
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- // Reseting the achievement variables
- AInfo[playerid][Ach1] = 0, AInfo[playerid][Ach2] = 0, AInfo[playerid][Ach3] = 0, AInfo[playerid][AchsCompleted] = 0;
- // Let's check if there is a row with this username
- mysql_format(MySQL, gQuery, 256, "SELECT * FROM `"Achievements_"` WHERE Username = '%s' LIMIT 1", GetPName(playerid));
- mysql_tquery(MySQL, gQuery, "CheckAchievements", "i", playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- // Saving the achievements
- mysql_format(MySQL, gQuery, 256, "UPDATE `"Achievements_"` SET Ach1 = '%i', Ach2 = '%i', Ach3 = '%i', AchsCompleted = '%i' WHERE Username = '%s'",
- AInfo[playerid][Ach1], AInfo[playerid][Ach2], AInfo[playerid][Ach3], AInfo[playerid][AchsCompleted], GetPName(playerid));
- mysql_tquery(MySQL, gQuery, "", "");
- // Reseting the achievement variables
- AInfo[playerid][Ach1] = 0, AInfo[playerid][Ach2] = 0, AInfo[playerid][Ach3] = 0, AInfo[playerid][AchsCompleted] = 0;
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- CheckAchs(playerid);
- return 1;
- }
- //================================== [ Functions ] =============================
- function CheckAchievements(playerid)
- {
- new rows, fields;
- cache_get_data(rows, fields, MySQL);
- if(rows)
- {
- cache_get_field_content(0, "Username", AInfo[playerid][Username], MySQL, 24);
- AInfo[playerid][Ach1] = cache_get_field_content_int(0, "Ach1", MySQL);
- AInfo[playerid][Ach2] = cache_get_field_content_int(0, "Ach2", MySQL);
- AInfo[playerid][Ach3] = cache_get_field_content_int(0, "Ach3", MySQL);
- AInfo[playerid][AchsCompleted] = cache_get_field_content_int(0, "AchsCompleted", MySQL);
- }
- else
- {
- mysql_format(MySQL, gQuery, 256, "INSERT INTO `"Achievements_"` (Username, Ach1, Ach2, Ach3, AchsCompleted) VALUES ('%s', '0', '0', '0', '0')", GetPName(playerid));
- mysql_tquery(MySQL, gQuery, "", "");
- }
- return 1;
- }
- function CheckAchs(playerid)
- {
- if(AInfo[playerid][Ach1] != 1)
- {
- if(GetPlayerMoney(playerid) >= 5000000)
- {
- AInfo[playerid][Ach1] = 1;
- AInfo[playerid][AchsCompleted]++;
- SendFormattedMessageToAll(0xFF0000FF, "ACHS: {8CAB62}%s(%i) has unlocked the 'Millionare' achievement!", GetPName(playerid), playerid);
- GivePlayerMoney(playerid, 200000), GivePlayerScore(playerid, 10);
- if(AInfo[playerid][AchsCompleted] >= 3)
- {
- GivePlayerMoney(playerid, 10000000), GivePlayerScore(playerid, 2500);
- SendFormattedMessageToAll(0xFF0000FF, "ACHS: {8CAB62}%s(%i) has unlocked all of the achievements!", GetPName(playerid), playerid);
- return 1;
- }
- }
- }
- if(AInfo[playerid][Ach2] != 1)
- {
- if(GetPlayerScore(playerid) >= 2500)
- {
- AInfo[playerid][Ach2] = 1;
- AInfo[playerid][AchsCompleted]++;
- SendFormattedMessageToAll(0xFF0000FF, "ACHS: {8CAB62}%s(%i) has unlocked the 'Score Whore' achievement!", GetPName(playerid), playerid);
- GivePlayerMoney(playerid, 200000), GivePlayerScore(playerid, 10);
- if(AInfo[playerid][AchsCompleted] >= 3)
- {
- GivePlayerMoney(playerid, 10000000), GivePlayerScore(playerid, 2500);
- SendFormattedMessageToAll(0xFF0000FF, "ACHS: {8CAB62}%s(%i) has unlocked all of the achievements!", GetPName(playerid), playerid);
- return 1;
- }
- }
- }
- if(AInfo[playerid][Ach3] != 1)
- {
- if(GetPlayerPing(playerid) >= 500)
- {
- AInfo[playerid][Ach3] = 1;
- AInfo[playerid][AchsCompleted]++;
- SendFormattedMessageToAll(0xFF0000FF, "ACHS: {8CAB62}%s(%i) has unlocked the 'Mother of Lag' achievement!", GetPName(playerid), playerid);
- GivePlayerMoney(playerid, 200000), GivePlayerScore(playerid, 10);
- if(AInfo[playerid][AchsCompleted] >= 3)
- {
- GivePlayerMoney(playerid, 10000000), GivePlayerScore(playerid, 2500);
- SendFormattedMessageToAll(0xFF0000FF, "ACHS: {8CAB62}%s(%i) has unlocked all of the achievements!", GetPName(playerid), playerid);
- return 1;
- }
- }
- }
- return 1;
- }
- //================================= [ Stocks ] =================================
- stock GetPName(playerid)
- {
- GetPlayerName(playerid, gName, sizeof gName);
- return gName;
- }
- stock ShowPlayerAchievements(playerid, targetid)
- {
- new TempStr[520], complete[20], incomplete[20];
- complete = "{05E200}[•]", incomplete = "{FF0000}[•]";
- strcat(TempStr, "%s {FFFFFF}Millionare \t\t{FF4500}- {00FFFF}Get $5,000,000 money to unlock this!\n");
- strcat(TempStr, "%s {FFFFFF}Score Whore\t\t{FF4500}- {00FFFF}Get 2,500 score to unlock this!\n");
- strcat(TempStr, "%s {FFFFFF}Mother of Lag \t {FF4500}- {00FFFF}Have a ping greater than 500! xd\n");
- strcat(TempStr, "%s(%i) has completed %i/3 achievements!\n");
- strcat(TempStr, "%s {FF4500}- {00FFFF}Completed Achievement {FFFFFF} | %s {FF4500}- {00FFFF}Incomplete Achievement");
- format(TempStr, sizeof TempStr, TempStr, (AInfo[targetid][Ach1] == 1) ? (complete) : (incomplete), (AInfo[targetid][Ach2] == 1) ? (complete) : (incomplete),
- (AInfo[targetid][Ach3] == 1) ? (complete) : (incomplete), GetPName(targetid), targetid, AInfo[targetid][AchsCompleted], complete, incomplete);
- ShowPlayerDialog(playerid, 7182, DIALOG_STYLE_MSGBOX, " Player Achievements", TempStr, "Great", "");
- return 1;
- }
- //=============================== [ Command(s) ] ===============================
- CMD:achievements(playerid, params[])
- {
- new id;
- if(sscanf(params, "u", id)) return SendClientMessage(playerid, 0x00B9FFFF, "Use /ach(ievements) [player name/id] to view another player's achievements info!"), ShowPlayerAchievements(playerid, playerid);
- if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: {828282}You have entered an invalid player name/id!");
- ShowPlayerAchievements(playerid, id);
- return 1;
- }
- CMD:ach(playerid, params[]) return cmd_achievements(playerid, params);
- //==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment