[Include] Achievements by Joe Staff (Uses SQLite)
#1

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
[Image: JA1.jpg]
[Image: JA2.jpg]
[Image: JA3.jpg]
[Image: JA4.jpg]

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);
}
Reply
#2

PRO! Nice include!!
Reply
#3

hy top perfect xD
Reply
#4

I've given a couple of examples to help you understand how it works. If you're still lost on what the functions do, the developement log goes into further detail.
Reply
#5

Nice work.
Reply
#6

i like it good work
Reply
#7

nice work!
Reply
#8

nice script but there are some things you can fix:

"CREATE TABLE" instead of "CREATE TABLE IF NOT EXISTS"
ShortName validation is a bit dodgy
no sql injection protection
no checks to see if the database opened correctly
if just checking if a row exists, "SELECT ROWID FROM" should be faster than "SELECT * FROM"
database connections are not always closed
magic numbers used alot
fair enough about the pages but 1024 is pertty small for a list dialog
sqlite is pretty tolerant, but ID='%d' should be ID=%d
Reply
#9

So is this fully working then s some people are saying there is things wrong?
Reply
#10

DNS Error on screens and INC
Reply
#11

Fix this code:
pawn Код:
if(GetPlayerState(playerid)==PLAYER_STATE_ONFOOT||PLAYER_STATE_DRIVER||PLAYER_STATE_PASSENGER)
Reply
#12

Link is down
Reply
#13

Update link please
Reply
#14

Links updated
Reply
#15

for me theres not working any function , i did same as at the example script
Reply
#16

Looks Nice.
Reply
#17

pretty cool release
Reply
#18

Niccework!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)