10.09.2010, 23:59
(
Последний раз редактировалось Joe Staff; 04.04.2013 в 18:26.
)
I saw another Achievements script and I felt like it was lacking a few things.
This include makes adding achievements to any script fairly easy. It was designed for use in the gamemode only, not filterscripts.
It's a slight bit advanced, considering you have to design how the achievements are earned, but if you can make a very simple deathmatch, you can make an achievement with ease.
Features
Uses SA-MP's native SQLite Database engine, a fast and organized method of saving information. You can access it using an SQLite manager program, one is supplied at the bottom of this post.
Achievements are easily created, and the level of complexity is up to you.
A "Secret" variable can change how much information of an achievement is given to a player when using the given functions
Onscreen textdraw confirmation when an achievement is completed or progressed atleast 10%. It shows for 3 seconds, during which it will continue to update if the achievement is progressing while it's still showing.
The achievement dialog list is a 1 function call that shows all achievements to the player and allows them to see the description and their progression on the achievement.
Designed to allow for infinite achievements.*
Functions
stock CreateAchievement(ShortName[],FullName[],Stages,Description[],Secret=0)**
--Creates the achievement and lists in in the SQLite database found in scriptfiles named "Achievements"
stock ProgressPlayerAchievement(playerid,ShortName[],Increment)
--Use this to make the progress go up about the indicated amount, it won't go passed the maximum.
stock GetPlayerProgress(playerid,AchievementName[])
--This returns how much progress has been completed
stock ShowPlayerProgress(playerid,AchievementName[],Time=3000,update=0)***
--This shows the onscreen textdraw (highly suggested to put this in the OnPlayerFinishAchievement and OnPlayerProgressCheckpoint callbacks)
stock ShowAchievementsDialog(playerid)
--This shows the Dialog list, REQUIRES JA_OnDialogResponse
---------------
stock JA_OnDialogReponse(playerid,dialogid,response,list item) //Required if you use ShowAchievementsDialog
--Put this in OnDialogResponse callback using the respective parameters.
Callbacks
public OnPlayerFinishAchievement(playerid,AchievementName[])
--Called upon completion of the achievement, AchievementName[] is the achievement's ShortName
public OnPlayerProgressCheckpoint(playerid,AchievementNam e[])
--Called every 10% of completion on the achievement, AchievementName[] is the achievement's ShortName
---------------
public JA_DeleteAchievementWindow(playerid) //You don't have much reason to use this, just leave it alone.
--This is for the timer to delete the Textdraw, don't bother with it
Pictures and Development Log
Achievements Include Topic
You'll find other projects in developement here if you're interested. More information can be found here
Download
J_Achievements.INC
SQL Database Browser 2.0 b1 -I use it, pretty decent
Notes
*The Achievement dialog will be cut off if too many achievements are shown, I plan on updating this
**Secret level 1 = No Description, level 2 = Not Title, level 3 = No Progress displayed, will show when completed
***The parameter marked as "update" is used for another system, do NOT mess with it
Examples:
This example includes:
How to implement the Achievements Dialog
How to implement the OnScreen Achievements Progress textdraw window
Globe Trotter Achievement: Travel 1000000 meters
Bad Insurance (Secret lvl 3) Achievement: Die 50 times
I Need A Helmet (Secret lvl 1) Achievement: Ride an NRG
This include makes adding achievements to any script fairly easy. It was designed for use in the gamemode only, not filterscripts.
It's a slight bit advanced, considering you have to design how the achievements are earned, but if you can make a very simple deathmatch, you can make an achievement with ease.
Features
Uses SA-MP's native SQLite Database engine, a fast and organized method of saving information. You can access it using an SQLite manager program, one is supplied at the bottom of this post.
Achievements are easily created, and the level of complexity is up to you.
A "Secret" variable can change how much information of an achievement is given to a player when using the given functions
Onscreen textdraw confirmation when an achievement is completed or progressed atleast 10%. It shows for 3 seconds, during which it will continue to update if the achievement is progressing while it's still showing.
The achievement dialog list is a 1 function call that shows all achievements to the player and allows them to see the description and their progression on the achievement.
Designed to allow for infinite achievements.*
Functions
stock CreateAchievement(ShortName[],FullName[],Stages,Description[],Secret=0)**
--Creates the achievement and lists in in the SQLite database found in scriptfiles named "Achievements"
stock ProgressPlayerAchievement(playerid,ShortName[],Increment)
--Use this to make the progress go up about the indicated amount, it won't go passed the maximum.
stock GetPlayerProgress(playerid,AchievementName[])
--This returns how much progress has been completed
stock ShowPlayerProgress(playerid,AchievementName[],Time=3000,update=0)***
--This shows the onscreen textdraw (highly suggested to put this in the OnPlayerFinishAchievement and OnPlayerProgressCheckpoint callbacks)
stock ShowAchievementsDialog(playerid)
--This shows the Dialog list, REQUIRES JA_OnDialogResponse
---------------
stock JA_OnDialogReponse(playerid,dialogid,response,list item) //Required if you use ShowAchievementsDialog
--Put this in OnDialogResponse callback using the respective parameters.
Callbacks
public OnPlayerFinishAchievement(playerid,AchievementName[])
--Called upon completion of the achievement, AchievementName[] is the achievement's ShortName
public OnPlayerProgressCheckpoint(playerid,AchievementNam e[])
--Called every 10% of completion on the achievement, AchievementName[] is the achievement's ShortName
---------------
public JA_DeleteAchievementWindow(playerid) //You don't have much reason to use this, just leave it alone.
--This is for the timer to delete the Textdraw, don't bother with it
Pictures and Development Log
Achievements Include Topic
You'll find other projects in developement here if you're interested. More information can be found here
Download
J_Achievements.INC
SQL Database Browser 2.0 b1 -I use it, pretty decent
Notes
*The Achievement dialog will be cut off if too many achievements are shown, I plan on updating this
**Secret level 1 = No Description, level 2 = Not Title, level 3 = No Progress displayed, will show when completed
***The parameter marked as "update" is used for another system, do NOT mess with it
Examples:
This example includes:
How to implement the Achievements Dialog
How to implement the OnScreen Achievements Progress textdraw window
Globe Trotter Achievement: Travel 1000000 meters
Bad Insurance (Secret lvl 3) Achievement: Die 50 times
I Need A Helmet (Secret lvl 1) Achievement: Ride an NRG
pawn Код:
#include <a_samp>
#include <j_achievements>
public OnGameModeInit()
{
//Globe Trotter Achievement
CreateAchievement("Distance1","Globe Trotter", 1000000, "Travel 1000000 meters");
SetTimer("UpdatePlayerPos",1000,1);
//Bad Insurance Achievement
CreateAchievement("Deaths1","Bad Insurance", 50, "Die 50 times",3);
//I Need A Helmt Achievement
CreateAchievement("Vehicle1","I Need A Helmet",1,"Ride an NRG",1);
}
//Globe Trotter Achievement
forward UpdatePlayerPos();
public UpdatePlayerPos()
{
new Float:x,Float:y,Float:z;
for(new playerid;playerid<MAX_PLAYERS;playerid++)
{
if(!IsPlayerConnected(playerid))continue;
GetPlayerPos(playerid,x,y,z);
if(GetPlayerState(playerid)==PLAYER_STATE_ONFOOT||PLAYER_STATE_DRIVER||PLAYER_STATE_PASSENGER)ProgressPlayerAchievement(playerid,"Distance1",floatround( floatsqroot( ( (GetPVarFloat(playerid,"OLDX")-x)*(GetPVarFloat(playerid,"OLDX")-x)+(GetPVarFloat(playerid,"OLDY")-y)*(GetPVarFloat(playerid,"OLDY")-y)+(GetPVarFloat(playerid,"OLDZ")-z)*(GetPVarFloat(playerid,"OLDZ")-z) ) ),floatround_floor ) );
SetPVarFloat(playerid,"OLDX",x);
SetPVarFloat(playerid,"OLDY",y);
SetPVarFloat(playerid,"OLDZ",z);
}
return 1;
}
//Bad Insurance Achievement
public OnPlayerDeath(playerid,killerid,reason)
{
ProgressPlayerAchievement(playerid,"Deaths1",1);
return 1;
}
//I Need A Helmet Achievement
public OnPlayerStateChange(playerid,newstate,oldstate)
{
if(newstate==PLAYER_STATE_DRIVER)
{
if(GetVehiceModel(GetPlayerVehicleID(playerid))==522)ProgressPlayerAchievement(playerid,"Vehicle1",1);
}
return 1;
}
public OnPlayerCommandText(playerid,cmdtext[])
{
//Achievement Dialog
if(!strcmp(cmdtext,"/Achievements",true)
{
ShowAchievementDialog(playerid);
return 1;
}
return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
//Dialog hook
if(JA_OnDialogResponse(playerid, dialogid, response, listitem))return 1;
return 1;
}
//Onscreen achievement window
public OnPlayerFinishAchievement(playerid,AchievementName[])
{
ShowPlayerProgress(playerid,AchievementName);
}
public OnPlayerProgressCheckpoint(playerid,AchievementName[])
{
ShowPlayerProgress(playerid,AchievementName);
}