30.05.2013, 22:47
Well basically here is what you'll want to get....
You can set up your DB structure in here
http://sourceforge.net/projects/sqlitebrowser/
You'll need this in your code.
You'll need to check when a user logs out if they're DB is created like this
So now with that set up you'll be able to make the queries you need to figure out the top players please note you can add more than kills / deaths to the DB in fact you may choose to drop ini all together and just use sqlite it's actually not all that difficult to implement.
I'll post some more code of how to do a query and actually get something out of it once your ready let me know.
You can set up your DB structure in here
http://sourceforge.net/projects/sqlitebrowser/
You'll need this in your code.
pawn Код:
Global Variable
new DB: UserData;
public OnGameModeInit()
{
UserData = db_open("databases/userdata.db"); // Folder inside of scriptfiles
}
pawn Код:
new Query[256];
new DBResult:Result;
// This will check if the player is in the DB yet
format(Query, sizeof(Query), "SELECT `PlayerName` FROM `UserData` Where `PlayerName` = '%s'", ReturnName(playerid));
// Send the query
Result = db_query(UserData, Query);
// User has a DB created
if(db_num_rows(Result))
{
// Update the database with their kills / deaths
format(Query, sizeof(Query), "UPDATE `UserData` set `Kills` = '%i', `Deaths` = '%i', where `PlayerName` = '%s'",
PlayerData[kills], PlayerData[Deaths], ReturnName(playerid));
Result = db_query(UserData, Query);
}
else
{
// Create their database entry with kills and deaths will automatically update whatever they already have
format(Query, sizeof(Query), "INSERT INTO `UserData`(`PlayerName`, `Kills`, `Deaths`) VALUES('%s', '%i', '%i'),
ReturnName(playerid), PlayerData[kills], PlayerData[Deaths]");
Result = db_query(UserData, Query);
}
// We now free the memory
db_free_result(Result);
I'll post some more code of how to do a query and actually get something out of it once your ready let me know.