Advertisement
ukazax

Weapon Save System [Filterscript]

Jul 25th, 2015
1,508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.55 KB | None | 0 0
  1. // Main thread and database: http://forum.sa-mp.com/showthread.php?t=583034
  2. #include <a_samp>
  3.  
  4. #define ScriptVersion        1
  5. #define ScriptName            "Weapon Save System"
  6. #define ScriptAuthor        "kaZax"
  7.  
  8. #define DataBaseName        "PlayerWeapons.db"
  9.  
  10. new DB:db_Main;
  11.  
  12. new WeaponData[MAX_PLAYERS][13][2];
  13.  
  14. public OnFilterScriptInit()
  15. {
  16.     db_Main = db_open(DataBaseName);
  17.     db_query (db_Main, "PRAGMA synchronous=OFF; PRAGMA journal_mode=OFF;");
  18.    
  19.     printf("  Filterscript %s loaded. Version %d. Author: %s", ScriptName, ScriptVersion, ScriptAuthor);
  20.     return 1;
  21. }
  22. public OnFilterScriptExit()
  23. {
  24.     db_close(db_Main);
  25.     return 1;
  26. }
  27. public OnPlayerConnect(playerid)
  28. {
  29.     new k_PName[24];
  30.    
  31.     GetPlayerName(playerid, k_PName, 24);
  32.    
  33.     new query[80], DBResult:db_result, tmp[48], w_idx, a_idx;
  34.  
  35.     format(query, sizeof query, "SELECT * FROM `Weapon_Data` WHERE `Player`='%s'", k_PName);
  36.     db_result = db_query(db_Main, query);
  37.    
  38.     if(db_num_rows(db_result))
  39.     {
  40.         for (new x = 0; x < 26; x ++)
  41.         {
  42.             db_get_field(db_result, x + 2, tmp, sizeof tmp);
  43.             WeaponData[playerid][w_idx][a_idx] = strval(tmp);
  44.             w_idx ++;
  45.             if (x > 11 && a_idx == 0) w_idx = 0, a_idx = 1;          
  46.         }
  47.        
  48.         SetPVarInt(playerid, "FirstSpawn", 1);
  49.     }
  50.     else
  51.     {
  52.         format(query, sizeof(query), "INSERT INTO `Weapon_Data` (`Player`) VALUES ('%q')", k_PName);
  53.         db_free_result(db_query(db_Main, query));
  54.     }
  55.     db_free_result(db_result);  
  56.     return 1;
  57. }
  58. public OnPlayerSpawn(playerid)
  59. {
  60.     if (GetPVarInt(playerid, "FirstSpawn"))
  61.     {
  62.         for (new x = 0; x <= 12; x ++)
  63.         {
  64.             GivePlayerWeapon(playerid, WeaponData[playerid][x][0], WeaponData[playerid][x][1]);
  65.             WeaponData[playerid][x][0] = 0;
  66.             WeaponData[playerid][x][1] = 0;
  67.         }
  68.        
  69.         DeletePVar(playerid, "FirstSpawn");
  70.     }
  71.     return 1;
  72. }
  73. public OnPlayerDisconnect(playerid, reason)
  74. {
  75.     new weapons[13][2], query[384], k_PName[MAX_PLAYER_NAME];
  76.    
  77.     GetPlayerName(playerid, k_PName, MAX_PLAYER_NAME);
  78.    
  79.     for (new i = 0; i <= 12; i++)
  80.     {
  81.         GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
  82.     }
  83.    
  84.     format(query, sizeof query, "UPDATE `Weapon_Data` SET `Field3` = '%d', `Field4` = '%d', `Field5` = '%d', `Field6` = '%d', `Field7` = '%d', `Field8` = '%d', `Field9` = '%d', `Field10` = '%d' WHERE `Player` = '%q'",
  85.     weapons[0][0], weapons[1][0], weapons[2][0], weapons[3][0], weapons[4][0], weapons[5][0], weapons[6][0], weapons[7][0], k_PName);
  86.     db_free_result(db_query(db_Main, query));
  87.     format(query, sizeof query, "UPDATE `Weapon_Data` SET `Field11` = '%d', `Field12` = '%d', `Field13` = '%d', `Field14` = '%d', `Field15` = '%d', `Field16` = '%d', `Field17` = '%d', `Field18` = '%d' WHERE `Player` = '%q'",
  88.     weapons[8][0], weapons[9][0], weapons[10][0], weapons[11][0], weapons[12][0], weapons[0][1], weapons[1][1], weapons[2][1], k_PName);
  89.     db_free_result(db_query(db_Main, query));
  90.     format(query, sizeof query, "UPDATE `Weapon_Data` SET `Field19` = '%d', `Field20` = '%d', `Field21` = '%d', `Field22` = '%d', `Field23` = '%d', `Field24` = '%d', `Field25` = '%d', `Field26` = '%d', `Field27` = '%d', `Field28` = '%d' WHERE `Player` = '%q'",
  91.     weapons[3][1], weapons[4][1], weapons[5][1], weapons[6][1], weapons[7][1], weapons[8][1], weapons[9][1], weapons[10][1], weapons[11][1], weapons[12][1], k_PName);
  92.     db_free_result(db_query(db_Main, query));
  93.     return 1;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement