SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 18/05/2020, 01:56 PM   #1
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 233
Reputation: 4
Default achievements

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
Ertouq is offline   Reply With Quote
Old 18/05/2020, 02:00 PM   #2
jasperschellekens
High-roller
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Holland
Posts: 1,065
Reputation: 106
Default Re: achievements

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.
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!


Undead Wasteland Roleplay - The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
Discord - Website
jasperschellekens is offline   Reply With Quote
Old 18/05/2020, 04:11 PM   #3
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 233
Reputation: 4
Default Re: achievements

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
Ertouq is offline   Reply With Quote
Old 18/05/2020, 04:56 PM   #4
XStormiest
Gangsta
 
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 558
Reputation: 46
Default Re: achievements

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);
__________________
XStormiest is offline   Reply With Quote
Old 18/05/2020, 05:18 PM   #5
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 233
Reputation: 4
Default Re: achievements

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
Ertouq is offline   Reply With Quote
Old 18/05/2020, 05:31 PM   #6
XStormiest
Gangsta
 
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 558
Reputation: 46
Default Re: achievements

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
__________________
XStormiest is offline   Reply With Quote
Old 18/05/2020, 05:41 PM   #7
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 233
Reputation: 4
Default Re: achievements

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
Ertouq is offline   Reply With Quote
Old 18/05/2020, 05:58 PM   #8
XStormiest
Gangsta
 
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 558
Reputation: 46
Default Re: achievements

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.
__________________
XStormiest is offline   Reply With Quote
Old 18/05/2020, 06:10 PM   #9
Ertouq
Huge Clucker
 
Ertouq's Avatar
 
Join Date: Jul 2014
Posts: 233
Reputation: 4
Default Re: achievements

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
Ertouq is offline   Reply With Quote
Old 18/05/2020, 06:50 PM   #10
XStormiest
Gangsta
 
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 558
Reputation: 46
Default Re: achievements

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

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with achievements Sc0pion Scripting Help 2 22/07/2015 08:31 PM
Achievements Help Sc0pion Scripting Help 5 26/06/2015 08:18 AM
[Include] (LCI) Achievements System Deskoft Includes 43 27/01/2012 05:28 PM
Achievements Haydz Help Archive 1 17/11/2010 06:09 AM
[FilterScript] [FS] Achievements 0.9 bogeymanEST Filterscripts 15 08/07/2010 08:13 PM


All times are GMT. The time now is 09:08 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.