SA-MP Forums Archive
achievements - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: achievements (/showthread.php?tid=675683)



achievements - Ertouq - 18.05.2020

Hello, what is the most correct way to save achievements? I'll do an achievement system based on kills, duel wins, etc. then I can think of 2 ways: check if they have X kills and give it the achievement (when killing someone) or using a global timer checking everyone? I would also like to save it by mysql, is it advisable to use a separate table or create inside the users table? Thanks


Re: achievements - jasperschellekens - 18.05.2020

Use a seperate table with an Primary key auto IC ID and a column which holds the users/characters ID.

You don't need a timer for that.

Kill archievement? Let's say people get an archievment at 50 kills. Then you just check under OnPlayerDeath if the killer has more than 50 kills, if so, reward them the archievement.


Re: achievements - Ertouq - 18.05.2020

Quote:
Originally Posted by jasperschellekens
View Post
Use a seperate table with an Primary key auto IC ID and a column which holds the users/characters ID.

You don't need a timer for that.

Kill archievement? Let's say people get an archievment at 50 kills. Then you just check under OnPlayerDeath if the killer has more than 50 kills, if so, reward them the archievement.
So in each column I put a different achievement of name and inside i put the ids, right? And variables? Do I need to create a variable for each achievement? Since I will also put command where the achievements made and those that do not


Re: achievements - XStormiest - 18.05.2020

You do not need a variable for every achievement. You will perform MySQL database queries to select the achievement you want to load into a variable. Then use that variable to do whatever you want. I suggest creating a method like:

LoadPlayerAchievment(playerid, achvid);


Re: achievements - Ertouq - 18.05.2020

Quote:
Originally Posted by XStormiest
View Post
You do not need a variable for every achievement. You will perform MySQL database queries to select the achievement you want to load into a variable. Then use that variable to do whatever you want. I suggest creating a method like:

LoadPlayerAchievment(playerid, achvid);
Oh nice! could you give me a mini example to get an idea of how to do it? Thanks


Re: achievements - XStormiest - 18.05.2020

Code:
LoadPlayerAchievement(playerid, achvid)
{
     // Get the MySQL query
     new query[256];
     format(query, sizeof(query), "SELECT `pID`, `achvid` FROM `achievements` WHERE `pName` = '%s' AND `achvid` = '%d'", replacemewithnamevariable, achvid);
     mysql_tquery(replacemewithdatabasehandle,query, "OnPlayerLoadAchievment", "dd", playerid, achvid);   
}

forward OnPlayerLoadAchievement(playerid, achvid);
public OnPlayerLoadAchievement(playerid, achvid)
{
     new rows;
     cache_get_num_rows(rows)
     if(rows)
     {
          cache_get_value_int(0, "achvid", replacemewithvariablename);
     }
     return 1;
}
I believe it would look something similar to this


Re: achievements - Ertouq - 18.05.2020

Quote:
Originally Posted by XStormiest
View Post
Code:
LoadPlayerAchievement(playerid, achvid)
{
     // Get the MySQL query
     new query[256];
     format(query, sizeof(query), "SELECT `pID`, `achvid` FROM `achievements` WHERE `pName` = '%s' AND `achvid` = '%d'", replacemewithnamevariable, achvid);
     mysql_tquery(replacemewithdatabasehandle,query, "OnPlayerLoadAchievment", "dd", playerid, achvid);   
}

forward OnPlayerLoadAchievement(playerid, achvid);
public OnPlayerLoadAchievement(playerid, achvid)
{
     new rows;
     cache_get_num_rows(rows)
     if(rows)
     {
          cache_get_value_int(0, "achvid", replacemewithvariablename);
     }
     return 1;
}
I believe it would look something similar to this
Thank you. I understood everything, so in the achievements table I have to put an auto increment id, pid where the id of the name and the achvid are saved? example

achievements:

ID | pID || achvid

and if so, when it comes to getting 2 accomplishments how does it get there? putting 2 to the achvid or creating another row of that achvid? example: achvid 1 for 5 kills, achvid 2 for 100, etc and so with different achievements, I do not know if I explain myself


Re: achievements - XStormiest - 18.05.2020

Well, every time you create a new achievement, you create it for the player, or the player name or character name or whatever you want to use. You need to create a table that has 2 foreign keys. One foreign key that comes from your account table. A second key from the table that handles achievements with data like name, progress, etc. (This one you have to create as well)

Then you create a third table that has 2 foreign keys, like accID (or whatever you want to use), achvID

So this table will probably be named 'player_achievements' and will have as column names the next variables:
p_achvid | pID (whatever you won't use here, like: charID, accountID, playerName, accountable, etc) | achvID
Where pID, achvid is a foreign key, and p_achvid is the primary key in this table.


Re: achievements - Ertouq - 18.05.2020

Quote:
Originally Posted by XStormiest
View Post
Well, every time you create a new achievement, you create it for the player, or the player name or character name or whatever you want to use. You need to create a table that has 2 foreign keys. One foreign key that comes from your account table. A second key from the table that handles achievements with data like name, progress, etc. (This one you have to create as well)

Then you create a third table that has 2 foreign keys, like accID (or whatever you want to use), achvID

So this table will probably be named 'player_achievements' and will have as column names the next variables:
p_achvid | pID (whatever you won't use here, like: charID, accountID, playerName, accountable, etc) | achvID
Where pID, achvid is a foreign key, and p_achvid is the primary key in this table.
Thank you very much, but I have not understood completely, excuse me (I need coffre haha). If it's not too much trouble you could show me a picture on the db of what it would be like? I haven't understood much


Re: achievements - XStormiest - 18.05.2020

I believe this image will help you understand the design of the database, although, this is just an example.
https://imgshare.io/image/NNHAYY